Skip to content

Commit

Permalink
pickSHA: Improve pickSHA to handle pull_request_target and push
Browse files Browse the repository at this point in the history
To support use in pull_request_target target workflows, we need to
use the pull_request.head.sha value for check-runs.

We also better support push target workflows by using the after
SHA value as it better represents "The SHA of the most recent commit on
ref after the push."

Signed-off-by: BJ Hargrave <bj@hargrave.dev>
  • Loading branch information
bjhargrave authored and dghubble committed Oct 27, 2024
1 parent fa57bd6 commit f177115
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
11 changes: 8 additions & 3 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ async function run(): Promise<void> {
}

function pickSHA(context: Context): string {
if (context.eventName === 'pull_request') {
return context.payload.pull_request?.head.sha || context.sha
switch (context.eventName) {
case 'pull_request':
case 'pull_request_target':
return context.payload.pull_request?.head.sha || context.sha
case 'push':
return context.payload.after || context.sha
default:
return context.sha
}
return context.sha
}

run()

0 comments on commit f177115

Please sign in to comment.