Skip to content

Commit 42f9f58

Browse files
committed
✨ Add Job and Step node completion times
1 parent b64d6bd commit 42f9f58

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/treeViews/githubActionTreeDataProvider.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */
1445
export abstract class GithubActionTreeDataProvider<
1546
T extends GithubActionTreeNode

src/treeViews/shared/workflowJobNode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class WorkflowJobNode extends GithubActionTreeNode {
1515
this.contextValue = "job";
1616
if (this.job.status === "completed") {
1717
this.contextValue += " completed";
18+
this.description = this.getNodeDuration(this.job);
1819
}
1920

2021
this.iconPath = getIconForWorkflowNode(this.job);

src/treeViews/shared/workflowStepNode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class WorkflowStepNode extends GithubActionTreeNode {
1414
this.contextValue = "step";
1515
if (this.step.status === "completed") {
1616
this.contextValue += " completed";
17+
this.description = this.getNodeDuration(this.step);
1718
}
1819

1920
this.iconPath = getIconForWorkflowNode(this.step);

0 commit comments

Comments
 (0)