forked from ubiquity/ubiquibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabel.ts
More file actions
38 lines (32 loc) · 1.05 KB
/
Copy pathlabel.ts
File metadata and controls
38 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Context } from "../types/context";
import { Label } from "../types/label";
import { GitHubPayload } from "../types/payload";
// cspell:disable
const COLORS = { default: "ededed", price: "1f883d" };
// cspell:enable
export async function listLabelsForRepo(context: Context): Promise<Label[]> {
const payload = context.event.payload as GitHubPayload;
const res = await context.event.octokit.rest.issues.listLabelsForRepo({
owner: payload.repository.owner.login,
repo: payload.repository.name,
per_page: 100,
page: 1,
});
if (res.status === 200) {
return res.data;
}
throw context.logger.fatal("Failed to fetch lists of labels", { status: res.status });
}
export async function createLabel(
context: Context,
name: string,
labelType = "default" as keyof typeof COLORS
): Promise<void> {
const payload = context.event.payload as GitHubPayload;
await context.event.octokit.rest.issues.createLabel({
owner: payload.repository.owner.login,
repo: payload.repository.name,
name,
color: COLORS[labelType],
});
}