Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👷 Add a GitHub workflow to prevent blocked PRs from being merged #85

Merged
merged 2 commits into from
Nov 3, 2024

Conversation

ebouchut
Copy link
Contributor

@ebouchut ebouchut commented Oct 27, 2024

Description

This PR adds a new feature to PRs in this GitHub repository.
A PR can depend on:

  • another PR from the same repository
  • a GitHub issue from the same repository

To indicate that PR2 depends on PR1,
add Blocked by #1 to PR2's description

This PR adds a new GitHub workflow (.github/workflows/pr-dependencies-check.yml) using the Levi-Lesches/blocking-issues GitHub Action.
It runs each time a PR is created, updated, closed, or re-opened.
It checks if the PR is blocked.
If so it fails, preventing the PR from being merged.

⏱️ The workflow takes ~10 seconds to run.

Remarks

PR Dependent on another PR

✅ This works fine provided both PRs are in the same repository.
Cross-repository PR dependencies are not supported.

PR Dependent on an Issue

I experimented with making a PR dependent on a GitHub Issue.
Based on my testing, it does not work as closing this issue does not trigger the workflow.
Therefore this dependency change is not taken into account automatically.
I needed to edit the PR description to trigger the workflow again which is not optimal!
❌ This is why, I do not recommend making a PR dependent on a GH issue.

EDIT: ✅ It now works fine. I made a mistake and the indentation was off. Now fixed.

Resources

To indicate that PR2 depends on PR1,
add `Depends on #1` to PR2's description

This GitHub workflow uses a GitHub Action to check for issues blocking a PR.
The term "issue" above is misleading as it can denote another PR
or a GitHub issue from the same repository.
iThis syntax does not allow cross repository PR dependencies.

See:

- GH Action: https://github.com/Levi-Lesches/blocking-issues
- Discussion about the need for such a feature in GitHub and
  the open-source workarounds in the meantime:
  https://github.com/orgs/community/discussions/4477#discussioncomment-1039627
@ebouchut
Copy link
Contributor Author

ebouchut commented Oct 27, 2024

This PR adds a GitHub Workflow to check for PRs blocked by another PR and/or issue.
It prevents the dependent PR from being merged while the blocking PR/issue is opened.

GitHub does not provide a way to mark a PR dependent on another PR.
For example, making PR-2 dependent on PR-1.

  • PR-1 is the parent PR
  • PR-2 is the child PR

While searching for open-source alternatives to fill this void,
I came across an interesting discussion on GitHub itself.
It was started a few years ago by @isaacs on his isaacs/github repo.
GitHub subsequently hired him, and the repo morphed into this discussion (now hosted on Github).

The need is twofold:

  1. Be able to compare the difference between PR-1 (parent) and PR-2 (child).
  2. Prevent PR-2 from being merged before PR-1 is merged

I have paraphrased above what is explained in this message:
https://github.com/orgs/community/discussions/4477#discussioncomment-1293255

A few tools answer point 2 (i.e. avoid an incorrect merge of the child PR before the parent PR):
https://github.com/orgs/community/discussions/4477#discussioncomment-1039627

I tried every one of them and decided to go with the blocking-issues Github Action.
https://github.com/Levi-Lesches/blocking-issues

A GitHub action to label issues and PRs when they're blocked by another issue or PR.

This PR adds a GitHub Workflow to check for PRs and GitHub issues blocked by another PR and/or Issue.
For instance, we can edit the description of PR-2 and mark it as blocked by PR-1 like this:

Blocked by #1

The workflow will now prevent PR-2 from being merged before PR-1 is merged.

Issues indentation was off.
@ebouchut ebouchut changed the title 👷 Add a a GitHub workflow to prevent blocked PRs from being merged 👷 Add a GitHub workflow to prevent blocked PRs from being merged Oct 27, 2024
Copy link
Contributor

@MikePlante1 MikePlante1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MikePlante1 MikePlante1 merged commit ad9b1c0 into nightscout:dev Nov 3, 2024
@ebouchut
Copy link
Contributor Author

ebouchut commented Nov 3, 2024

Thanks @MikePlante1 .

❌ The workflow failed because it could not create the blocked label.
Could you create it by hand here like this and edit the PR description to re-trigger the checks:

CleanShot 2024-11-03 at 19 40 49@2x

@ebouchut ebouchut deleted the config/pr-dependency-check branch November 3, 2024 18:56
@ebouchut
Copy link
Contributor Author

ℹ️ For the record, the Checks of a PR may display this error

Error: Resource not accessible by integration

as long as it is in Draft mode.

To display the detailed the Checks logs, click the Details link next to

Prevent Blocked PRs from being Merged / blocking_issues (pull_request)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants