Some checks failed
Build and Release / Test (push) Has been cancelled
Build and Release / Build Windows (push) Has been cancelled
Build and Release / Build Linux (push) Has been cancelled
Build and Release / Build macOS (push) Has been cancelled
Build and Release / Create Release (push) Has been cancelled
Build and Release / Development Build (push) Has been cancelled
103 lines
2.3 KiB
TypeScript
103 lines
2.3 KiB
TypeScript
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<Issue[]> {
|
|
const { data } = await this.client.get<Issue[]>(`/repos/${owner}/${repo}/issues`, {
|
|
params: options,
|
|
});
|
|
return data;
|
|
}
|
|
|
|
async getIssue(owner: string, repo: string, index: number): Promise<Issue> {
|
|
const { data } = await this.client.get<Issue>(`/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<Issue> {
|
|
const { data } = await this.client.post<Issue>(
|
|
`/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<Issue> {
|
|
const { data } = await this.client.patch<Issue>(
|
|
`/repos/${owner}/${repo}/issues/${index}`,
|
|
payload,
|
|
);
|
|
return data;
|
|
}
|
|
|
|
async listIssueComments(owner: string, repo: string, index: number): Promise<Comment[]> {
|
|
const { data } = await this.client.get<Comment[]>(
|
|
`/repos/${owner}/${repo}/issues/${index}/comments`,
|
|
);
|
|
return data;
|
|
}
|
|
|
|
async addIssueComment(
|
|
owner: string,
|
|
repo: string,
|
|
index: number,
|
|
body: string,
|
|
): Promise<Comment> {
|
|
const { data } = await this.client.post<Comment>(
|
|
`/repos/${owner}/${repo}/issues/${index}/comments`,
|
|
{ body },
|
|
);
|
|
return data;
|
|
}
|
|
|
|
async listLabels(owner: string, repo: string): Promise<Label[]> {
|
|
const { data } = await this.client.get<Label[]>(`/repos/${owner}/${repo}/labels`);
|
|
return data;
|
|
}
|
|
|
|
async listMilestones(
|
|
owner: string,
|
|
repo: string,
|
|
state?: "open" | "closed" | "all",
|
|
): Promise<Milestone[]> {
|
|
const { data } = await this.client.get<Milestone[]>(
|
|
`/repos/${owner}/${repo}/milestones`,
|
|
{ params: { state } },
|
|
);
|
|
return data;
|
|
}
|
|
}
|