@@ -8,8 +8,39 @@ export abstract class GithubActionTreeNode extends vscode.TreeItem {
88 getChildren ( ) : vscode . ProviderResult < GithubActionTreeNode [ ] > {
99 return [ ] ;
1010 }
11+
12+ /** Calculate the time a run, job, or step took to run. If completed_at is not specified, return duration to the current time */
13+ protected getNodeDuration ( { started_at, completed_at} : {
14+ started_at ?: string | null ;
15+ completed_at ?: string | null ;
16+ } ) : string | undefined {
17+ if ( ! started_at ) return undefined ;
18+ const started = new Date ( started_at ) ;
19+ const completed = completed_at ? new Date ( completed_at ) : new Date ( ) ;
20+ return this . getHumanizedDuration ( started , completed ) ;
21+ }
22+
23+ protected getHumanizedDuration ( started : Date , completed : Date = new Date ( ) ) : string | undefined {
24+ const diffMs = Math . max ( 0 , completed . getTime ( ) - started . getTime ( ) ) ;
25+ const diffSeconds = Math . floor ( diffMs / 1000 ) ;
26+
27+ let remaining = diffSeconds ;
28+ const hours = Math . floor ( remaining / 3600 ) ;
29+ remaining %= 3600 ;
30+ const minutes = Math . floor ( remaining / 60 ) ;
31+ const seconds = remaining % 60 ;
32+
33+ const parts : string [ ] = [ ] ;
34+ if ( hours > 0 ) parts . push ( `${ hours } h` ) ;
35+ if ( minutes > 0 ) parts . push ( `${ minutes } m` ) ;
36+ if ( seconds > 0 ) parts . push ( `${ seconds } s` ) ;
37+
38+ return parts . slice ( 0 , 2 ) . join ( " " ) || "0s" ;
39+ }
1140}
1241
42+
43+
1344/** Provides the base infrastructure for interfacing the Github Actions API to the vscode tree view */
1445export abstract class GithubActionTreeDataProvider <
1546 T extends GithubActionTreeNode
0 commit comments