99import { getGitHubContextForWorkspaceUri , GitHubRepoContext } from "../git/repository" ;
1010
1111import { sep } from "path" ;
12- import { log , logError } from "../log" ;
12+ import { log , logDebug , logError } from "../log" ;
1313import { Workflow } from "../model" ;
1414import { RunStore } from "../store/store" ;
1515import { WorkflowRun } from "../store/workflowRun" ;
@@ -114,7 +114,6 @@ async function updatePinnedWorkflows() {
114114 } ) ;
115115
116116 const workflowByPath : { [ id : string ] : Workflow } = { } ;
117- // @ts -expect-error FIXME: Newer Typescript catches a problem that previous didn't. This will be fixed in Octokit bump.
118117 workflows . forEach ( w => ( workflowByPath [ w . path ] = w ) ) ;
119118
120119 for ( const pinnedWorkflow of workflowsByWorkspace . get ( workspaceName ) || [ ] ) {
@@ -129,12 +128,6 @@ async function updatePinnedWorkflows() {
129128 }
130129}
131130
132- async function refreshPinnedWorkflows ( ) {
133- for ( const pinnedWorkflow of pinnedWorkflows ) {
134- await refreshPinnedWorkflow ( pinnedWorkflow ) ;
135- }
136- }
137-
138131function clearPinnedWorkflows ( ) {
139132 // Remove any existing pinned workflows
140133 for ( const pinnedWorkflow of pinnedWorkflows ) {
@@ -150,8 +143,8 @@ function createPinnedWorkflow(gitHubRepoContext: GitHubRepoContext, workflow: Wo
150143
151144 const pinnedWorkflow = {
152145 gitHubRepoContext,
153- workflowId : workflow . id ,
154- workflowName : workflow . name ,
146+ workflowId : ( workflow as any ) . id ,
147+ workflowName : ( workflow as any ) . name ,
155148 lastRunId : undefined ,
156149 statusBarItem
157150 } ;
@@ -161,20 +154,37 @@ function createPinnedWorkflow(gitHubRepoContext: GitHubRepoContext, workflow: Wo
161154 return pinnedWorkflow ;
162155}
163156
157+ async function refreshPinnedWorkflows ( ) {
158+ for ( const pinnedWorkflow of pinnedWorkflows ) {
159+ await refreshPinnedWorkflow ( pinnedWorkflow ) ;
160+ }
161+ }
162+
164163async function refreshPinnedWorkflow ( pinnedWorkflow : PinnedWorkflow ) {
165164 const { gitHubRepoContext} = pinnedWorkflow ;
166165 const { client} = gitHubRepoContext ;
167-
166+ logDebug ( "Checking for updates to pinned workflow" , pinnedWorkflow . workflowName , "in" , gitHubRepoContext . name ) ;
168167 try {
169- const run = await client . paginate ( client . actions . listWorkflowRuns , {
170- owner : gitHubRepoContext . owner ,
171- repo : gitHubRepoContext . name ,
172- workflow_id : pinnedWorkflow . workflowId ,
173- per_page : 1 ,
174- page : 1
175- } ) ;
168+ const workflowRunCacheId = `MostRecentRun-${ gitHubRepoContext . owner } /${ gitHubRepoContext . name } /${ pinnedWorkflow . workflowId } ` ;
169+ const workflowRunResult = await client . conditionalRequest (
170+ client . actions . listWorkflowRuns ,
171+ {
172+ owner : gitHubRepoContext . owner ,
173+ repo : gitHubRepoContext . name ,
174+ workflow_id : pinnedWorkflow . workflowId ,
175+ per_page : 1 ,
176+ page : 1
177+ } ,
178+ workflowRunCacheId
179+ ) ;
180+
181+ if ( workflowRunResult === undefined ) {
182+ logDebug ( "No new runs detected for pinned workflow" , pinnedWorkflow . workflowName ) ;
183+ return ;
184+ }
176185
177- const mostRecentRun = run [ 0 ] ;
186+ const mostRecentRun = workflowRunResult . data . workflow_runs [ 0 ] ;
187+ logDebug ( "Updating pinned workflow" , pinnedWorkflow . workflowName , "with most recent run id" , mostRecentRun ?. id ) ;
178188
179189 runStore . addRun ( gitHubRepoContext , mostRecentRun ) ;
180190
0 commit comments