Show a warning comment for PRs targeting the wrong base branch #412
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.
Motivation
I've accidentally submitted a pull request targeting master at #410, and we didn't notice it until after the merge (HebaruSan was wondering why it didn't deploy on alpha).
We had to force-push the commits away from master again and re-do the PR to alpha (#411).
GitHub automatically chooses the master branch as it is our default branch.
We want to keep it that way so technology-interested users of SpaceDock that want to look at our source code can find it in the state as it is deployed right now.
On Discord we got the idea to add a workflow that posts a warning comment on a pull request that is not targeting alpha.
Changes
A new
branch-warning.yml
workflow file is added.It triggers on
pull_request_target: opened
, which is equivalent topull_request
except that it runs in the context of the base branch and not the source branch (or an automatically created merge commit thereof).This seems to be the recommended way for workflows that do not need to interact with the code changes of the source branch, as it has some security benefits (and I guess minimally reduced load on GitHub's servers as it doesn't need to create a merge commit).
It checks for the target and source branch of the PR, and executes if the PR goes to master/beta and does not come from beta/alpha.
I used the
label
property of the event payload, as it contains the username of the repo owners, so to make sure the warning triggers if someone opens up a PR from their own, changedalpha
/beta
branch.Helpful docs links:
Test run
See DasSkelett#2 and DasSkelett#3
I had to do change the trigger to
pull_request
as otherwise the workflow wouldn't have run until it had been merged.While I was on it, I realized that we do not mention our branching strategy anywhere in the README or CONTRIBUTING.md, only the "Development Guide" wiki page. Now CONTRIBUTING.md links to the "Development Guide" wiki page, and README.md links to CONTRIBUTING.md.
Still two clicks away, but better than before.
Additionally I've reworked CONTRIBUTING.md to make it more inline with our current setup.