|
| 1 | +import * as vscode from "vscode"; |
| 2 | +import {EnvironmentVariablesCommandArgs} from "../../treeViews/settings/environmentVariablesNode"; |
| 3 | +import {RepoVariablesCommandArgs} from "../../treeViews/settings/repoVariablesNode"; |
| 4 | + |
| 5 | +type Args = RepoVariablesCommandArgs | EnvironmentVariablesCommandArgs; |
| 6 | + |
| 7 | +export function registerAddVariable(context: vscode.ExtensionContext) { |
| 8 | + context.subscriptions.push( |
| 9 | + vscode.commands.registerCommand("github-actions.settings.variable.add", async (args: Args) => { |
| 10 | + const {gitHubRepoContext} = args; |
| 11 | + |
| 12 | + const name = await vscode.window.showInputBox({ |
| 13 | + prompt: "Enter name for new variable", |
| 14 | + placeHolder: "Variable name" |
| 15 | + }); |
| 16 | + |
| 17 | + if (!name) { |
| 18 | + return; |
| 19 | + } |
| 20 | + |
| 21 | + const value = await vscode.window.showInputBox({ |
| 22 | + prompt: "Enter the new variable value" |
| 23 | + }); |
| 24 | + |
| 25 | + if (!value) { |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + try { |
| 30 | + if ("environment" in args) { |
| 31 | + await gitHubRepoContext.client.actions.createEnvironmentVariable({ |
| 32 | + repository_id: gitHubRepoContext.id, |
| 33 | + environment_name: args.environment.name, |
| 34 | + name, |
| 35 | + value |
| 36 | + }); |
| 37 | + } else { |
| 38 | + await gitHubRepoContext.client.actions.createRepoVariable({ |
| 39 | + owner: gitHubRepoContext.owner, |
| 40 | + repo: gitHubRepoContext.name, |
| 41 | + name, |
| 42 | + value |
| 43 | + }); |
| 44 | + } |
| 45 | + } catch (e) { |
| 46 | + await vscode.window.showErrorMessage((e as Error).message); |
| 47 | + } |
| 48 | + |
| 49 | + await vscode.commands.executeCommand("github-actions.explorer.refresh"); |
| 50 | + }) |
| 51 | + ); |
| 52 | +} |
0 commit comments