Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 98ed009

Browse files
committed
Add secrets commands
1 parent 8686c09 commit 98ed009

9 files changed

Lines changed: 280 additions & 193 deletions

File tree

src/commands/cancelWorkflowRun.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as vscode from "vscode";
2+
import { GitHubRepoContext } from "../git/repository";
3+
import { WorkflowRun } from "../model";
4+
5+
interface CancelWorkflowRunLogsCommandArgs {
6+
gitHubRepoContext: GitHubRepoContext;
7+
run: WorkflowRun;
8+
}
9+
10+
export function registerCancelWorkflowRun(context: vscode.ExtensionContext) {
11+
context.subscriptions.push(
12+
vscode.commands.registerCommand(
13+
"github-actions.workflow.run.cancel",
14+
async (args: CancelWorkflowRunLogsCommandArgs) => {
15+
const gitHubContext = args.gitHubRepoContext;
16+
const run = args.run;
17+
18+
try {
19+
await gitHubContext.client.actions.cancelWorkflowRun({
20+
owner: gitHubContext.owner,
21+
repo: gitHubContext.name,
22+
run_id: run.id,
23+
});
24+
} catch (e) {
25+
vscode.window.showErrorMessage(
26+
`Could not cancel workflow: '${e.message}'`
27+
);
28+
}
29+
30+
vscode.commands.executeCommand("github-actions.explorer.refresh");
31+
}
32+
)
33+
);
34+
}

src/commands/orgLogin.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as vscode from "vscode";
2+
import { enableOrgFeatures } from "../auth/auth";
3+
4+
export function registerOrgLogin(context: vscode.ExtensionContext) {
5+
context.subscriptions.push(
6+
vscode.commands.registerCommand(
7+
"github-actions.auth.org-login",
8+
async () => {
9+
enableOrgFeatures();
10+
}
11+
)
12+
);
13+
}

src/commands/rerunWorkflowRun.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as vscode from "vscode";
2+
import { GitHubRepoContext } from "../git/repository";
3+
import { WorkflowRun } from "../model";
4+
5+
export interface ReRunWorkflowRunLogsCommandArgs {
6+
gitHubRepoContext: GitHubRepoContext;
7+
run: WorkflowRun;
8+
}
9+
10+
export function registerReRunWorkflowRun(context: vscode.ExtensionContext) {
11+
context.subscriptions.push(
12+
vscode.commands.registerCommand(
13+
"github-actions.workflow.run.rerun",
14+
async (args: ReRunWorkflowRunLogsCommandArgs) => {
15+
const gitHubContext = args.gitHubRepoContext;
16+
const run = args.run;
17+
18+
try {
19+
await gitHubContext.client.actions.reRunWorkflow({
20+
owner: gitHubContext.owner,
21+
repo: gitHubContext.name,
22+
run_id: run.id,
23+
});
24+
} catch (e) {
25+
vscode.window.showErrorMessage(
26+
`Could not rerun workflow: '${e.message}'`
27+
);
28+
}
29+
30+
vscode.commands.executeCommand("github-actions.explorer.refresh");
31+
}
32+
)
33+
);
34+
}

src/commands/secrets/addSecret.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as vscode from "vscode";
2+
import { GitHubRepoContext } from "../../git/repository";
3+
import { encodeSecret } from "../../secrets";
4+
5+
interface AddSecretCommandArgs {
6+
gitHubRepoContext: GitHubRepoContext;
7+
}
8+
9+
export function registerAddSecret(context: vscode.ExtensionContext) {
10+
context.subscriptions.push(
11+
vscode.commands.registerCommand(
12+
"github-actions.settings.secret.add",
13+
async (args: AddSecretCommandArgs) => {
14+
const gitHubContext = args.gitHubRepoContext;
15+
16+
const name = await vscode.window.showInputBox({
17+
prompt: "Enter name for new secret",
18+
});
19+
20+
if (!name) {
21+
return;
22+
}
23+
24+
const value = await vscode.window.showInputBox({
25+
prompt: "Enter the new secret value",
26+
});
27+
28+
if (value) {
29+
try {
30+
const keyResponse =
31+
await gitHubContext.client.actions.getRepoPublicKey({
32+
owner: gitHubContext.owner,
33+
repo: gitHubContext.name,
34+
});
35+
36+
const key_id = keyResponse.data.key_id;
37+
const key = keyResponse.data.key;
38+
39+
await gitHubContext.client.actions.createOrUpdateRepoSecret({
40+
owner: gitHubContext.owner,
41+
repo: gitHubContext.name,
42+
secret_name: name,
43+
key_id: key_id,
44+
encrypted_value: encodeSecret(key, value),
45+
});
46+
} catch (e) {
47+
vscode.window.showErrorMessage(e.message);
48+
}
49+
}
50+
51+
vscode.commands.executeCommand("github-actions.explorer.refresh");
52+
}
53+
)
54+
);
55+
}

