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
82 changes: 0 additions & 82 deletions src/commands/secrets/addSecret.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/commands/secrets/copySecret.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/commands/secrets/deleteSecret.ts

This file was deleted.

29 changes: 0 additions & 29 deletions src/commands/secrets/updateSecret.ts

This file was deleted.

113 changes: 113 additions & 0 deletions src/commands/settings/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

import * as vscode from "vscode";
import {GitHubRepoContext} from "../../git/repository";
import {encodeSecret} from "../../secrets";
import {EnvironmentSecretsCommandArgs} from "../../treeViews/settings/environmentSecretsNode";
import {EnvironmentVariablesCommandArgs} from "../../treeViews/settings/environmentVariablesNode";
import {RepoSecretsCommandArgs} from "../../treeViews/settings/repoSecretsNode";
import {RepoVariablesCommandArgs} from "../../treeViews/settings/repoVariablesNode";

type AddCommandArgs =
| RepoSecretsCommandArgs
| EnvironmentSecretsCommandArgs
| RepoVariablesCommandArgs
| EnvironmentVariablesCommandArgs;

type SettingType = "secret" | "variable";

export function registerAddSetting(context: vscode.ExtensionContext, type: SettingType) {
context.subscriptions.push(
vscode.commands.registerCommand(
`github-actions.settings.${type}.add`,
async (args: AddCommandArgs) => {
const {gitHubRepoContext} = args;

const name = await vscode.window.showInputBox({
prompt: `Enter name for new ${type}`,
ignoreFocusOut: true
});

if (!name) {
return;
}

const value = await vscode.window.showInputBox({
prompt: `Enter the new ${type} value`,
ignoreFocusOut: true
});

if (!value) {
return;
}

try {
if (type === "secret") {
if ("environment" in args) {
await createOrUpdateEnvSecret(gitHubRepoContext, args.environment.name, name, value);
} else {
await createOrUpdateRepoSecret(gitHubRepoContext, name, value);
}
} else {
if ("environment" in args) {
await gitHubRepoContext.client.actions.createEnvironmentVariable({
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
environment_name: args.environment.name,
name,
value
});
} else {
await gitHubRepoContext.client.actions.createRepoVariable({
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
name,
value
});
}
}
} catch (e) {
await vscode.window.showErrorMessage((e as Error).message);
}

await vscode.commands.executeCommand("github-actions.explorer.refresh");
}
)
);
}

export async function createOrUpdateRepoSecret(context: GitHubRepoContext, name: string, value: string) {
const keyResponse = await context.client.actions.getRepoPublicKey({
owner: context.owner,
repo: context.name
});

await context.client.actions.createOrUpdateRepoSecret({
owner: context.owner,
repo: context.name,
secret_name: name,
key_id: keyResponse.data.key_id,
encrypted_value: await encodeSecret(keyResponse.data.key, value)
});
}

export async function createOrUpdateEnvSecret(
context: GitHubRepoContext,
environment: string,
name: string,
value: string
) {
const keyResponse = await context.client.actions.getEnvironmentPublicKey({
owner: context.owner,
repo: context.name,
environment_name: environment
});

await context.client.actions.createOrUpdateEnvironmentSecret({
owner: context.owner,
repo: context.name,
environment_name: environment,
secret_name: name,
key_id: keyResponse.data.key_id,
encrypted_value: await encodeSecret(keyResponse.data.key, value)
});
}
31 changes: 31 additions & 0 deletions src/commands/settings/copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import * as vscode from "vscode";
import {SecretCommandArgs} from "../../treeViews/settings/secretNode";
import {VariableCommandArgs} from "../../treeViews/settings/variableNode";

type CopyCommandArgs = SecretCommandArgs | VariableCommandArgs;
type SettingType = "secret" | "variable";
type CopyPart = "name" | "value";

export function registerCopySetting(context: vscode.ExtensionContext, type: SettingType, part?: CopyPart) {
const command = part ? `github-actions.settings.${type}.copy-${part}` : `github-actions.settings.${type}.copy`;

context.subscriptions.push(
vscode.commands.registerCommand(command, async (args: CopyCommandArgs) => {
let value: string;
if (type === "secret") {
value = (args as SecretCommandArgs).secret.name;
} else {
if (part === "name") {
value = (args as VariableCommandArgs).variable.name;
} else {
value = (args as VariableCommandArgs).variable.value;
}
}

await vscode.env.clipboard.writeText(value);

vscode.window.setStatusBarMessage(`Copied ${value}`, 2000);
})
);
}
73 changes: 73 additions & 0 deletions src/commands/settings/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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");
}
)
);
}
Loading