File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ // yarn tsn -T examples/list_environments.ts
2
+
3
+ import Gitpod from '@gitpod/sdk' ;
4
+
5
+ const client = new Gitpod ( {
6
+ bearerToken : process . env [ 'GITPOD_API_KEY' ] ,
7
+ } ) ;
8
+
9
+ async function main ( ) {
10
+ console . log ( 'Listing environments...\n' ) ;
11
+
12
+ // Using for-await to automatically handle pagination
13
+ for await ( const environment of client . environments . list ( {
14
+ pageSize : 100 ,
15
+ token : '' ,
16
+ } ) ) {
17
+ // Print key information about each environment
18
+ console . log ( `Environment ID: ${ environment . id } ` ) ;
19
+ console . log ( `Status: ${ environment ?. status ?. phase } ` ) ;
20
+ console . log ( `Created: ${ environment ?. metadata ?. createdAt } ` ) ;
21
+
22
+ if ( environment ?. metadata ?. projectId ) {
23
+ console . log ( `Project ID: ${ environment ?. metadata ?. projectId } ` ) ;
24
+ }
25
+
26
+ // Print repository information if available
27
+ const contextUrl = environment ?. spec ?. content ?. initializer ?. specs ?. [ 0 ] ?. contextUrl ?. url ;
28
+ if ( contextUrl ) {
29
+ console . log ( `Repository: ${ contextUrl } ` ) ;
30
+ }
31
+
32
+ // Print machine class
33
+ if ( environment ?. spec ?. machine ?. class ) {
34
+ console . log ( `Machine Class: ${ environment ?. spec ?. machine ?. class } ` ) ;
35
+ }
36
+
37
+ console . log ( '---\n' ) ;
38
+ }
39
+ }
40
+
41
+ main ( ) . catch ( console . error ) ;
You can’t perform that action at this time.
0 commit comments