Skip to content

Commit b28c7a9

Browse files
chore(ci): automatically add area label based on title (#1300)
Co-authored-by: Heitor Lessa <[email protected]>
1 parent e677cab commit b28c7a9

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

Diff for: .github/scripts/constants.js

+19
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,23 @@ module.exports = Object.freeze({
3232

3333
/** @type {string[]} */
3434
"IGNORE_AUTHORS": ["dependabot[bot]", "markdownify[bot]"],
35+
36+
/** @type {string[]} */
37+
"AREAS": [
38+
"tracer",
39+
"metrics",
40+
"utilities",
41+
"logger",
42+
"event_handlers",
43+
"middleware_factory",
44+
"idempotency",
45+
"event_sources",
46+
"feature_flags",
47+
"parameters",
48+
"batch",
49+
"parser",
50+
"validator",
51+
"jmespath_util",
52+
"lambda-layers",
53+
],
3554
});

Diff for: .github/scripts/label_pr_based_on_title.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { PR_NUMBER, PR_TITLE } = require("./constants")
1+
const { PR_NUMBER, PR_TITLE, AREAS } = require("./constants")
22

33
module.exports = async ({github, context, core}) => {
44
const FEAT_REGEX = /feat(\((.+)\))?(\:.+)/
@@ -26,12 +26,27 @@ module.exports = async ({github, context, core}) => {
2626
if (isMatch != null) {
2727
core.info(`Auto-labeling PR ${PR_NUMBER} with ${label}`)
2828

29-
return await github.rest.issues.addLabels({
30-
issue_number: PR_NUMBER,
31-
owner: context.repo.owner,
32-
repo: context.repo.repo,
33-
labels: [label]
29+
await github.rest.issues.addLabels({
30+
issue_number: PR_NUMBER,
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
labels: [label]
3434
})
35+
36+
const area = matches[2]; // second capture group contains the area
37+
if (AREAS.indexOf(area) > -1) {
38+
core.info(`Auto-labeling PR ${PR_NUMBER} with area ${area}`);
39+
await github.rest.issues.addLabels({
40+
issue_number: PR_NUMBER,
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
labels: [`area/${area}`],
44+
});
45+
} else {
46+
core.debug(`'${PR_TITLE}' didn't match any known area.`);
47+
}
48+
49+
return;
3550
} else {
3651
core.debug(`'${PR_TITLE}' didn't match '${label}' semantic.`)
3752
miss += 1
@@ -42,4 +57,4 @@ module.exports = async ({github, context, core}) => {
4257
return core.notice(`PR ${PR_NUMBER} title '${PR_TITLE}' doesn't follow semantic titles; skipping...`)
4358
}
4459
}
45-
}
60+
}

0 commit comments

Comments
 (0)