Skip to content

Commit 519f540

Browse files
committed
Use issue argument to get the correct SHA for the status check
1 parent 2649c1a commit 519f540

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/github/handler.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
updateComment,
55
listComments,
66
addCommentToIssue,
7-
deleteComment
7+
deleteComment,
8+
createGitHubClient
89
} from '../client/github'
910
import { Inputs } from '../types'
1011
import { Report } from '../ctrf/core/types/ctrf'
@@ -285,10 +286,28 @@ export async function createStatusCheck(
285286
}
286287

287288
try {
289+
// Use the correct SHA for PR association
290+
let sha = context.sha
291+
if (inputs.issue) {
292+
try {
293+
const octokit = await createGitHubClient()
294+
const pr = await octokit.pulls.get({
295+
owner: context.repo.owner,
296+
repo: context.repo.repo,
297+
pull_number: parseInt(inputs.issue)
298+
})
299+
sha = pr.data.head.sha
300+
core.info(`Using PR head SHA: ${sha} for PR #${inputs.issue}`)
301+
} catch (error) {
302+
core.warning(`Failed to fetch PR #${inputs.issue}, using context.sha: ${context.sha}. ${String(error)}`)
303+
sha = context.sha
304+
}
305+
}
306+
288307
await createCheckRun(
289308
context.repo.owner,
290309
context.repo.repo,
291-
context.sha,
310+
sha,
292311
inputs.statusCheckName,
293312
'completed',
294313
report.results.summary.failed > 0 ? 'failure' : 'success',

0 commit comments

Comments
 (0)