From 9dfeb3edff852d7aba1b3da6c0b7a3dde54a1cce Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Thu, 13 Aug 2026 17:38:21 +0100 Subject: [PATCH] fix: use base sha for PRs instead of ref The ref is a named point, like `main`, so it can point at a different target to the PR (e.g. outdated branch). Using the `sha` means we diff against the target commit rather than a named ref. --- build/main.js | 6 +++--- src/git.ts | 6 +++--- test/git_test.ts | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/build/main.js b/build/main.js index a7d42b4..b400c99 100644 --- a/build/main.js +++ b/build/main.js @@ -24160,9 +24160,9 @@ function getBaseRef() { if (inputBaseRef) { return inputBaseRef.includes("/") ? inputBaseRef : `origin/${inputBaseRef}`; } - const githubBaseRef = context2.payload.pull_request?.base.ref; - if (githubBaseRef) { - return `origin/${githubBaseRef}`; + const githubBaseSha = context2.payload.pull_request?.base.sha; + if (githubBaseSha) { + return githubBaseSha; } return "origin/main"; } diff --git a/src/git.ts b/src/git.ts index 9aa75a1..b76d5be 100644 --- a/src/git.ts +++ b/src/git.ts @@ -46,10 +46,10 @@ export function getBaseRef(): string { return inputBaseRef.includes('/') ? inputBaseRef : `origin/${inputBaseRef}`; } - const githubBaseRef = github.context.payload.pull_request?.base.ref; + const githubBaseSha = github.context.payload.pull_request?.base.sha; - if (githubBaseRef) { - return `origin/${githubBaseRef}`; + if (githubBaseSha) { + return githubBaseSha; } return 'origin/main'; diff --git a/test/git_test.ts b/test/git_test.ts index 009df62..aa790da 100644 --- a/test/git_test.ts +++ b/test/git_test.ts @@ -30,19 +30,20 @@ describe('getBaseRef', () => { } }); - it('should return pull request base ref if in PR context', () => { + it('should return pull request base sha if in PR context', () => { const originalPayload = github.context.payload; try { github.context.payload = { pull_request: { number: 303, base: { - ref: 'develop' + ref: 'develop', + sha: 'base-sha' } } }; const baseRef = git.getBaseRef(); - expect(baseRef).toBe('origin/develop'); + expect(baseRef).toBe('base-sha'); } finally { github.context.payload = originalPayload; }