File tree Expand file tree Collapse file tree
aws/lambda/cross_repo_ci_relay/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ def build_check_run_output(
143143 conclusion : str ,
144144 details_url : str ,
145145 downstream_repo : str ,
146- pr_number : str
146+ pr_number : str = "" ,
147147) -> dict :
148148 """Return a GitHub Check Run output dict shown in the detail panel."""
149149 if status != "completed" :
@@ -152,9 +152,10 @@ def build_check_run_output(
152152 title = conclusion .capitalize ()
153153 else :
154154 title = "Completed"
155+ pr_part = f" for PR { pr_number } " if pr_number else ""
155156 return {
156157 "title" : title ,
157- "summary" : f"{ downstream_repo } workflow for PR { pr_number } : { details_url } " ,
158+ "summary" : f"{ downstream_repo } workflow{ pr_part } : { details_url } " ,
158159 }
159160
160161
Original file line number Diff line number Diff line change @@ -81,14 +81,18 @@ export default function crcrOncallBot(app: Probot): void {
8181
8282 // Get the PRs this check run belongs to.
8383 let prNumbers : number [ ] = [ ] ;
84- if ( checkRun . pull_requests && checkRun . pull_requests . length > 0 ) {
85- prNumbers = checkRun . pull_requests . map ( ( pr ) => pr . number ) ;
86- } else if ( checkRun . output ?. summary ) {
84+ if ( checkRun . output ?. summary ) {
8785 const match = checkRun . output . summary . match ( / f o r P R ( \d + ) / ) ;
8886 if ( match ) {
8987 prNumbers = [ parseInt ( match [ 1 ] , 10 ) ] ;
9088 }
91- } else if ( checkRun . head_sha ) {
89+ } else if ( checkRun . pull_requests && checkRun . pull_requests . length > 0 ) {
90+ prNumbers = checkRun . pull_requests . map ( ( pr ) => pr . number ) ;
91+ }
92+
93+ // Fall back to Search API if still no PR found (e.g., pr_number was empty
94+ // on the Lambda side).
95+ if ( prNumbers . length === 0 && checkRun . head_sha ) {
9296 try {
9397 const result = await ctx . octokit . rest . search . issuesAndPullRequests ( {
9498 q : `${ checkRun . head_sha } type:pr repo:${ owner } /${ repo } ` ,
Original file line number Diff line number Diff line change 177177 } ) ;
178178
179179 test ( "does not comment when output has no PR number" , async ( ) => {
180+ // output.summary exists but regex doesn't match (empty pr_number);
181+ // falls through to Search API which also returns nothing
182+ const scope = nock ( "https://api.github.com" )
183+ . get ( "/search/issues" )
184+ . query ( true )
185+ . reply ( 200 , { total_count : 0 , items : [ ] } ) ;
186+
180187 await probot . receive ( {
181188 name : "check_run" as any ,
182189 payload : checkRunPayload ( {
188195 } ) as any ,
189196 id : "8" ,
190197 } ) ;
198+ handleScope ( scope ) ;
191199 } ) ;
192200
193201 test ( "posts comment when output contains PR number for cross-fork PR" , async ( ) => {
You can’t perform that action at this time.
0 commit comments