11import * as vscode from "vscode" ;
2-
3- import { GitHubContext , getGitHubContext } from "../git/repository" ;
4- import { OrgSecret , RepoSecret , SelfHostedRunner } from "../model" ;
5-
2+ import { getGitHubContext , GitHubContext } from "../git/repository" ;
3+ import {
4+ Environment ,
5+ EnvironmentSecret ,
6+ OrgSecret ,
7+ RepoSecret ,
8+ SelfHostedRunner ,
9+ } from "../model" ;
610import { getAbsoluteIconPath } from "./icons" ;
711
812class OrgFeaturesNode extends vscode . TreeItem {
@@ -90,16 +94,58 @@ class OrgSecretNode extends vscode.TreeItem {
9094 }
9195}
9296
97+ class EnvironmentsNode extends vscode . TreeItem {
98+ constructor ( public readonly gitHubContext : GitHubContext ) {
99+ super ( "Environments" , vscode . TreeItemCollapsibleState . Collapsed ) ;
100+
101+ this . iconPath = new vscode . ThemeIcon ( "server-environment" ) ;
102+ }
103+ }
104+
105+ class EnvironmentNode extends vscode . TreeItem {
106+ constructor (
107+ public readonly gitHubContext : GitHubContext ,
108+ public readonly environment : Environment
109+ ) {
110+ super ( environment . name , vscode . TreeItemCollapsibleState . Collapsed ) ;
111+
112+ this . contextValue = "environment" ;
113+ }
114+ }
115+
116+ class EnvironmentSecretNode extends vscode . TreeItem {
117+ constructor (
118+ public readonly gitHubContext : GitHubContext ,
119+ public readonly secret : EnvironmentSecret
120+ ) {
121+ super ( secret . name ) ;
122+
123+ this . contextValue = "env-secret" ;
124+ }
125+ }
126+
127+ class EmptyEnvironmentSecretsNode extends vscode . TreeItem {
128+ constructor ( ) {
129+ super ( "No environment secrets defined" ) ;
130+ }
131+ }
132+
93133type SettingsExplorerNode =
94134 | OrgFeaturesNode
95135 | SelfHostedRunnersNode
96136 | SecretsNode
97137 | RepoSecretNode
98- | OrgSecretNode ;
138+ | OrgSecretNode
139+ | EnvironmentsNode
140+ | EnvironmentNode
141+ | EnvironmentSecretNode
142+ | EmptyEnvironmentSecretsNode ;
99143
100144export class SettingsTreeProvider
101- implements vscode . TreeDataProvider < SettingsExplorerNode > {
102- private _onDidChangeTreeData = new vscode . EventEmitter < SettingsExplorerNode | null > ( ) ;
145+ implements vscode . TreeDataProvider < SettingsExplorerNode >
146+ {
147+ private _onDidChangeTreeData =
148+ new vscode . EventEmitter < SettingsExplorerNode | null > ( ) ;
103149 readonly onDidChangeTreeData = this . _onDidChangeTreeData . event ;
104150
105151 refresh ( ) : void {
@@ -125,9 +171,14 @@ export class SettingsTreeProvider
125171 return [
126172 new SelfHostedRunnersNode ( gitHubContext ) ,
127173 new SecretsNode ( gitHubContext ) ,
174+ new EnvironmentsNode ( gitHubContext ) ,
128175 ] ;
129176 }
130177
178+ //
179+ // Secrets
180+ //
181+
131182 if ( element instanceof SecretsNode ) {
132183 const nodes = [ new RepoSecretsNode ( gitHubContext ) ] ;
133184
@@ -164,17 +215,44 @@ export class SettingsTreeProvider
164215 }
165216
166217 if ( element instanceof SelfHostedRunnersNode ) {
167- const result = await gitHubContext . client . actions . listSelfHostedRunnersForRepo (
168- {
218+ const result =
219+ await gitHubContext . client . actions . listSelfHostedRunnersForRepo ( {
169220 owner : gitHubContext . owner ,
170221 repo : gitHubContext . name ,
171- }
172- ) ;
222+ } ) ;
173223
174224 const data = result . data . runners || [ ] ;
175225 return data . map ( ( r ) => new SelfHostedRunnerNode ( gitHubContext , r ) ) ;
176226 }
177227
228+ //
229+ // Environments
230+ //
231+
232+ if ( element instanceof EnvironmentsNode ) {
233+ const result = await gitHubContext . client . repos . getAllEnvironments ( {
234+ owner : gitHubContext . owner ,
235+ repo : gitHubContext . name ,
236+ } ) ;
237+
238+ const data = result . data . environments || [ ] ;
239+ return data . map ( ( e ) => new EnvironmentNode ( gitHubContext , e ) ) ;
240+ }
241+
242+ if ( element instanceof EnvironmentNode ) {
243+ const result = await gitHubContext . client . actions . listEnvironmentSecrets ( {
244+ repository_id : gitHubContext . id ,
245+ environment_name : element . environment . name ,
246+ } ) ;
247+
248+ const data = result . data . secrets ;
249+ if ( ! data ) {
250+ return [ new EmptyEnvironmentSecretsNode ( ) ] ;
251+ }
252+
253+ return data . map ( ( s ) => new EnvironmentSecretNode ( gitHubContext , s ) ) ;
254+ }
255+
178256 return [ ] ;
179257 }
180258}
0 commit comments