Skip to content

Commit 5b220d9

Browse files
committed
fix(ci): adding missing scripts
1 parent fecba1c commit 5b220d9

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const {
2+
PR_NUMBER,
3+
PR_ACTION,
4+
PR_AUTHOR,
5+
IGNORE_AUTHORS,
6+
} = require("./constants")
7+
8+
9+
/**
10+
* Notify PR author to split XXL PR in smaller chunks
11+
*
12+
* @param {object} core - core functions instance from @actions/core
13+
* @param {object} gh_client - Pre-authenticated REST client (Octokit)
14+
* @param {string} owner - GitHub Organization
15+
* @param {string} repository - GitHub repository
16+
*/
17+
const notifyAuthor = async ({
18+
core,
19+
gh_client,
20+
owner,
21+
repository,
22+
}) => {
23+
core.info(`Commenting on PR ${PR_NUMBER}`)
24+
25+
let msg = `### ⚠️Large PR detected⚠️
26+
27+
Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.
28+
`;
29+
30+
try {
31+
await gh_client.rest.issues.createComment({
32+
owner: owner,
33+
repo: repository,
34+
body: msg,
35+
issue_number: PR_NUMBER,
36+
});
37+
} catch (error) {
38+
core.setFailed("Failed to notify PR author to split large PR");
39+
console.error(err);
40+
}
41+
}
42+
43+
module.exports = async ({github, context, core}) => {
44+
if (IGNORE_AUTHORS.includes(PR_AUTHOR)) {
45+
return core.notice("Author in IGNORE_AUTHORS list; skipping...")
46+
}
47+
48+
if (PR_ACTION != "labeled") {
49+
return core.notice("Only run on PRs labeling actions; skipping")
50+
}
51+
52+
53+
/** @type {string[]} */
54+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
issue_number: PR_NUMBER,
58+
})
59+
60+
// Schema: https://docs.github.com/en/rest/issues/labels#list-labels-for-an-issue
61+
for (const label of labels) {
62+
core.info(`Label: ${label}`)
63+
if (label.name == "size/XXL") {
64+
await notifyAuthor({
65+
core: core,
66+
gh_client: github,
67+
owner: context.repo.owner,
68+
repository: context.repo.repo,
69+
})
70+
break;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)