Fix Bitbucket PR head SHA detection#2350
Draft
juan-fernandez wants to merge 1 commit into
Draft
Conversation
|
5785080 to
d77c991
Compare
d77c991 to
7068b4e
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Logical steps
For Bitbucket PR pipelines (
BITBUCKET_PR_IDis set):BITBUCKET_COMMITasgit.commit.sha, preserving the checked-out commit reported by Bitbucket.HEADequalsBITBUCKET_COMMIT. If it does not, leavegit.commit.head.shaunset.git rev-list --parents -n 1 HEAD.BITBUCKET_BRANCH, then resolve the source branch ref locally first (refs/remotes/origin/<source-branch>, thenrefs/heads/<source-branch>), falling back togit ls-remote origin refs/heads/<source-branch>.BITBUCKET_COMMIT, the checked-out commit is already the PR source head, so setgit.commit.head.shatoBITBUCKET_COMMIT.BITBUCKET_COMMIT, it may be a Bitbucket synthetic merge.git.commit.head.shaunset. This avoids reporting a newer source branch head if the branch moved while the pipeline was running.HEADhas exactly two parents.BITBUCKET_PR_DESTINATION_BRANCH, resolved locally first and remotely only as a fallback, matches the second parent.git.commit.head.shato the first parent. Otherwise, leave it unset rather than guessing.Tests
yarn buildyarn exec eslint --cache --quiet packages/base/src/helpers/ci.ts packages/base/src/helpers/git/get-git-data.ts packages/base/src/helpers/__tests__/ci.test.ts packages/base/src/helpers/git/__tests__/get-git-data.test.tsyarn test packages/base/src/helpers/__tests__/ci.test.ts packages/base/src/helpers/git/__tests__/get-git-data.test.ts