Skip to content

Commit ec7e1c6

Browse files
committed
Show org secrets and variables in the sidebar
1 parent ea32d09 commit ec7e1c6

11 files changed

Lines changed: 127 additions & 18 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
},
336336
{
337337
"command": "github-actions.settings.secret.copy",
338-
"when": "viewItem == 'repo-secret'",
338+
"when": "viewItem == 'repo-secret' || viewItem == 'env-secret' || viewItem == 'org-secret'",
339339
"group": "context"
340340
},
341341
{
@@ -360,12 +360,12 @@
360360
},
361361
{
362362
"command": "github-actions.settings.variable.copy-name",
363-
"when": "viewItem == 'repo-variable' || viewItem == 'env-variable'",
363+
"when": "viewItem == 'repo-variable' || viewItem == 'env-variable' || viewItem == 'org-variable'",
364364
"group": "context"
365365
},
366366
{
367367
"command": "github-actions.settings.variable.copy-value",
368-
"when": "viewItem == 'repo-variable' || viewItem == 'env-variable'",
368+
"when": "viewItem == 'repo-variable' || viewItem == 'env-variable' || viewItem == 'org-variable'",
369369
"group": "context"
370370
},
371371
{

src/commands/secrets/updateSecret.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import * as vscode from "vscode";
2-
import {RepoSecret} from "../../model";
32
import {encodeSecret} from "../../secrets";
43
import {SecretCommandArgs} from "../../treeViews/settings/secretNode";
54

65
export function registerUpdateSecret(context: vscode.ExtensionContext) {
76
context.subscriptions.push(
87
vscode.commands.registerCommand("github-actions.settings.secret.update", async (args: SecretCommandArgs) => {
98
const gitHubContext = args.gitHubRepoContext;
10-
const secret: RepoSecret = args.secret;
9+
const secret = args.secret;
1110

1211
const value = await vscode.window.showInputBox({
1312
prompt: "Enter the new secret value"

src/model.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ export type EnvironmentSecret = OctokitData<"listEnvironmentSecrets", "secrets">
4242

4343
export type EnvironmentVariable = OctokitData<"listEnvironmentVariables", "variables">;
4444

45+
export type OrgSecret = {name: string};
46+
47+
export type OrgVariable = {name: string; value: string};
48+
4549
export type SelfHostedRunner = OctokitData<"listSelfHostedRunnersForRepo", "runners">;

src/treeViews/settings.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {RepoVariablesNode} from "./settings/repoVariablesNode";
1313
import {VariablesNode} from "./settings/variablesNode";
1414
import {EnvironmentSecretsNode} from "./settings/environmentSecretsNode";
1515
import {EnvironmentVariablesNode} from "./settings/environmentVariablesNode";
16+
import {OrgVariablesNode} from "./settings/orgVariablesNode";
17+
import {OrgSecretsNode} from "./settings/orgSecretsNode";
1618

1719
export class SettingsTreeProvider implements vscode.TreeDataProvider<SettingsExplorerNode> {
1820
private _onDidChangeTreeData = new vscode.EventEmitter<SettingsExplorerNode | null>();
@@ -50,21 +52,21 @@ export class SettingsTreeProvider implements vscode.TreeDataProvider<SettingsExp
5052
// Secrets
5153
//
5254
if (element instanceof SecretsNode) {
53-
return [new RepoSecretsNode(element.gitHubRepoContext)];
55+
return element.nodes;
5456
}
5557

56-
if (element instanceof RepoSecretsNode) {
58+
if (element instanceof RepoSecretsNode || element instanceof OrgSecretsNode) {
5759
return element.getSecrets();
5860
}
5961

6062
//
6163
// Variables
6264
//
6365
if (element instanceof VariablesNode) {
64-
return [new RepoVariablesNode(element.gitHubRepoContext)];
66+
return element.nodes;
6567
}
6668

67-
if (element instanceof RepoVariablesNode) {
69+
if (element instanceof RepoVariablesNode || element instanceof OrgVariablesNode) {
6870
return element.getVariables();
6971
}
7072

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as vscode from "vscode";
2+
import {GitHubRepoContext} from "../../git/repository";
3+
import {OrgSecret} from "../../model";
4+
import {EmptyNode} from "./emptyNode";
5+
import {SecretNode} from "./secretNode";
6+
7+
export class OrgSecretsNode extends vscode.TreeItem {
8+
constructor(public readonly gitHubRepoContext: GitHubRepoContext) {
9+
super("Organization Secrets", vscode.TreeItemCollapsibleState.Collapsed);
10+
11+
this.contextValue = "org-secrets";
12+
}
13+
14+
async getSecrets(): Promise<vscode.TreeItem[]> {
15+
let secrets: OrgSecret[] = [];
16+
try {
17+
secrets = await this.gitHubRepoContext.client.paginate("GET /repos/{owner}/{repo}/actions/organization-secrets", {
18+
owner: this.gitHubRepoContext.owner,
19+
repo: this.gitHubRepoContext.name,
20+
per_page: 100
21+
});
22+
} catch (e) {
23+
await vscode.window.showErrorMessage((e as Error).message);
24+
}
25+
26+
if (!secrets || secrets.length === 0) {
27+
return [new EmptyNode("No organization secrets shared with this repository")];
28+
}
29+
30+
return secrets.map(s => new SecretNode(this.gitHubRepoContext, s, undefined, true));
31+
}
32+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as vscode from "vscode";
2+
import {GitHubRepoContext} from "../../git/repository";
3+
import {OrgVariable} from "../../model";
4+
import {EmptyNode} from "./emptyNode";
5+
import {VariableNode} from "./variableNode";
6+
7+
export class OrgVariablesNode extends vscode.TreeItem {
8+
constructor(public readonly gitHubRepoContext: GitHubRepoContext) {
9+
super("Organization Variables", vscode.TreeItemCollapsibleState.Collapsed);
10+
11+
this.contextValue = "org-variables";
12+
}
13+
14+
async getVariables(): Promise<vscode.TreeItem[]> {
15+
let variables: OrgVariable[] = [];
16+
try {
17+
variables = await this.gitHubRepoContext.client.paginate(
18+
"GET /repos/{owner}/{repo}/actions/organization-variables",
19+
{
20+
owner: this.gitHubRepoContext.owner,
21+
repo: this.gitHubRepoContext.name,
22+
per_page: 100
23+
}
24+
);
25+
} catch (e) {
26+
await vscode.window.showErrorMessage((e as Error).message);
27+
}
28+
29+
if (!variables || variables.length === 0) {
30+
return [new EmptyNode("No organization variables shared with this repository")];
31+
}
32+
33+
return variables.map(s => new VariableNode(this.gitHubRepoContext, s, undefined, true));
34+
}
35+
}
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import * as vscode from "vscode";
22
import {GitHubRepoContext} from "../../git/repository";
3-
import {Environment, EnvironmentSecret, RepoSecret} from "../../model";
3+
import {Environment, EnvironmentSecret, OrgSecret, RepoSecret} from "../../model";
44

55
export type SecretCommandArgs = Pick<SecretNode, "gitHubRepoContext" | "secret" | "environment">;
66

77
export class SecretNode extends vscode.TreeItem {
8+
constructor(gitHubRepoContext: GitHubRepoContext, secret: RepoSecret);
9+
constructor(gitHubRepoContext: GitHubRepoContext, secret: EnvironmentSecret, environment: Environment);
10+
constructor(githubRepoContext: GitHubRepoContext, secret: OrgSecret, environment: undefined, org: true);
811
constructor(
912
public readonly gitHubRepoContext: GitHubRepoContext,
10-
public readonly secret: RepoSecret | EnvironmentSecret,
11-
public readonly environment?: Environment
13+
public readonly secret: RepoSecret | EnvironmentSecret | OrgSecret,
14+
public readonly environment?: Environment,
15+
public readonly org?: boolean
1216
) {
1317
super(secret.name);
1418

15-
this.contextValue = environment ? "env-secret" : "repo-secret";
19+
this.contextValue = environment ? "env-secret" : org ? "org-secret" : "repo-secret";
1620
}
1721
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import * as vscode from "vscode";
22
import {GitHubRepoContext} from "../../git/repository";
3+
import {OrgSecretsNode} from "./orgSecretsNode";
4+
import {RepoSecretsNode} from "./repoSecretsNode";
5+
import {SettingsExplorerNode} from "./types";
36

47
export class SecretsNode extends vscode.TreeItem {
58
constructor(public readonly gitHubRepoContext: GitHubRepoContext) {
69
super("Secrets", vscode.TreeItemCollapsibleState.Collapsed);
710

811
this.iconPath = new vscode.ThemeIcon("lock");
912
}
13+
14+
get nodes(): SettingsExplorerNode[] {
15+
if (this.gitHubRepoContext.organizationOwned) {
16+
return [new RepoSecretsNode(this.gitHubRepoContext), new OrgSecretsNode(this.gitHubRepoContext)];
17+
}
18+
19+
return [new RepoSecretsNode(this.gitHubRepoContext)];
20+
}
1021
}

src/treeViews/settings/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import {SecretNode} from "./secretNode";
88
import {SecretsNode} from "./secretsNode";
99
import {SelfHostedRunnersNode} from "./selfHostedRunnersNode";
1010
import {VariablesNode} from "./variablesNode";
11+
import {RepoVariablesNode} from "./repoVariablesNode";
12+
import {OrgVariablesNode} from "./orgVariablesNode";
13+
import {OrgSecretsNode} from "./orgSecretsNode";
14+
import {RepoSecretsNode} from "./repoSecretsNode";
1115

1216
export type SettingsExplorerNode =
1317
| SelfHostedRunnersNode
@@ -16,7 +20,11 @@ export type SettingsExplorerNode =
1620
| EnvironmentsNode
1721
| EnvironmentNode
1822
| EnvironmentSecretsNode
23+
| EnvironmentVariablesNode
24+
| OrgSecretsNode
25+
| OrgVariablesNode
26+
| RepoSecretsNode
27+
| RepoVariablesNode
1928
| VariableNode
2029
| VariablesNode
21-
| EnvironmentVariablesNode
2230
| EmptyNode;
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import * as vscode from "vscode";
22
import {GitHubRepoContext} from "../../git/repository";
3-
import {Environment, EnvironmentVariable, RepoVariable} from "../../model";
3+
import {Environment, EnvironmentVariable, OrgVariable, RepoVariable} from "../../model";
44

55
export type VariableCommandArgs = Pick<VariableNode, "gitHubRepoContext" | "variable" | "environment">;
66

77
export class VariableNode extends vscode.TreeItem {
8+
constructor(gitHubRepoContext: GitHubRepoContext, variable: RepoVariable);
9+
constructor(gitHubRepoContext: GitHubRepoContext, variable: EnvironmentVariable, environment: Environment);
10+
constructor(githubRepoContext: GitHubRepoContext, variable: OrgVariable, environment: undefined, org: true);
811
constructor(
912
public readonly gitHubRepoContext: GitHubRepoContext,
10-
public readonly variable: EnvironmentVariable | RepoVariable,
11-
public readonly environment?: Environment
13+
public readonly variable: EnvironmentVariable | RepoVariable | OrgVariable,
14+
public readonly environment?: Environment,
15+
public readonly org?: boolean
1216
) {
1317
super(variable.name);
1418
this.description = variable.value;
1519

16-
this.contextValue = environment ? "env-variable" : "repo-variable";
20+
this.contextValue = environment ? "env-variable" : org ? "org-variable" : "repo-variable";
1721
}
1822
}

0 commit comments

Comments
 (0)