Skip to content

Commit

Permalink
Merge pull request #432 from github/simon-engledew/fix-ref-check
Browse files Browse the repository at this point in the history
Fix rev-parse errors
  • Loading branch information
simon-engledew committed Mar 25, 2021
2 parents 972dc3e + ba14abb commit bb012c4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/actions-util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/actions-util.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.test.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/actions-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test("getRef() returns merge PR ref if GITHUB_REF still checked out but sha has
const sha = "a".repeat(40);

const callback = sinon.stub(actionsutil, "getCommitOid");
callback.withArgs("refs/pull/1/merge").resolves(sha);
callback.withArgs("refs/remotes/pull/1/merge").resolves(sha);
callback.withArgs("HEAD").resolves(sha);

const actualRef = await actionsutil.getRef();
Expand Down
5 changes: 4 additions & 1 deletion src/actions-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,10 @@ export async function getRef(): Promise<string> {
// using GITHUB_REF. There is a subtle race condition where
// git rev-parse GITHUB_REF != GITHUB_SHA, so we must check
// git git-parse GITHUB_REF == git rev-parse HEAD instead.
const hasChangedRef = sha !== head && (await getCommitOid(ref)) !== head;
const hasChangedRef =
sha !== head &&
(await getCommitOid(ref.replace(/^refs\/pull\//, "refs/remotes/pull/"))) !==
head;

if (hasChangedRef) {
const newRef = ref.replace(pull_ref_regex, "refs/pull/$1/head");
Expand Down

0 comments on commit bb012c4

Please sign in to comment.