-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix PR validity check in create_release_backmerge_pr
#607
Conversation
I've tried to run a simple test:
The result: [19:16:35]: Creating new pull request from 'merge/iangmaia-test-fix-backmerge-pr-validity-check-into-iangmaia-test-fix-backmerge-pr-validity-check-target' to branch 'iangmaia/test-fix-backmerge-pr-validity-check-target' of 'bloom/DayOne-Android'
[19:16:35]: GitHub responded with 422: {"message":"Validation Failed","errors":[{"resource":"PullRequest","code":"custom","message":"No commits between iangmaia/test-fix-backmerge-pr-validity-check-target and merge/iangmaia-test-fix-backmerge-pr-validity-check-into-iangmaia-test-fix-backmerge-pr-validity-check-target"}],"documentation_url":"https://docs.github.com/rest/pulls/pulls#create-a-pull-request","status":"422"} Also, the lane didn't fail, as it usually doesn't when the creation of PRs fails like this at the GitHub API level. |
Another very similar test, but with an empty commit: it works fine. |
Strange, because checking the results of
So this means the reasoning we intended to apply is correct, but there's a bug in the current implementation I guess… |
@iangmaia I've pushed some commits that I think should fix the issue. Can you redo your tests after pointing to the latest commit of this branch? 🙇 |
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 ran a few checks with the latest changes and I correctly had the Backmerge PR created or a Nothing to merge from <source> into <target>. Skipping PR creation.
message.
Why?
Our logic for testing if the backmerge PR would be valid or rejected by GitHub was incorrect.
head
andbase
of the PR about to be created returnedtrue
forpoint_to_same_commit?
. Which would never be true, as even if there were no new commit on thehead
branch since the last backmerge PR into thebase
branch, those would still be two different commits (due to the merge commit inbase
being created from the last backmerge PR).head
andbase
were empty, it would technically still be valid to create a PR between the two, because one could have added a commit and its revert on thehead
branch since the last backmerge ofhead
intobase
, resulting in an emptydiff
in the PR, but still a valid PR as some commits fromhead
would not be onbase
branch yet and would still be ok to merge to reconcile the git graph / history.GitHub uses the three-dots diff to create Pull Requests, meaning it uses
git diff base...head
(akagit diff $(git merge-base base head) head
) to only include the diff since the common ancestor (merge-base) of the base branch and the head branch.We thus need to use a similar logic in our action, to detect if GitHub would consider that there was nothing to merge and would reject the PR creation before even attempting to do the API call to create the PR.
How?
This PR fixes the logic to check if PR would be invalid (nothing to merge), by first finding the
merge-base
between the two branches and checking if the merge base is the same as the head commit we are trying to merge.If so, that means that there were no new commits on the head branch since it was last cut or last merged into the base branch. In other words, all the commits in the head branch are already in the base branch too (are already part of the common ancestor tree). And in such case there is nothing new to merge, so we should skip the PR creation
This PR also fixes the call to
ensure_git_branch
after having called the callback optionally provided by the user, as it had a typo in the regex used.Checklist before requesting a review
bundle exec rubocop
to test for code style violations and recommendationsspecs/*_spec.rb
) if applicablebundle exec rspec
to run the whole test suite and ensure all your tests passCHANGELOG.md
file to describe your changes under the appropriate existing###
subsection of the existing## Trunk
section.MIGRATION.md
file to describe how the changes will affect the migration from the previous major version and what the clients will need to change and consider.