@@ -174,13 +174,27 @@ function getRepository(
174174function getSha (
175175 context : Context ,
176176 vercelPayload : VercelDeploymentPayload | null ,
177+ payload : EventPayload | null ,
177178) : string {
179+ // In "pull_request_target", the GITHUB_SHA is pointing to the base branch,
180+ // so we use the pull request commit instead.
181+ if ( context . env . GITHUB_EVENT_NAME === "pull_request_target" ) {
182+ if ( ! payload ) {
183+ throw new Error ( "Payload is missing in " pull_request_target " event" ) ;
184+ }
185+ const pullRequest = getPullRequestFromPayload ( payload ) ;
186+ if ( ! pullRequest ) {
187+ throw new Error ( "Pull request missing in " pull_request_target " event" ) ;
188+ }
189+ return pullRequest . head . sha ;
190+ }
191+
178192 if ( vercelPayload ) {
179193 return vercelPayload . client_payload . git . sha ;
180194 }
181195
182196 if ( ! context . env . GITHUB_SHA ) {
183- throw new Error ( ` GITHUB_SHA is missing` ) ;
197+ throw new Error ( " GITHUB_SHA is missing" ) ;
184198 }
185199
186200 return context . env . GITHUB_SHA ;
@@ -262,7 +276,7 @@ const service: Service = {
262276 const payload = readEventPayload ( context ) ;
263277 const vercelPayload = getVercelDeploymentPayload ( payload ) ;
264278 const mergeGroupPayload = getMergeGroupPayload ( payload ) ;
265- const sha = getSha ( context , vercelPayload ) ;
279+ const sha = getSha ( context , vercelPayload , payload ) ;
266280 const pullRequest = await getPullRequest ( {
267281 payload,
268282 vercelPayload,
0 commit comments