-
Notifications
You must be signed in to change notification settings - Fork 78
/
main.ts
44 lines (40 loc) 路 1.13 KB
/
main.ts
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
39
40
41
42
43
44
import * as core from "@actions/core";
import * as github from "@actions/github";
import { approve } from "./approve";
export async function run() {
try {
const token = core.getInput("github-token");
const reviewMessage = core.getInput("review-message");
await approve({
token,
context: github.context,
prNumber: prNumber(),
reviewMessage: reviewMessage || undefined,
});
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
} else {
core.setFailed("Unknown error");
}
}
}
function prNumber(): number {
if (core.getInput("pull-request-number") !== "") {
const prNumber = parseInt(core.getInput("pull-request-number"), 10);
if (Number.isNaN(prNumber)) {
throw new Error("Invalid `pull-request-number` value");
}
return prNumber;
}
if (!github.context.payload.pull_request) {
throw new Error(
"This action must be run using a `pull_request` event or " +
"have an explicit `pull-request-number` provided",
);
}
return github.context.payload.pull_request.number;
}
if (require.main === module) {
run();
}