Skip to content

Commit 06a44e7

Browse files
feat(examples): add list environments example script
1 parent f9e2a50 commit 06a44e7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

examples/list_environments.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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);

0 commit comments

Comments
 (0)