-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathenvironmentVariablesNode.ts
More file actions
41 lines (34 loc) · 1.45 KB
/
environmentVariablesNode.ts
File metadata and controls
41 lines (34 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as vscode from "vscode";
import {GitHubRepoContext} from "../../git/repository";
import {Environment} from "../../model";
import {EmptyNode} from "./emptyNode";
import {VariableNode} from "./variableNode";
export type EnvironmentVariablesCommandArgs = Pick<EnvironmentVariablesNode, "gitHubRepoContext" | "environment">;
export class EnvironmentVariablesNode extends vscode.TreeItem {
constructor(public readonly gitHubRepoContext: GitHubRepoContext, public readonly environment: Environment) {
super("Variables", vscode.TreeItemCollapsibleState.Collapsed);
this.iconPath = new vscode.ThemeIcon("symbol-text");
this.contextValue = "environment-variables";
}
async getVariables(): Promise<(VariableNode | EmptyNode)[]> {
let variables: VariableNode[] = [];
try {
variables = await this.gitHubRepoContext.client.paginate(
this.gitHubRepoContext.client.actions.listEnvironmentVariables,
{
owner: this.gitHubRepoContext.owner,
repo: this.gitHubRepoContext.name,
environment_name: this.environment.name,
per_page: 100
},
response => response.data.map(v => new VariableNode(this.gitHubRepoContext, v, this.environment))
);
} catch (e) {
await vscode.window.showErrorMessage((e as Error).message);
}
if (!variables || variables.length === 0) {
return [new EmptyNode("No environment variables defined")];
}
return variables;
}
}