@@ -44,7 +44,7 @@ async function analyzeJob(github, context, core, job) {
4444
4545 core . info ( ` Found ${ failureAnnotations . length } failure-related annotations:` ) ;
4646 failureAnnotations . forEach ( annotation => {
47- core . info ( ` [${ annotation . annotation_level } ] ${ annotation . message } ` ) ;
47+ core . info ( ` > [${ annotation . annotation_level } ] ${ annotation . message } ` ) ;
4848 } ) ;
4949
5050 const allFailureAnnotationMessages = failureAnnotations . map ( annotation => annotation . message ) . join ( '' ) ;
@@ -174,6 +174,12 @@ async function getWorkflowInfo(github, context, core, runID) {
174174}
175175
176176async function findRelatedPR ( github , context , core , workflowRun ) {
177+ // Try to find PR from context first (most reliable)
178+ if ( context . payload . pull_request ) {
179+ core . info ( `Found PR from context: #${ context . payload . pull_request . number } ` ) ;
180+ return context . payload . pull_request ;
181+ }
182+
177183 // Try to find PR by commit SHA
178184 core . info ( `Finding related PR for commit SHA: ${ workflowRun . head_sha } ` ) ;
179185 try {
@@ -196,7 +202,52 @@ async function findRelatedPR(github, context, core, workflowRun) {
196202 core . warning ( `Failed to find PR by commit SHA ${ workflowRun . head_sha } : ${ error . message } ` ) ;
197203 }
198204
199- core . info ( 'No related PR found for this workflow run' ) ;
205+ // Fallback: try to find PR by branch (handles fork scenarios)
206+ if ( workflowRun . head_branch ) {
207+ try {
208+ // First try with the current owner (for non-fork scenarios)
209+ const { data : pulls } = await github . rest . pulls . list ( {
210+ owner : context . repo . owner ,
211+ repo : context . repo . repo ,
212+ head : `${ context . repo . owner } :${ workflowRun . head_branch } ` ,
213+ state : 'open' ,
214+ sort : 'updated' ,
215+ direction : 'desc'
216+ } ) ;
217+
218+ if ( pulls . length > 0 ) {
219+ core . info ( `Found PR from branch ${ workflowRun . head_branch } : #${ pulls [ 0 ] . number } ` ) ;
220+ return pulls [ 0 ] ;
221+ }
222+
223+ // If not found, try to find PRs from forks
224+ const { data : allPulls } = await github . rest . pulls . list ( {
225+ owner : context . repo . owner ,
226+ repo : context . repo . repo ,
227+ state : 'open' ,
228+ sort : 'updated' ,
229+ direction : 'desc' ,
230+ per_page : 100 // Get more PRs to search through
231+ } ) ;
232+
233+ // Look for PRs that match the branch name (could be from forks)
234+ const matchingPulls = allPulls . filter ( pr => {
235+ // Check if the PR's head ref matches our branch
236+ return pr . head . ref === workflowRun . head_branch ||
237+ pr . head . label . endsWith ( `:${ workflowRun . head_branch } ` ) ;
238+ } ) ;
239+
240+ if ( matchingPulls . length > 0 ) {
241+ const latestPR = matchingPulls . sort ( ( a , b ) => new Date ( b . updated_at ) - new Date ( a . updated_at ) ) [ 0 ] ;
242+ core . info ( `Found PR from fork branch ${ workflowRun . head_branch } : #${ latestPR . number } (from ${ latestPR . head . user . login } )` ) ;
243+ return latestPR ;
244+ }
245+
246+ } catch ( error ) {
247+ core . warning ( `Failed to find PR by branch ${ workflowRun . head_branch } : ${ error . message } ` ) ;
248+ }
249+ }
250+
200251 return null ;
201252}
202253
0 commit comments