-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathworkflowRunNode.ts
More file actions
67 lines (51 loc) · 2.24 KB
/
workflowRunNode.ts
File metadata and controls
67 lines (51 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as vscode from "vscode";
import {GitHubRepoContext} from "../../git/repository";
import {RunStore} from "../../store/store";
import {WorkflowRun} from "../../store/workflowRun";
import {getIconForWorkflowRun} from "../icons";
import {getEventString, getStatusString} from "./runTooltipHelper";
import {NoWorkflowJobsNode} from "./noWorkflowJobsNode";
import {PreviousAttemptsNode} from "./previousAttemptsNode";
import {WorkflowJobNode} from "./workflowJobNode";
export type WorkflowRunCommandArgs = Pick<WorkflowRunNode, "gitHubRepoContext" | "run" | "store">;
export class WorkflowRunNode extends vscode.TreeItem {
constructor(
public readonly store: RunStore,
public readonly gitHubRepoContext: GitHubRepoContext,
public run: WorkflowRun,
public readonly workflowName?: string
) {
super(WorkflowRunNode._getLabel(run, workflowName), vscode.TreeItemCollapsibleState.Collapsed);
this.updateRun(run);
}
updateRun(run: WorkflowRun) {
this.run = run;
this.label = WorkflowRunNode._getLabel(run, this.workflowName);
this.contextValue = this.run.contextValue(this.gitHubRepoContext.permissionLevel);
this.iconPath = getIconForWorkflowRun(this.run.run);
this.tooltip = this.getTooltip();
}
async getJobs(): Promise<(WorkflowJobNode | NoWorkflowJobsNode | PreviousAttemptsNode)[]> {
const jobs = await this.run.jobs();
const children: (WorkflowJobNode | NoWorkflowJobsNode | PreviousAttemptsNode)[] = jobs.map(
job => new WorkflowJobNode(this.gitHubRepoContext, job)
);
if (this.run.hasPreviousAttempts) {
children.push(new PreviousAttemptsNode(this.gitHubRepoContext, this.run));
}
return children;
}
getTooltip(): vscode.MarkdownString {
let markdownString = "";
if (this.run.hasPreviousAttempts && this.run.run.run_attempt) {
markdownString += `Attempt #${this.run.run.run_attempt} `;
}
markdownString += getStatusString(this.run, markdownString.length == 0);
markdownString += `\n\n`;
markdownString += getEventString(this.run);
return new vscode.MarkdownString(markdownString);
}
private static _getLabel(run: WorkflowRun, workflowName?: string): string {
return `${workflowName ? workflowName + " " : ""}#${run.run.run_number}`;
}
}