src/commands/secrets/copySecret.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as vscode from "vscode";
2+
import { GitHubRepoContext } from "../../git/repository";
3+
import { EnvironmentSecret, OrgSecret, RepoSecret } from "../../model";
4+
5+
interface CopySecretCommandArgs {
6+
gitHubRepoContext: GitHubRepoContext;
7+
secret: RepoSecret | OrgSecret | EnvironmentSecret;
8+
}
9+
10+
export function registerCopySecret(context: vscode.ExtensionContext) {
11+
context.subscriptions.push(
12+
vscode.commands.registerCommand(
13+
"github-actions.settings.secret.copy",
14+
async (args: CopySecretCommandArgs) => {
15+
const { secret } = args;
16+
17+
vscode.env.clipboard.writeText(secret.name);
18+
19+
vscode.window.setStatusBarMessage(`Copied ${secret.name}`, 2000);
20+
}
21+
)
22+
);
23+
}
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 { GitHubRepoContext } from "../../git/repository";
3+
import { RepoSecret } from "../../model";
4+
5+
interface DeleteSecretCommandArgs {
6+
gitHubRepoContext: GitHubRepoContext;
7+
secret: RepoSecret;
8+
}
9+
10+
export function registerDeleteSecret(context: vscode.ExtensionContext) {
11+
context.subscriptions.push(
12+
vscode.commands.registerCommand(
13+
"github-actions.settings.secret.delete",
14+
async (args: DeleteSecretCommandArgs) => {
15+
const gitHubContext = args.gitHubRepoContext;
16+
const secret = args.secret;
17+
18+
await gitHubContext.client.actions.deleteRepoSecret({
19+
owner: gitHubContext.owner,
20+
repo: gitHubContext.name,
21+
secret_name: secret.name,
22+
});
23+
24+
vscode.commands.executeCommand("github-actions.explorer.refresh");
25+
}
26+
)
27+
);
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as vscode from "vscode";
2+
import { GitHubRepoContext } from "../../git/repository";
3+
import { WorkflowRun } from "../../model";
4+
5+
interface ManageOrgSecretsCommandArgs {
6+
gitHubRepoContext: GitHubRepoContext;
7+
run: WorkflowRun;
8+
}
9+
10+
export function registerManageOrgSecrets(context: vscode.ExtensionContext) {
11+
context.subscriptions.push(
12+
vscode.commands.registerCommand(
13+
"github-actions.settings.secrets.manage",
14+
async (args: ManageOrgSecretsCommandArgs) => {
15+
const gitHubContext = args.gitHubRepoContext;
16+
17+
// Open link to manage org-secrets
18+
vscode.commands.executeCommand(
19+
"vscode.open",
20+
vscode.Uri.parse(
21+
`https://github.com/organizations/${gitHubContext.owner}/settings/secrets`
22+
)
23+
);
24+
}
25+
)
26+
);
27+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as vscode from "vscode";
2+
import { GitHubRepoContext } from "../../git/repository";
3+
import { RepoSecret } from "../../model";
4+
import { encodeSecret } from "../../secrets";
5+
6+
interface UpdateSecretCommandArgs {
7+
gitHubRepoContext: GitHubRepoContext;
8+
secret: RepoSecret;
9+
}
10+
11+
export function registerUpdateSecret(context: vscode.ExtensionContext) {
12+
context.subscriptions.push(
13+
vscode.commands.registerCommand(
14+
"github-actions.settings.secret.update",
15+
async (args: UpdateSecretCommandArgs) => {
16+
const gitHubContext = args.gitHubRepoContext;
17+
const secret: RepoSecret = args.secret;
18+
19+
const value = await vscode.window.showInputBox({
20+
prompt: "Enter the new secret value",
21+
});
22+
23+
if (!value) {
24+
return;
25+
}
26+
27+
try {
28+
const keyResponse =
29+
await gitHubContext.client.actions.getRepoPublicKey({
30+
owner: gitHubContext.owner,
31+
repo: gitHubContext.name,
32+
});
33+
34+
const key_id = keyResponse.data.key_id;
35+
const key = keyResponse.data.key;
36+
37+
await gitHubContext.client.actions.createOrUpdateRepoSecret({
38+
owner: gitHubContext.owner,
39+
repo: gitHubContext.name,
40+
secret_name: secret.name,
41+
key_id: key_id,
42+
encrypted_value: encodeSecret(key, value),
43+
});
44+
} catch (e) {
45+
vscode.window.showErrorMessage(e.message);
46+
}
47+
}
48+
)
49+
);
50+
}

0 commit comments

Comments
 (0)