Skip to content

Commit

Permalink
chore(ci): automatically add area label based on title (#1300)
Browse files Browse the repository at this point in the history
Co-authored-by: Heitor Lessa <lessa@amazon.com>
  • Loading branch information
rubenfonseca and heitorlessa authored Jul 15, 2022
1 parent e677cab commit b28c7a9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
19 changes: 19 additions & 0 deletions .github/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@ module.exports = Object.freeze({

/** @type {string[]} */
"IGNORE_AUTHORS": ["dependabot[bot]", "markdownify[bot]"],

/** @type {string[]} */
"AREAS": [
"tracer",
"metrics",
"utilities",
"logger",
"event_handlers",
"middleware_factory",
"idempotency",
"event_sources",
"feature_flags",
"parameters",
"batch",
"parser",
"validator",
"jmespath_util",
"lambda-layers",
],
});
29 changes: 22 additions & 7 deletions .github/scripts/label_pr_based_on_title.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { PR_NUMBER, PR_TITLE } = require("./constants")
const { PR_NUMBER, PR_TITLE, AREAS } = require("./constants")

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

return await github.rest.issues.addLabels({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [label]
await github.rest.issues.addLabels({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [label]
})

const area = matches[2]; // second capture group contains the area
if (AREAS.indexOf(area) > -1) {
core.info(`Auto-labeling PR ${PR_NUMBER} with area ${area}`);
await github.rest.issues.addLabels({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [`area/${area}`],
});
} else {
core.debug(`'${PR_TITLE}' didn't match any known area.`);
}

return;
} else {
core.debug(`'${PR_TITLE}' didn't match '${label}' semantic.`)
miss += 1
Expand All @@ -42,4 +57,4 @@ module.exports = async ({github, context, core}) => {
return core.notice(`PR ${PR_NUMBER} title '${PR_TITLE}' doesn't follow semantic titles; skipping...`)
}
}
}
}

0 comments on commit b28c7a9

Please sign in to comment.