Skip to content

TypeScript Gitpod SDK Example #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions examples/list_environments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// yarn tsn -T examples/list_environments.ts

import Gitpod from '@gitpod/sdk';

const client = new Gitpod({
bearerToken: process.env['GITPOD_API_KEY'],
});

async function main() {
console.log('Listing environments...\n');

// Using for-await to automatically handle pagination
for await (const environment of client.environments.list({
pageSize: 100,
token: '',
})) {
// Print key information about each environment
console.log(`Environment ID: ${environment.id}`);
console.log(`Status: ${environment?.status?.phase}`);
console.log(`Created: ${environment?.metadata?.createdAt}`);

if (environment?.metadata?.projectId) {
console.log(`Project ID: ${environment?.metadata?.projectId}`);
}

// Print repository information if available
const contextUrl = environment?.spec?.content?.initializer?.specs?.[0]?.contextUrl?.url;
if (contextUrl) {
console.log(`Repository: ${contextUrl}`);
}

// Print machine class
if (environment?.spec?.machine?.class) {
console.log(`Machine Class: ${environment?.spec?.machine?.class}`);
}

console.log('---\n');
}
}

main().catch(console.error);