74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { BaseClient, ClientOptions } from './base-client.js';
|
|
|
|
export class RepositoryClient extends BaseClient {
|
|
constructor(options: ClientOptions = {}) {
|
|
super(options);
|
|
}
|
|
|
|
async listWorkspaces(options?: { page?: number; pagelen?: number }): Promise<any> {
|
|
await this.ensureInitialized();
|
|
try {
|
|
const params: Record<string, any> = {};
|
|
if (options?.page) params.page = options.page;
|
|
if (options?.pagelen) params.pagelen = options.pagelen;
|
|
const response = await this.axiosInstance.get('/workspaces', { params });
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error(`Failed to list workspaces: ${this.formatError(error)}`);
|
|
}
|
|
}
|
|
|
|
async listRepositories(
|
|
workspace: string,
|
|
options?: { role?: 'member' | 'contributor' | 'owner'; page?: number; pagelen?: number },
|
|
): Promise<any> {
|
|
await this.ensureInitialized();
|
|
try {
|
|
const params: Record<string, any> = {};
|
|
if (options?.role) params.role = options.role;
|
|
if (options?.page) params.page = options.page;
|
|
if (options?.pagelen) params.pagelen = options.pagelen;
|
|
const response = await this.axiosInstance.get(
|
|
`/repositories/${workspace}`,
|
|
{ params },
|
|
);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error(`Failed to list repositories: ${this.formatError(error)}`);
|
|
}
|
|
}
|
|
|
|
async getRepository(workspace: string, repoSlug: string): Promise<any> {
|
|
await this.ensureInitialized();
|
|
try {
|
|
const response = await this.axiosInstance.get(
|
|
`/repositories/${workspace}/${repoSlug}`,
|
|
);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error(`Failed to get repository: ${this.formatError(error)}`);
|
|
}
|
|
}
|
|
|
|
async listBranches(
|
|
workspace: string,
|
|
repoSlug: string,
|
|
options?: { filter_by_name?: string; page?: number; pagelen?: number },
|
|
): Promise<any> {
|
|
await this.ensureInitialized();
|
|
try {
|
|
const params: Record<string, any> = {};
|
|
if (options?.filter_by_name) params.q = `name~"${options.filter_by_name}"`;
|
|
if (options?.page) params.page = options.page;
|
|
if (options?.pagelen) params.pagelen = options.pagelen;
|
|
const response = await this.axiosInstance.get(
|
|
`/repositories/${workspace}/${repoSlug}/refs/branches`,
|
|
{ params },
|
|
);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error(`Failed to list branches: ${this.formatError(error)}`);
|
|
}
|
|
}
|
|
}
|