File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,14 +35,25 @@ async function runAction() {
3535 } ) ;
3636
3737 const workflowRunsForAffectedPrs = workflowRuns . data . workflow_runs . filter ( run => run . pull_requests ?. some ( pr => prMap [ pr . number ] ) ) ;
38- await Promise . all ( workflowRunsForAffectedPrs . map ( async run => {
38+
39+ const latestRunPerPullRequestMap = { } ;
40+ workflowRunsForAffectedPrs . map ( workflowRun => {
41+ workflowRun . pull_requests ?. map ( pr => {
42+ latestRunPerPullRequestMap [ pr . number ] = Math . max ( workflowRun . id , latestRunPerPullRequestMap [ pr . number ] || 0 ) ;
43+ } ) ;
44+ } ) ;
45+
46+ const latestWorkflowRuns = Object . values ( latestRunPerPullRequestMap ) ;
47+
48+ await Promise . all ( latestWorkflowRuns . map ( async runId => {
3949 try {
40- await core . info ( `Attempting to rerun: ${ run . id } ` ) ;
50+ await core . info ( `Attempting to rerun: ${ runId } ` ) ;
4151 await octokit . rest . actions . reRunWorkflow ( {
42- owner, repo, run_id : run . id
52+ owner, repo, run_id : runId
4353 } ) ;
4454 } catch ( error ) {
45- core . error ( `Failed to automatically retrigger pull request: ${ run . pull_requests ?. map ( pr => pr . number ) . join ( ',' ) } : ${ error . status } - ${ error . message } ` ) ;
55+ const workflowRun = workflowRunsForAffectedPrs . find ( run => run . id === runId ) ;
56+ core . error ( `Failed to automatically retrigger pull request: ${ workflowRun . pull_requests ?. map ( pr => pr . number ) . join ( ',' ) } : ${ error . status } - ${ error . message } ` ) ;
4657 }
4758 } ) ) ;
4859}
You can’t perform that action at this time.
0 commit comments