-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (55 loc) · 1.73 KB
/
index.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// @ts-check
import core from "@actions/core";
import github from "@actions/github";
async function addMergeBlockedLabelsToAllTargetPrs() {
try {
const develop = core.getInput("release-source-branch");
const label = core.getInput("label");
const actionType = core.getInput("type");
const octokit = github.getOctokit(process.env.GITHUB_TOKEN ?? "").rest;
try {
const { data: prs } = await octokit.pulls.list({
...github.context.repo,
base: develop,
state: "open",
});
for (const pr of prs) {
if (actionType === "add") {
await octokit.issues.addLabels({
...github.context.repo,
issue_number: pr.number,
labels: [label],
});
} else {
try {
await octokit.issues.removeLabel({
...github.context.repo,
issue_number: pr.number,
name: label,
});
} catch (e) {
core.info(`No "${label}" label for PR #${pr.number}`);
}
}
core.info(`${actionType} "${label}" label to PR #${pr.number}`);
}
} catch (error) {
core.error("Error adding label to PRs:", error);
core.setFailed(error.message);
}
core.info(
`Added "${label}" label to all other PRs targeting the ${develop} branch.`
);
} catch (error) {
core.error("Error fetching PRs:", error);
core.setFailed(error.message);
}
}
await addMergeBlockedLabelsToAllTargetPrs();
// await octokit.repos.createCommitStatus({
// ...github.context.repo,
// sha: pr.head.sha,
// state: "error",
// context: `Block Merge to ${develop} before the Release`,
// description: `This PR is blocked and cannot be merged.`,
// });