Skip to content

Commit 7cd8e7f

Browse files
committed
Hide cancel and re-run button based on permissions
1 parent 589fcdb commit 7cd8e7f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/treeViews/shared/workflowRunNode.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from "vscode";
22

33
import {GitHubRepoContext} from "../../git/repository";
4+
import {RepositoryPermission, hasWritePermission} from "../../git/repository-permissions";
45
import {RunStore} from "../../store/store";
56
import {WorkflowRun} from "../../store/workflowRun";
67
import {getIconForWorkflowRun} from "../icons";
@@ -20,18 +21,22 @@ export class WorkflowRunNode extends vscode.TreeItem {
2021
) {
2122
super(WorkflowRunNode._getLabel(run, workflowName), vscode.TreeItemCollapsibleState.Collapsed);
2223

23-
this.updateRun(run);
24+
this.updateRun(run, gitHubRepoContext.permissionLevel);
2425
}
2526

26-
updateRun(run: WorkflowRun) {
27+
updateRun(run: WorkflowRun, permissionLevel: RepositoryPermission) {
2728
this.run = run;
2829
this.label = WorkflowRunNode._getLabel(run, this.workflowName);
2930

30-
if (this.run.run.status === "completed") {
31-
this.contextValue = "run rerunnable completed";
32-
} else {
33-
this.contextValue = "run cancelable";
31+
const contextValues = ["run"];
32+
const completed = this.run.run.status === "completed";
33+
if (hasWritePermission(permissionLevel)) {
34+
contextValues.push(completed ? "rerunnable" : "cancelable");
3435
}
36+
if (completed) {
37+
contextValues.push("completed");
38+
}
39+
this.contextValue = contextValues.join(" ");
3540

3641
this.iconPath = getIconForWorkflowRun(this.run.run);
3742
this.tooltip = this.getTooltip();

0 commit comments

Comments
 (0)