Skip to content

Commit abf8a63

Browse files
authored
Merge pull request #66 from github/joshmgross/update-variables
Allow updating variables in the sidebar
2 parents e3fe7b5 + 976e7e8 commit abf8a63

6 files changed

Lines changed: 77 additions & 5 deletions

File tree

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@
183183
"light": "resources/icons/light/add.svg"
184184
}
185185
},
186+
{
187+
"command": "github-actions.settings.variable.update",
188+
"category": "GitHub Actions",
189+
"title": "Update variable",
190+
"icon": {
191+
"dark": "resources/icons/dark/edit.svg",
192+
"light": "resources/icons/light/edit.svg"
193+
}
194+
},
186195
{
187196
"command": "github-actions.workflow.pin",
188197
"category": "GitHub Actions",
@@ -320,6 +329,11 @@
320329
"group": "inline",
321330
"when": "viewItem == 'repo-variables' || viewItem == 'environment-variables'"
322331
},
332+
{
333+
"command": "github-actions.settings.variable.update",
334+
"group": "inline",
335+
"when": "viewItem == 'repo-variable' || viewItem == 'env-variable'"
336+
},
323337
{
324338
"command": "github-actions.workflow.run.open",
325339
"when": "viewItem =~ /run\\s/",
@@ -367,6 +381,10 @@
367381
"command": "github-actions.settings.variable.add",
368382
"when": "false"
369383
},
384+
{
385+
"command": "github-actions.settings.variable.update",
386+
"when": "false"
387+
},
370388
{
371389
"command": "github-actions.workflow.pin",
372390
"when": "false"
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 {VariableCommandArgs} from "../../treeViews/settings/variableNode";
3+
4+
export function registerUpdateVariable(context: vscode.ExtensionContext) {
5+
context.subscriptions.push(
6+
vscode.commands.registerCommand("github-actions.settings.variable.update", async (args: VariableCommandArgs) => {
7+
const {gitHubRepoContext, variable, environment} = args;
8+
9+
const name = await vscode.window.showInputBox({
10+
prompt: "Enter the new variable name",
11+
value: variable.name
12+
});
13+
14+
const value = await vscode.window.showInputBox({
15+
prompt: "Enter the new variable value",
16+
value: variable.value
17+
});
18+
19+
if (name == variable.name && value == variable.value) {
20+
return;
21+
}
22+
23+
const payload: {name?: string; value?: string} = {};
24+
if (name != variable.name) {
25+
payload.name = name;
26+
}
27+
if (value != variable.value) {
28+
payload.value = value;
29+
}
30+
31+
try {
32+
if (environment) {
33+
await gitHubRepoContext.client.request(
34+
`PATCH /repositories/${gitHubRepoContext.id}/environments/${environment.name}/variables/${variable.name}`,
35+
payload
36+
);
37+
} else {
38+
await gitHubRepoContext.client.request(
39+
`PATCH /repos/${gitHubRepoContext.owner}/${gitHubRepoContext.name}/actions/variables/${variable.name}`,
40+
payload
41+
);
42+
}
43+
} catch (e) {
44+
await vscode.window.showErrorMessage((e as Error).message);
45+
}
46+
47+
await vscode.commands.executeCommand("github-actions.explorer.refresh");
48+
})
49+
);
50+
}

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {registerUpdateSecret} from "./commands/secrets/updateSecret";
1515
import {registerTriggerWorkflowRun} from "./commands/triggerWorkflowRun";
1616
import {registerUnPinWorkflow} from "./commands/unpinWorkflow";
1717
import {registerAddVariable} from "./commands/variables/addVariable";
18+
import {registerUpdateVariable} from "./commands/variables/updateVariable";
1819
import {initConfiguration} from "./configuration/configuration";
1920
import {getGitHubContext} from "./git/repository";
2021
import {LogScheme} from "./logs/constants";
@@ -64,6 +65,7 @@ export async function activate(context: vscode.ExtensionContext) {
6465
registerUpdateSecret(context);
6566

6667
registerAddVariable(context);
68+
registerUpdateVariable(context);
6769

6870
registerPinWorkflow(context);
6971
registerUnPinWorkflow(context);

src/treeViews/settings/environmentVariablesNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class EnvironmentVariablesNode extends vscode.TreeItem {
2323
environment_name: this.environment.name,
2424
per_page: 100
2525
},
26-
response => response.data.map(v => new VariableNode(this.gitHubRepoContext, v, "env"))
26+
response => response.data.map(v => new VariableNode(this.gitHubRepoContext, v, this.environment))
2727
);
2828

2929
if (!variables || variables.length === 0) {

src/treeViews/settings/repoVariablesNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class RepoVariablesNode extends vscode.TreeItem {
1919
repo: this.gitHubRepoContext.name,
2020
per_page: 100
2121
},
22-
response => response.data.map(s => new VariableNode(this.gitHubRepoContext, s, "repo"))
22+
response => response.data.map(s => new VariableNode(this.gitHubRepoContext, s))
2323
);
2424
}
2525
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import * as vscode from "vscode";
22
import {GitHubRepoContext} from "../../git/repository";
3-
import {EnvironmentVariable, RepoVariable} from "../../model";
3+
import {Environment, EnvironmentVariable, RepoVariable} from "../../model";
4+
5+
export type VariableCommandArgs = Pick<VariableNode, "gitHubRepoContext" | "variable" | "environment">;
46

57
export class VariableNode extends vscode.TreeItem {
68
constructor(
79
public readonly gitHubRepoContext: GitHubRepoContext,
810
public readonly variable: EnvironmentVariable | RepoVariable,
9-
public readonly contextPrefix: string
11+
public readonly environment?: Environment
1012
) {
1113
super(variable.name);
1214
this.description = variable.value;
1315

14-
this.contextValue = contextPrefix ? `${contextPrefix}-variable` : "variable";
16+
this.contextValue = environment ? "env-variable" : "repo-variable";
1517
}
1618
}

0 commit comments

Comments
 (0)