Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@
"title": "Cancel workflow run",
"when": "viewItem =~ /run/ && viewItem =~ /cancelable/"
},
{
"command": "github-actions.workflow.run.delete",
"category": "GitHub Actions",
"title": "Delete workflow run",
"when": "viewItem =~ /run/ && viewItem =~ /deletable/",
"icon": "$(trash)"
},
{
"command": "github-actions.settings.secrets.manage",
"category": "GitHub Actions",
Expand Down Expand Up @@ -405,6 +412,11 @@
"command": "github-actions.workflow.run.rerun",
"when": "viewItem =~ /run/ && viewItem =~ /rerunnable/"
},
{
"command": "github-actions.workflow.run.delete",
"when": "viewItem =~ /run/ && viewItem =~ /deletable/",
"group": "inline@3"
},
{
"command": "github-actions.settings.secret.add",
"group": "inline",
Expand Down Expand Up @@ -484,6 +496,10 @@
"command": "github-actions.workflow.run.cancel",
"when": "false"
},
{
"command": "github-actions.workflow.run.delete",
"when": "false"
},
{
"command": "github-actions.settings.secrets.manage",
"when": "false"
Expand Down
39 changes: 39 additions & 0 deletions src/commands/deleteWorkflowRun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as vscode from "vscode";
import {WorkflowRunCommandArgs} from "../treeViews/shared/workflowRunNode";

export function registerDeleteWorkflowRun(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand("github-actions.workflow.run.delete", async (args: WorkflowRunCommandArgs) => {
const {gitHubRepoContext, run} = args;
const acceptText = "Yes, delete this workflow run";
const answer = await vscode.window.showWarningMessage(
`Are you sure you want to delete workflow run #${run.run.run_number}?`,
{
modal: true,
detail: "Deleting this workflow run, its logs, and its artifacts cannot be undone"
},
acceptText
);

if (answer !== acceptText) {
return;
}

try {
await gitHubRepoContext.client.actions.deleteWorkflowRun({
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
run_id: run.run.id
});
} catch (e) {
await vscode.window.showErrorMessage(`Could not delete workflow run: '${(e as Error).message}'`);
return;
}

await Promise.all([
vscode.commands.executeCommand("github-actions.explorer.refresh"),
vscode.commands.executeCommand("github-actions.explorer.current-branch.refresh")
]);
})
);
}
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as vscode from "vscode";
import {canReachGitHubAPI} from "./api/canReachGitHubAPI";
import {getSession} from "./auth/auth";
import {registerCancelWorkflowRun} from "./commands/cancelWorkflowRun";
import {registerDeleteWorkflowRun} from "./commands/deleteWorkflowRun";
import {registerOpenWorkflowFile} from "./commands/openWorkflowFile";
import {registerOpenWorkflowJobLogs} from "./commands/openWorkflowJobLogs";
import {registerOpenWorkflowStepLogs} from "./commands/openWorkflowStepLogs";
Expand Down Expand Up @@ -78,6 +79,7 @@ export async function activate(context: vscode.ExtensionContext) {
registerTriggerWorkflowRun(context);
registerReRunWorkflowRun(context);
registerCancelWorkflowRun(context);
registerDeleteWorkflowRun(context);

registerAddSecret(context);
registerDeleteSecret(context);
Expand Down
13 changes: 3 additions & 10 deletions src/store/workflowRun.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as vscode from "vscode";
import {GitHubRepoContext} from "../git/repository";
import {RepositoryPermission, hasWritePermission} from "../git/repository-permissions";
import {RepositoryPermission} from "../git/repository-permissions";
import {log, logDebug} from "../log";
import * as model from "../model";
import {WorkflowJob} from "./WorkflowJob";
import {getWorkflowRunContextValue} from "./workflowRunContext";

abstract class WorkflowRunBase {
protected _gitHubRepoContext: GitHubRepoContext;
Expand Down Expand Up @@ -53,15 +54,7 @@ abstract class WorkflowRunBase {
}

contextValue(permission: RepositoryPermission): string {
const contextValues = ["run"];
const completed = this._run.status === "completed";
if (hasWritePermission(permission)) {
contextValues.push(completed ? "rerunnable" : "cancelable");
}
if (completed) {
contextValues.push("completed");
}
return contextValues.join(" ");
return getWorkflowRunContextValue(this._run.status, permission);
}

protected abstract fetchJobs(): Promise<WorkflowJob[]>;
Expand Down
12 changes: 12 additions & 0 deletions src/store/workflowRunContext.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {getWorkflowRunContextValue} from "./workflowRunContext";

describe("getWorkflowRunContextValue", () => {
it.each([
["read", "completed", "run completed"],
["write", "queued", "run cancelable"],
["write", "completed", "run rerunnable deletable completed"],
["admin", "completed", "run rerunnable deletable completed"]
] as const)("returns the available actions for %s access to a %s run", (permission, status, expected) => {
expect(getWorkflowRunContextValue(status, permission)).toBe(expected);
});
});
19 changes: 19 additions & 0 deletions src/store/workflowRunContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {RepositoryPermission, hasWritePermission} from "../git/repository-permissions";

export function getWorkflowRunContextValue(status: string | null, permission: RepositoryPermission): string {
const contextValues = ["run"];
const completed = status === "completed";

if (hasWritePermission(permission)) {
contextValues.push(completed ? "rerunnable" : "cancelable");
if (completed) {
contextValues.push("deletable");
}
}

if (completed) {
contextValues.push("completed");
}

return contextValues.join(" ");
}