@@ -15,6 +15,7 @@ import {WorkflowJobNode} from "./shared/workflowJobNode";
1515import { WorkflowRunNode } from "./shared/workflowRunNode" ;
1616import { WorkflowRunTreeDataProvider } from "./workflowRunTreeDataProvider" ;
1717import { WorkflowStepNode } from "./workflows/workflowStepNode" ;
18+ import { match , P } from "ts-pattern" ;
1819
1920type CurrentBranchTreeNode =
2021 | CurrentBranchRepoNode
@@ -87,19 +88,32 @@ export class CurrentBranchTreeProvider
8788 } )
8889 . filter ( x => x !== undefined ) as CurrentBranchRepoNode [ ] ;
8990 }
90- } else if ( element instanceof CurrentBranchRepoNode ) {
91- return this . getRuns ( element . gitHubRepoContext , element . currentBranchName ) ;
92- } else if ( element instanceof WorkflowRunNode ) {
93- return element . getJobs ( ) ;
94- } else if ( element instanceof PreviousAttemptsNode ) {
95- return element . getAttempts ( ) ;
96- } else if ( element instanceof AttemptNode ) {
97- return element . getJobs ( ) ;
98- } else if ( element instanceof WorkflowJobNode ) {
99- return element . getSteps ( ) ;
10091 }
10192
102- return [ ] ;
93+ const result = match ( element )
94+ . with ( P . instanceOf ( CurrentBranchRepoNode ) ,
95+ e => this . getRuns ( e . gitHubRepoContext , e . currentBranchName )
96+ )
97+ . with ( P . instanceOf ( PreviousAttemptsNode ) ,
98+ e => e . getAttempts ( )
99+ )
100+ . with ( P . instanceOf ( AttemptNode ) ,
101+ e => e . getJobs ( )
102+ )
103+ . with ( P . instanceOf ( WorkflowJobNode ) ,
104+ e => e . getSteps ( )
105+ )
106+ . with ( P . instanceOf ( WorkflowRunNode ) ,
107+ e => e . getJobs ( )
108+ )
109+ . otherwise (
110+ e => {
111+ logWarn ( `Unknown class seen during getChildren: ${ e ?. constructor ?. name } . Has it been implemented yet?` ) ;
112+ return Promise . resolve ( [ ] ) ;
113+ }
114+ ) ;
115+
116+ return result ;
103117 }
104118
105119 private async getRuns ( gitHubRepoContext : GitHubRepoContext , currentBranchName : string ) : Promise < WorkflowRunNode [ ] > {
0 commit comments