feat(orgs): add organization and organization-repository APIs: getOrg, getOrgRepos, createOrg, createOrgRepo
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiclient.xyz/gitea',
|
||||
version: '1.0.3',
|
||||
version: '1.1.0',
|
||||
description: 'A TypeScript client for the Gitea API, providing easy access to repositories, organizations, secrets, and action runs.'
|
||||
}
|
||||
|
||||
@@ -149,6 +149,56 @@ export class GiteaClient {
|
||||
return this.request<IGiteaOrganization[]>('GET', `/api/v1/orgs?page=${page}&limit=${limit}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single organization by name
|
||||
*/
|
||||
public async getOrg(orgName: string): Promise<IGiteaOrganization> {
|
||||
return this.request<IGiteaOrganization>('GET', `/api/v1/orgs/${encodeURIComponent(orgName)}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* List repositories within an organization
|
||||
*/
|
||||
public async getOrgRepos(orgName: string, opts?: IListOptions): Promise<IGiteaRepository[]> {
|
||||
const page = opts?.page || 1;
|
||||
const limit = opts?.perPage || 50;
|
||||
let url = `/api/v1/orgs/${encodeURIComponent(orgName)}/repos?page=${page}&limit=${limit}&sort=updated`;
|
||||
if (opts?.search) {
|
||||
url += `&q=${encodeURIComponent(opts.search)}`;
|
||||
}
|
||||
return this.request<IGiteaRepository[]>('GET', url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new organization
|
||||
*/
|
||||
public async createOrg(name: string, opts?: {
|
||||
fullName?: string;
|
||||
description?: string;
|
||||
visibility?: string;
|
||||
}): Promise<IGiteaOrganization> {
|
||||
return this.request<IGiteaOrganization>('POST', '/api/v1/orgs', {
|
||||
username: name,
|
||||
full_name: opts?.fullName || name,
|
||||
description: opts?.description || '',
|
||||
visibility: opts?.visibility || 'public',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a repository within an organization
|
||||
*/
|
||||
public async createOrgRepo(orgName: string, name: string, opts?: {
|
||||
description?: string;
|
||||
private?: boolean;
|
||||
}): Promise<IGiteaRepository> {
|
||||
return this.request<IGiteaRepository>('POST', `/api/v1/orgs/${encodeURIComponent(orgName)}/repos`, {
|
||||
name,
|
||||
description: opts?.description || '',
|
||||
private: opts?.private ?? true,
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Repository Secrets
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user