Skip to content

Commit e3fe7b5

Browse files
authored
Merge pull request #65 from github/joshmgross/create-variables
Support creating variables in the sidebar
2 parents e415d6a + f143327 commit e3fe7b5

5 files changed

Lines changed: 81 additions & 2 deletions

File tree

package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@
174174
"light": "resources/icons/light/remove.svg"
175175
}
176176
},
177+
{
178+
"command": "github-actions.settings.variable.add",
179+
"category": "GitHub Actions",
180+
"title": "Add new variable",
181+
"icon": {
182+
"dark": "resources/icons/dark/add.svg",
183+
"light": "resources/icons/light/add.svg"
184+
}
185+
},
177186
{
178187
"command": "github-actions.workflow.pin",
179188
"category": "GitHub Actions",
@@ -306,6 +315,11 @@
306315
"when": "viewItem == 'secret'",
307316
"group": "inline@2"
308317
},
318+
{
319+
"command": "github-actions.settings.variable.add",
320+
"group": "inline",
321+
"when": "viewItem == 'repo-variables' || viewItem == 'environment-variables'"
322+
},
309323
{
310324
"command": "github-actions.workflow.run.open",
311325
"when": "viewItem =~ /run\\s/",
@@ -349,6 +363,10 @@
349363
"command": "github-actions.settings.secret.delete",
350364
"when": "false"
351365
},
366+
{
367+
"command": "github-actions.settings.variable.add",
368+
"when": "false"
369+
},
352370
{
353371
"command": "github-actions.workflow.pin",
354372
"when": "false"
@@ -414,4 +432,4 @@
414432
"uuid": "^3.3.3",
415433
"vscode-languageclient": "^8.0.2"
416434
}
417-
}
435+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {registerDeleteSecret} from "./commands/secrets/deleteSecret";
1414
import {registerUpdateSecret} from "./commands/secrets/updateSecret";
1515
import {registerTriggerWorkflowRun} from "./commands/triggerWorkflowRun";
1616
import {registerUnPinWorkflow} from "./commands/unpinWorkflow";
17+
import {registerAddVariable} from "./commands/variables/addVariable";
1718
import {initConfiguration} from "./configuration/configuration";
1819
import {getGitHubContext} from "./git/repository";
1920
import {LogScheme} from "./logs/constants";
@@ -62,6 +63,8 @@ export async function activate(context: vscode.ExtensionContext) {
6263
registerCopySecret(context);
6364
registerUpdateSecret(context);
6465

66+
registerAddVariable(context);
67+
6568
registerPinWorkflow(context);
6669
registerUnPinWorkflow(context);
6770

src/treeViews/settings/environmentVariablesNode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import {Environment} from "../../model";
44
import {EmptyNode} from "./emptyNode";
55
import {VariableNode} from "./variableNode";
66

7+
export type EnvironmentVariablesCommandArgs = Pick<EnvironmentVariablesNode, "gitHubRepoContext" | "environment">;
8+
79
export class EnvironmentVariablesNode extends vscode.TreeItem {
810
constructor(public readonly gitHubRepoContext: GitHubRepoContext, public readonly environment: Environment) {
911
super("Variables", vscode.TreeItemCollapsibleState.Collapsed);
1012

1113
this.iconPath = new vscode.ThemeIcon("symbol-text");
14+
15+
this.contextValue = "environment-variables";
1216
}
1317

1418
async getVariables(): Promise<(VariableNode | EmptyNode)[]> {

src/treeViews/settings/repoVariablesNode.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import * as vscode from "vscode";
22
import {GitHubRepoContext} from "../../git/repository";
33
import {VariableNode} from "./variableNode";
44

5+
export type RepoVariablesCommandArgs = Pick<RepoVariablesNode, "gitHubRepoContext">;
6+
57
export class RepoVariablesNode extends vscode.TreeItem {
68
constructor(public readonly gitHubRepoContext: GitHubRepoContext) {
79
super("Repository Variables", vscode.TreeItemCollapsibleState.Collapsed);
810

9-
this.contextValue = "variables";
11+
this.contextValue = "repo-variables";
1012
}
1113

1214
async getVariables(): Promise<vscode.TreeItem[]> {

0 commit comments

Comments
 (0)