-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathdelete.ts
More file actions
73 lines (68 loc) · 2.72 KB
/
delete.ts
File metadata and controls
73 lines (68 loc) · 2.72 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
68
69
70
71
72
73
import * as vscode from "vscode";
import {SecretCommandArgs} from "../../treeViews/settings/secretNode";
import {VariableCommandArgs} from "../../treeViews/settings/variableNode";
type DeleteCommandArgs = SecretCommandArgs | VariableCommandArgs;
type SettingType = "secret" | "variable";
export function registerDeleteSetting(context: vscode.ExtensionContext, type: SettingType) {
context.subscriptions.push(
vscode.commands.registerCommand(
`github-actions.settings.${type}.delete`,
async (args: DeleteCommandArgs) => {
const {gitHubRepoContext, environment} = args;
let name: string;
if (type === "secret") {
name = (args as SecretCommandArgs).secret.name;
} else {
name = (args as VariableCommandArgs).variable.name;
}
const acceptText = `Yes, delete this ${type}`;
try {
await vscode.window
.showInformationMessage(
`Are you sure you want to delete ${name}?`,
{
modal: true,
detail: `Deleting this ${type} cannot be undone and may impact workflows in this repository`
},
acceptText
)
.then(async answer => {
if (answer === acceptText) {
if (type === "secret") {
if (environment) {
await gitHubRepoContext.client.actions.deleteEnvironmentSecret({
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
environment_name: environment.name,
secret_name: name
});
} else {
await gitHubRepoContext.client.actions.deleteRepoSecret({
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
secret_name: name
});
}
} else {
if (environment) {
await gitHubRepoContext.client.request(
`DELETE /repositories/${gitHubRepoContext.id}/environments/${environment.name}/variables/${name}`
);
} else {
await gitHubRepoContext.client.actions.deleteRepoVariable({
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
name: name
});
}
}
}
});
} catch (e) {
await vscode.window.showErrorMessage((e as Error).message);
}
await vscode.commands.executeCommand("github-actions.explorer.refresh");
}
)
);
}