-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetLabel.ts
More file actions
31 lines (26 loc) · 1.06 KB
/
getLabel.ts
File metadata and controls
31 lines (26 loc) · 1.06 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
import { GitHubScriptArguments } from "@urcomputeringpal/github-script-ts";
export async function getLabel(args: GitHubScriptArguments): Promise<String> {
const { github, context, core } = args;
if (github === undefined || context === undefined || core === undefined) {
throw new Error("Need github");
}
if (process.env.PR_NUMBER === undefined || process.env.PR_NUMBER === "") {
throw new Error("Need PR_NUMBER env variable");
}
console.log(`PR number: ${process.env.PR_NUMBER}`);
if (process.env.LABEL === undefined) {
throw new Error("Need LABEL env variable");
}
const response = await github.rest.issues.listLabelsOnIssue({
...context.repo,
issue_number: parseInt(process.env.PR_NUMBER),
});
const labels = response.data.filter(label => label.name.toLowerCase() == process.env.LABEL!.toLowerCase());
if (labels.length == 0) {
console.log(`No matching label`);
return "";
} else {
console.log(`Found matching label`);
return labels[0].name;
}
}