11import * as vscode from "vscode" ;
22
3- import { CurrentBranchRepoNode , getCurrentBranchWorkflowRunNodes } from "./current-branch/currentBranchRepoNode " ;
4- import { getCurrentBranch , getGitHubContext } from "../git/repository " ;
3+ import { getCurrentBranch , getGitHubContext , GitHubRepoContext } from "../git/repository " ;
4+ import { CurrentBranchRepoNode } from "./current-branch/currentBranchRepoNode " ;
55
6+ import { log , logDebug } from "../log" ;
7+ import { RunStore } from "../store/store" ;
68import { NoRunForBranchNode } from "./current-branch/noRunForBranchNode" ;
7- import { WorkflowJobNode } from "./workflows/workflowJobNode" ;
8- import { WorkflowRunNode } from "./workflows/workflowRunNode" ;
9+ import { NoWorkflowJobsNode } from "./shared/noWorkflowJobsNode" ;
10+ import { WorkflowJobNode } from "./shared/workflowJobNode" ;
11+ import { WorkflowRunNode } from "./shared/workflowRunNode" ;
12+ import { WorkflowRunTreeDataProvider } from "./workflowRunTreeDataProvider" ;
913import { WorkflowStepNode } from "./workflows/workflowStepNode" ;
10- import { logDebug } from "../log" ;
1114
1215type CurrentBranchTreeNode =
1316 | CurrentBranchRepoNode
1417 | WorkflowRunNode
1518 | WorkflowJobNode
19+ | NoWorkflowJobsNode
1620 | WorkflowStepNode
1721 | NoRunForBranchNode ;
1822
19- export class CurrentBranchTreeProvider implements vscode . TreeDataProvider < CurrentBranchTreeNode > {
20- private _onDidChangeTreeData = new vscode . EventEmitter < CurrentBranchTreeNode | null > ( ) ;
23+ export class CurrentBranchTreeProvider
24+ extends WorkflowRunTreeDataProvider
25+ implements vscode . TreeDataProvider < CurrentBranchTreeNode >
26+ {
27+ protected _onDidChangeTreeData = new vscode . EventEmitter < CurrentBranchTreeNode | null > ( ) ;
2128 readonly onDidChangeTreeData = this . _onDidChangeTreeData . event ;
2229
30+ constructor ( store : RunStore ) {
31+ super ( store ) ;
32+ }
33+
34+ protected _updateNode ( node : WorkflowRunNode ) : void {
35+ this . _onDidChangeTreeData . fire ( node ) ;
36+ }
37+
2338 refresh ( ) : void {
2439 this . _onDidChangeTreeData . fire ( null ) ;
2540 }
@@ -36,15 +51,22 @@ export class CurrentBranchTreeProvider implements vscode.TreeDataProvider<Curren
3651 }
3752
3853 if ( gitHubContext . repos . length === 1 ) {
39- return ( await getCurrentBranchWorkflowRunNodes ( gitHubContext . repos [ 0 ] ) ) || [ ] ;
54+ const repoContext = gitHubContext . repos [ 0 ] ;
55+ const currentBranch = getCurrentBranch ( repoContext . repositoryState ) ;
56+ if ( ! currentBranch ) {
57+ log ( `Could not find current branch for ${ repoContext . name } ` ) ;
58+ return [ ] ;
59+ }
60+
61+ return ( await this . getRuns ( repoContext , currentBranch ) ) || [ ] ;
4062 }
4163
42- if ( gitHubContext . repos . length > 1 ) {
64+ if ( gitHubContext . repos . length === 1 ) {
4365 return gitHubContext . repos
4466 . map ( ( repoContext ) : CurrentBranchRepoNode | undefined => {
4567 const currentBranch = getCurrentBranch ( repoContext . repositoryState ) ;
4668 if ( ! currentBranch ) {
47- logDebug ( `Could not find current branch for ${ repoContext . name } ` ) ;
69+ log ( `Could not find current branch for ${ repoContext . name } ` ) ;
4870 return undefined ;
4971 }
5072
@@ -53,7 +75,7 @@ export class CurrentBranchTreeProvider implements vscode.TreeDataProvider<Curren
5375 . filter ( x => x !== undefined ) as CurrentBranchRepoNode [ ] ;
5476 }
5577 } else if ( element instanceof CurrentBranchRepoNode ) {
56- return element . getRuns ( ) ;
78+ return this . getRuns ( element . gitHubRepoContext , element . currentBranchName ) ;
5779 } else if ( element instanceof WorkflowRunNode ) {
5880 return element . getJobs ( ) ;
5981 } else if ( element instanceof WorkflowJobNode ) {
@@ -62,4 +84,24 @@ export class CurrentBranchTreeProvider implements vscode.TreeDataProvider<Curren
6284
6385 return [ ] ;
6486 }
87+
88+ private async getRuns ( gitHubRepoContext : GitHubRepoContext , currentBranchName : string ) : Promise < WorkflowRunNode [ ] > {
89+ logDebug ( "Getting workflow runs" ) ;
90+
91+ const result = await gitHubRepoContext . client . actions . listWorkflowRunsForRepo ( {
92+ owner : gitHubRepoContext . owner ,
93+ repo : gitHubRepoContext . name ,
94+ branch : currentBranchName
95+ } ) ;
96+
97+ const resp = result . data ;
98+ const runs = resp . workflow_runs ;
99+
100+ return runs . map ( wr => {
101+ this . store . updateRun ( wr ) ;
102+ const node = new WorkflowRunNode ( gitHubRepoContext , wr ) ;
103+ this . _runNodes . set ( wr . id , node ) ;
104+ return node ;
105+ } ) ;
106+ }
65107}
0 commit comments