Repository navigation
chore(brancing): Warn targeting main #16
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| name: "PR target branch" | ||
|
|
||
| on: | ||
| # pull_request_target so the job can comment on pull requests from forks, | ||
| # which a fork-triggered pull_request token cannot do. | ||
| # | ||
| # DANGER: this runs with a repository token against pull requests from | ||
| # untrusted forks. It is safe only because nothing from the head revision is | ||
| # checked out or executed, and no pull-request-controlled string reaches a | ||
| # `run:` block. Do not add actions/checkout, and keep permissions scoped to | ||
| # pull-requests: write. | ||
| # | ||
| # GitHub reads this file from the pull request's base branch, so it must | ||
| # exist on main to guard pull requests into main. | ||
| pull_request_target: | ||
| types: [opened] | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
|
|
||
| concurrency: | ||
| group: pr-target-branch-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| check: | ||
| name: "Warn on pull requests targeting main" | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| steps: | ||
| # Pinned to a commit SHA because the tag is mutable and this step holds | ||
| # a write-scoped token. | ||
| - uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 | ||
| with: | ||
| script: | | ||
| const pr = context.payload.pull_request; | ||
| const base = pr.base.ref; | ||
| const {owner, repo} = context.repo; | ||
|
|
||
| if (base !== 'main') { | ||
| core.info(`Base branch is ${base}; nothing to check.`); | ||
| return; | ||
| } | ||
|
|
||
| const body = | ||
| `**This pull request targets \`main\`. Please retarget it to \`mezmo\`.** | ||
|
|
||
| Use **Edit** next to the pull request title to change the base branch, then | ||
| rebase onto \`mezmo\` if the diff picked up unrelated commits.`; | ||
|
|
||
| await github.rest.issues.createComment({owner, repo, issue_number: pr.number, body}); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow subscribes only to
opened, although its comments say retargeting reruns the check and clears the warning. Changing the base branch emits aneditedevent, and the script has no logic to remove an earlier comment, so a pull request retargeted tomezmowould retain the stale warning.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted the comment. But would it be better to do something like resolving it like what is done in https://github.com/mezmo/aura/blob/main/.github/workflows/pr-target-branch.yml#L89
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes—Aura’s marker-based update is better than deleting the comment. It preserves the audit trail, avoids duplicate bot comments, and replaces the warning in place when the PR is retargeted.
It is not technically resolving a GitHub review thread; it finds the bot’s marker comment and updates it to a “Resolved” message. For Rig, use the same pattern:
Add a stable marker such as
<!-- pr-target-branch -->, locate only thegithub-actions[bot]comment containing that marker, and update it to a resolved message when aneditedevent changes the base away frommain.editedis the key event for retargeting;reopenedcovers a PR reopened while still targetingmain. This maintains one warning comment per PR without leaving a stale warning.Tip: You can customize Greptile's behavior for this repo with
.greptile/rules.mdand.greptile/config.json.