Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions packages/core/src/ci-environment/services/github-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,27 @@ function getRepository(
function getSha(
context: Context,
vercelPayload: VercelDeploymentPayload | null,
payload: EventPayload | null,
): string {
// In "pull_request_target", the GITHUB_SHA is pointing to the base branch,
// so we use the pull request commit instead.
if (context.env.GITHUB_EVENT_NAME === "pull_request_target") {
if (!payload) {
throw new Error('Payload is missing in "pull_request_target" event');
}
const pullRequest = getPullRequestFromPayload(payload);
if (!pullRequest) {
throw new Error('Pull request missing in "pull_request_target" event');
}
return pullRequest.head.sha;
}

if (vercelPayload) {
return vercelPayload.client_payload.git.sha;
}

if (!context.env.GITHUB_SHA) {
throw new Error(`GITHUB_SHA is missing`);
throw new Error("GITHUB_SHA is missing");
}

return context.env.GITHUB_SHA;
Expand Down Expand Up @@ -262,7 +276,7 @@ const service: Service = {
const payload = readEventPayload(context);
const vercelPayload = getVercelDeploymentPayload(payload);
const mergeGroupPayload = getMergeGroupPayload(payload);
const sha = getSha(context, vercelPayload);
const sha = getSha(context, vercelPayload, payload);
const pullRequest = await getPullRequest({
payload,
vercelPayload,
Expand Down
Loading