@@ -17,6 +17,8 @@ const ARTIFACT_FALLBACK_REQUIRED_WORKFLOWS = [
1717 "Blacksmith ARM Testbox" ,
1818 "Workflow Sanity" ,
1919] ;
20+ const WORKFLOW_RUNS_PAGE_SIZE = 100 ;
21+ const MAX_WORKFLOW_RUN_SEARCH_RESULTS = 1_000 ;
2022
2123function readOptionValue ( argv , index , optionName ) {
2224 const value = argv [ index + 1 ] ;
@@ -168,8 +170,19 @@ function stripAnsi(raw) {
168170 return raw . replace ( new RegExp ( `${ escape } \\[[0-?]*[ -/]*[@-~]` , "gu" ) , "" ) ;
169171}
170172
171- export function parseWorkflowRunPages ( raw ) {
172- return JSON . parse ( stripAnsi ( raw ) ) . flatMap ( ( page ) => page . workflow_runs ?? [ ] ) ;
173+ export function parseWorkflowRunPage ( raw ) {
174+ const page = JSON . parse ( stripAnsi ( raw ) ) ;
175+ return {
176+ totalCount : page . total_count ?? 0 ,
177+ workflowRuns : page . workflow_runs ?? [ ] ,
178+ } ;
179+ }
180+
181+ export function workflowRunPageCount ( totalCount ) {
182+ return Math . min (
183+ Math . ceil ( totalCount / WORKFLOW_RUNS_PAGE_SIZE ) ,
184+ MAX_WORKFLOW_RUN_SEARCH_RESULTS / WORKFLOW_RUNS_PAGE_SIZE ,
185+ ) ;
173186}
174187
175188export function collectHostedGateEvidence ( { sha, workflowRuns, changelogOnly = false } ) {
@@ -220,11 +233,24 @@ export function collectHostedGateEvidence({ sha, workflowRuns, changelogOnly = f
220233}
221234
222235function loadWorkflowRuns ( repo , sha ) {
223- const raw = execPlainGh (
224- [ "api" , `repos/${ repo } /actions/runs?head_sha=${ sha } &per_page=100` , "--paginate" , "--slurp" ] ,
225- { encoding : "utf8" , stdio : [ "ignore" , "pipe" , "pipe" ] } ,
226- ) ;
227- return parseWorkflowRunPages ( raw ) ;
236+ const loadPage = ( page ) =>
237+ parseWorkflowRunPage (
238+ execPlainGh (
239+ [
240+ "api" ,
241+ `repos/${ repo } /actions/runs?head_sha=${ sha } &per_page=${ WORKFLOW_RUNS_PAGE_SIZE } &page=${ page } ` ,
242+ ] ,
243+ { encoding : "utf8" , stdio : [ "ignore" , "pipe" , "pipe" ] } ,
244+ ) ,
245+ ) ;
246+
247+ // Keep every request pinned to the head SHA and bound it to GitHub's documented search window.
248+ const firstPage = loadPage ( 1 ) ;
249+ const workflowRuns = [ ...firstPage . workflowRuns ] ;
250+ for ( let page = 2 ; page <= workflowRunPageCount ( firstPage . totalCount ) ; page += 1 ) {
251+ workflowRuns . push ( ...loadPage ( page ) . workflowRuns ) ;
252+ }
253+ return workflowRuns ;
228254}
229255
230256export function main ( argv = process . argv . slice ( 2 ) ) {
0 commit comments