import type { AxiosInstance } from "axios"; import type { Issue, Comment, Label, Milestone } from "./types"; export class IssueAPI { constructor(private client: AxiosInstance) {} async listIssues( owner: string, repo: string, options?: { state?: "open" | "closed" | "all"; labels?: string; page?: number; limit?: number; }, ): Promise { const { data } = await this.client.get(`/repos/${owner}/${repo}/issues`, { params: options, }); return data; } async getIssue(owner: string, repo: string, index: number): Promise { const { data } = await this.client.get(`/repos/${owner}/${repo}/issues/${index}`); return data; } async createIssue( owner: string, repo: string, payload: { title: string; body?: string; assignees?: string[]; labels?: number[]; milestone?: number; }, ): Promise { const { data } = await this.client.post( `/repos/${owner}/${repo}/issues`, payload, ); return data; } async editIssue( owner: string, repo: string, index: number, payload: Partial<{ title: string; body: string; state: "open" | "closed"; assignees: string[]; labels: number[]; milestone: number; }>, ): Promise { const { data } = await this.client.patch( `/repos/${owner}/${repo}/issues/${index}`, payload, ); return data; } async listIssueComments(owner: string, repo: string, index: number): Promise { const { data } = await this.client.get( `/repos/${owner}/${repo}/issues/${index}/comments`, ); return data; } async addIssueComment( owner: string, repo: string, index: number, body: string, ): Promise { const { data } = await this.client.post( `/repos/${owner}/${repo}/issues/${index}/comments`, { body }, ); return data; } async listLabels(owner: string, repo: string): Promise { const { data } = await this.client.get(`/repos/${owner}/${repo}/labels`); return data; } async listMilestones( owner: string, repo: string, state?: "open" | "closed" | "all", ): Promise { const { data } = await this.client.get( `/repos/${owner}/${repo}/milestones`, { params: { state } }, ); return data; } }