Add support for Github stacked pull requests behind opt in system property - #1550
Add support for Github stacked pull requests behind opt in system property#1550juliovalcarcel wants to merge 3 commits into
Conversation
…sts with opt in system property
|
I am not maintaining this plugin actively but FWIW: #1545 (comment) (CC @jtnord) |
|
So stacks are fun.. As for the commits, it is now possible to fetch commits via their sha ref, so adding that ref (or refs) consistently when fetching would be what I think we should do rather than attempt to re-implement things. Have not yet looked at the code, this is late night thoughts. |
| } | ||
| } | ||
| if (gitHubMergeHash != null) { | ||
| // fetch refs/pull/<n>/merge so the merge commit is available to check out below; |
There was a problem hiding this comment.
Should be able to fetch the commit directly (which should handle all cases?)
(although I recall (perhaps not GH but something else?) sometimes there was an race condition between the merge commit sha being in the metadata and it being available for pulling.)
There was a problem hiding this comment.
Updated and re-tested on my Jenkins instance (Swapped back to PR-Merge from PR-Head) and still worked. Let me know if there is something you want handled for the potential race condition, or if since this is feature gated, leave that for a future issue to resolve?
Also fixed SpotBugs.
This pull request adds support for Github Stacked Pull Requests (behind a feature flag) by fixing a merge-strategy build failure caused by stacked pull requests. This is my first contribution to this repo or to a Jenkins plugin, so I have some questions/notes in the reviewers section to confirm my approach/design. Additionally I have put this up for review to get feedback now, but in addition to the unit tests, I have deployed this plugin to our Jenkins instance to run for the next week or two to see if we run into issues with it enabled. From my testing this all addresses our issues.
Description
When a stacked pull request targets the branch of another open pull request (PR B "the child" and PR A "the base"), the build of PR B fails at checkout with this error:
The failure occurs when PR A is behind the target branch. In this case GitHub sets the base parent of the merge commit of PR B to the merge preview of PR A (
refs/pull/A/merge), but no branch contains this commit. The plugin then uses this commit as the base and tries to merge against it, but Git cannot find the commit, so the build fails.This pull request adds an opt-in system property which defaults to off. When enabled the plugin fetches
refs/pull/N/mergeand checks out the GitHub merge commit directly. My thought/design of this is that the plugin could either replicate the logic or just rely on GitHub's logic, and I thought it would be easier/more robust to use their logic. The merge commit is fetched into its own ref (…/<name>-merge) so it does not collide with the pull-head ref.The new property is:
Related to #1545
Notes/Questions for Reviewers
equivalent()is untouched, so JENKINS-57583 ("don't rebuild a merge PR when only the target branch changed") still holds. A consequence is that a stacked PR does not automatically rebuild when only its base PR advances, the same as any merge PR today.Reviewer's manual test instructions
master.master, so PR A is behindmaster.org.jenkinsci.plugins.github_branch_source.GitHubSCMSource.preferGitHubMergeCommit = truein the Script Console.false(or remove the property and restart). The behavior returns to the default.Submitter checklist
Reviewer checklist
Documentation changes
No documentation change is required. The option is an opt-in system property for preview. Happy to add documentation if requested.
Users/aliases to notify