1+ import { basename } from "path" ;
12import * as vscode from "vscode" ;
23
34import { getGitHead , getGitHubContextForWorkspaceUri , GitHubRepoContext } from "../git/repository" ;
@@ -19,11 +20,15 @@ export function registerTriggerWorkflowRun(context: vscode.ExtensionContext, sto
1920 "github-actions.explorer.triggerRun" ,
2021 async ( args : TriggerRunCommandOptions | vscode . Uri ) => {
2122 let workflowUri : vscode . Uri | null = null ;
23+ let workflowIdForApi : number | string | undefined ;
24+
2225 if ( args instanceof vscode . Uri ) {
2326 workflowUri = args ;
27+ workflowIdForApi = basename ( workflowUri . fsPath ) ;
2428 } else if ( args . wf ) {
2529 const wf : Workflow = args . wf ;
2630 workflowUri = getWorkflowUri ( args . gitHubRepoContext , wf . path ) ;
31+ workflowIdForApi = wf . id ;
2732 }
2833
2934 if ( ! workflowUri ) {
@@ -47,17 +52,23 @@ export function registerTriggerWorkflowRun(context: vscode.ExtensionContext, sto
4752 }
4853
4954 const relativeWorkflowPath = vscode . workspace . asRelativePath ( workflowUri , false ) ;
55+ if ( ! workflowIdForApi ) {
56+ workflowIdForApi = basename ( workflowUri . fsPath ) ;
57+ }
58+
5059 let latestRunId : number | undefined ;
5160 try {
61+ log ( `Fetching latest run for workflow: ${ workflowIdForApi } ` ) ;
5262 const result = await gitHubRepoContext . client . actions . listWorkflowRuns ( {
5363 owner : gitHubRepoContext . owner ,
5464 repo : gitHubRepoContext . name ,
55- workflow_id : relativeWorkflowPath ,
65+ workflow_id : workflowIdForApi ,
5666 per_page : 1
5767 } ) ;
5868 latestRunId = result . data . workflow_runs [ 0 ] ?. id ;
69+ log ( `Latest run ID before trigger: ${ latestRunId } ` ) ;
5970 } catch ( e ) {
60- // Ignore error
71+ log ( `Error fetching latest run: ${ ( e as Error ) . message } ` ) ;
6172 }
6273
6374 let dispatched = false ;
@@ -158,32 +169,35 @@ export function registerTriggerWorkflowRun(context: vscode.ExtensionContext, sto
158169 }
159170
160171 if ( dispatched ) {
161- vscode . window . withProgress ( {
162- location : vscode . ProgressLocation . Window ,
163- title : "Waiting for workflow run to start..."
164- } , async ( ) => {
165- for ( let i = 0 ; i < 20 ; i ++ ) {
166- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
167- try {
168- const result = await gitHubRepoContext . client . actions . listWorkflowRuns ( {
169- owner : gitHubRepoContext . owner ,
170- repo : gitHubRepoContext . name ,
171- workflow_id : relativeWorkflowPath ,
172- per_page : 1
173- } ) ;
174- const newLatestRunId = result . data . workflow_runs [ 0 ] ?. id ;
175- if ( newLatestRunId && newLatestRunId !== latestRunId ) {
176- log ( `Found new workflow run: ${ newLatestRunId } . Triggering refresh and polling.` ) ;
177- await vscode . commands . executeCommand ( "github-actions.explorer.refresh" ) ;
178- // Poll for 15 minutes (225 * 4s)
179- store . pollRun ( newLatestRunId , gitHubRepoContext , 4000 , 225 ) ;
180- break ;
172+ vscode . window . withProgress (
173+ {
174+ location : vscode . ProgressLocation . Window ,
175+ title : "Waiting for workflow run to start..."
176+ } ,
177+ async ( ) => {
178+ for ( let i = 0 ; i < 20 ; i ++ ) {
179+ await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
180+ try {
181+ const result = await gitHubRepoContext . client . actions . listWorkflowRuns ( {
182+ owner : gitHubRepoContext . owner ,
183+ repo : gitHubRepoContext . name ,
184+ workflow_id : workflowIdForApi ! ,
185+ per_page : 1
186+ } ) ;
187+ const newLatestRunId = result . data . workflow_runs [ 0 ] ?. id ;
188+ if ( newLatestRunId && newLatestRunId !== latestRunId ) {
189+ log ( `Found new workflow run: ${ newLatestRunId } . Triggering refresh and polling.` ) ;
190+ await vscode . commands . executeCommand ( "github-actions.explorer.refresh" ) ;
191+ // Poll for 15 minutes (225 * 4s)
192+ store . pollRun ( newLatestRunId , gitHubRepoContext , 4000 , 225 ) ;
193+ break ;
194+ }
195+ } catch ( e ) {
196+ log ( `Error checking for new run: ${ ( e as Error ) . message } ` ) ;
181197 }
182- } catch ( e ) {
183- log ( `Error checking for new run: ${ ( e as Error ) . message } ` ) ;
184198 }
185199 }
186- } ) ;
200+ ) ;
187201 }
188202
189203 return vscode . commands . executeCommand ( "github-actions.explorer.refresh" ) ;
0 commit comments