File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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" ,
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/" ,
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"
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {registerUpdateSecret} from "./commands/secrets/updateSecret";
1515import { registerTriggerWorkflowRun } from "./commands/triggerWorkflowRun" ;
1616import { registerUnPinWorkflow } from "./commands/unpinWorkflow" ;
1717import { registerAddVariable } from "./commands/variables/addVariable" ;
18+ import { registerUpdateVariable } from "./commands/variables/updateVariable" ;
1819import { initConfiguration } from "./configuration/configuration" ;
1920import { getGitHubContext } from "./git/repository" ;
2021import { 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 ) ;
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 11import * as vscode from "vscode" ;
22import { 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
57export 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}
You can’t perform that action at this time.
0 commit comments