Skip to content

Commit abcd792

Browse files
committed
Support deleting variables in the sidebar
1 parent 976e7e8 commit abcd792

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@
192192
"light": "resources/icons/light/edit.svg"
193193
}
194194
},
195+
{
196+
"command": "github-actions.settings.variable.delete",
197+
"category": "GitHub Actions",
198+
"title": "Update variable",
199+
"icon": {
200+
"dark": "resources/icons/dark/remove.svg",
201+
"light": "resources/icons/light/remove.svg"
202+
}
203+
},
195204
{
196205
"command": "github-actions.workflow.pin",
197206
"category": "GitHub Actions",
@@ -331,7 +340,12 @@
331340
},
332341
{
333342
"command": "github-actions.settings.variable.update",
334-
"group": "inline",
343+
"group": "inline@1",
344+
"when": "viewItem == 'repo-variable' || viewItem == 'env-variable'"
345+
},
346+
{
347+
"command": "github-actions.settings.variable.delete",
348+
"group": "inline@2",
335349
"when": "viewItem == 'repo-variable' || viewItem == 'env-variable'"
336350
},
337351
{
@@ -385,6 +399,10 @@
385399
"command": "github-actions.settings.variable.update",
386400
"when": "false"
387401
},
402+
{
403+
"command": "github-actions.settings.variable.delete",
404+
"when": "false"
405+
},
388406
{
389407
"command": "github-actions.workflow.pin",
390408
"when": "false"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as vscode from "vscode";
2+
import {VariableCommandArgs} from "../../treeViews/settings/variableNode";
3+
4+
export function registerDeleteVariable(context: vscode.ExtensionContext) {
5+
context.subscriptions.push(
6+
vscode.commands.registerCommand("github-actions.settings.variable.delete", async (args: VariableCommandArgs) => {
7+
const {gitHubRepoContext, variable, environment} = args;
8+
9+
try {
10+
if (environment) {
11+
await gitHubRepoContext.client.request(
12+
`DELETE /repositories/${gitHubRepoContext.id}/environments/${environment.name}/variables/${variable.name}`
13+
);
14+
} else {
15+
await gitHubRepoContext.client.actions.deleteRepoVariable({
16+
owner: gitHubRepoContext.owner,
17+
repo: gitHubRepoContext.name,
18+
name: variable.name
19+
});
20+
}
21+
} catch (e) {
22+
await vscode.window.showErrorMessage((e as Error).message);
23+
}
24+
25+
await vscode.commands.executeCommand("github-actions.explorer.refresh");
26+
})
27+
);
28+
}

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {registerUpdateSecret} from "./commands/secrets/updateSecret";
1515
import {registerTriggerWorkflowRun} from "./commands/triggerWorkflowRun";
1616
import {registerUnPinWorkflow} from "./commands/unpinWorkflow";
1717
import {registerAddVariable} from "./commands/variables/addVariable";
18+
import {registerDeleteVariable} from "./commands/variables/deleteVariable";
1819
import {registerUpdateVariable} from "./commands/variables/updateVariable";
1920
import {initConfiguration} from "./configuration/configuration";
2021
import {getGitHubContext} from "./git/repository";
@@ -66,6 +67,7 @@ export async function activate(context: vscode.ExtensionContext) {
6667

6768
registerAddVariable(context);
6869
registerUpdateVariable(context);
70+
registerDeleteVariable(context);
6971

7072
registerPinWorkflow(context);
7173
registerUnPinWorkflow(context);

0 commit comments

Comments
 (0)