diff --git a/src/api.ts b/src/api.ts index 5b01ca3..a3bfd70 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { Config, Issue, Comment, RepoItem } from './types.js'; +import { Config, Issue, Comment, RepoItem, Label } from './types.js'; /** * Normalizes the Gitea/Forgejo URL by stripping trailing slashes @@ -598,3 +598,105 @@ export async function setIssueAssignees( throw new Error(`Network Error: ${error.message}`); } } + +/** + * Fetches all labels for a specific repository. + */ +export async function fetchLabels(config: Config): Promise { + const client = createAxiosInstance(config); + try { + const response = await client.get(`/repos/${config.owner}/${config.repo}/labels`); + return response.data.map((item: any) => ({ + id: item.id, + name: item.name, + color: item.color, + description: item.description, + exclusive: item.exclusive, + })); + } catch (error: any) { + if (error.response) { + throw new Error(`Failed to fetch labels: ${error.response.data?.message || error.message}`); + } + throw new Error(`Network Error: ${error.message}`); + } +} + +/** + * Creates a new label in the specified repository. + */ +export async function createLabel(config: Config, label: Partial