From 3105db4008596a3c8a9170a9cb447c89707dcef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Fonseca?= Date: Thu, 14 Jul 2022 15:31:06 +0200 Subject: [PATCH 1/6] chore(ci): automatically add area label based on title --- .github/scripts/label_pr_based_on_title.js | 45 +++++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/.github/scripts/label_pr_based_on_title.js b/.github/scripts/label_pr_based_on_title.js index dcbc562c596..4e836fa8dec 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -17,6 +17,24 @@ module.exports = async ({github, context, core}) => { "deprecated": DEPRECATED_REGEX, } + const areas = [ + "tracer", + "metric", + "utilities", + "logger", + "event_handlers", + "middleware_factory", + "idempotency", + "event_sources", + "feature_flags", + "parameters", + "batch", + "parser", + "validator", + "jmespath_util", + "lambda-layers", + ]; + // Maintenance: We should keep track of modified PRs in case their titles change let miss = 0; try { @@ -26,12 +44,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 @@ -42,4 +75,4 @@ module.exports = async ({github, context, core}) => { return core.notice(`PR ${PR_NUMBER} title '${PR_TITLE}' doesn't follow semantic titles; skipping...`) } } -} \ No newline at end of file +} From df889658016c1879325c331883a54ff32c72910b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Fonseca?= Date: Thu, 14 Jul 2022 15:35:28 +0200 Subject: [PATCH 2/6] fix(ci): bad indentation --- .github/scripts/label_pr_based_on_title.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/label_pr_based_on_title.js b/.github/scripts/label_pr_based_on_title.js index 4e836fa8dec..a752d6006cd 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -51,7 +51,7 @@ module.exports = async ({github, context, core}) => { labels: [label] }) - const area = matches[2]; // second capture group contains the area + 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({ From 7343c4d594ab375b075d97d1715a3d1ead9b3a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Fonseca?= Date: Thu, 14 Jul 2022 15:36:15 +0200 Subject: [PATCH 3/6] fix(ci): indentation --- .github/scripts/label_pr_based_on_title.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/label_pr_based_on_title.js b/.github/scripts/label_pr_based_on_title.js index a752d6006cd..30a7d14e93a 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -64,7 +64,7 @@ module.exports = async ({github, context, core}) => { core.debug(`'${PR_TITLE}' didn't match any known area.`); } - return; + return; } else { core.debug(`'${PR_TITLE}' didn't match '${label}' semantic.`) miss += 1 From 729ae82cfe746e77ced3529d9ea63f01ce5429c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Fonseca?= Date: Thu, 14 Jul 2022 15:37:51 +0200 Subject: [PATCH 4/6] fix(ci): indentation --- .github/scripts/label_pr_based_on_title.js | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/scripts/label_pr_based_on_title.js b/.github/scripts/label_pr_based_on_title.js index 30a7d14e93a..d60d38f1dba 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -17,23 +17,23 @@ module.exports = async ({github, context, core}) => { "deprecated": DEPRECATED_REGEX, } - const areas = [ - "tracer", - "metric", - "utilities", - "logger", - "event_handlers", - "middleware_factory", - "idempotency", - "event_sources", - "feature_flags", - "parameters", - "batch", - "parser", - "validator", - "jmespath_util", - "lambda-layers", - ]; + const areas = [ + "tracer", + "metric", + "utilities", + "logger", + "event_handlers", + "middleware_factory", + "idempotency", + "event_sources", + "feature_flags", + "parameters", + "batch", + "parser", + "validator", + "jmespath_util", + "lambda-layers", + ]; // Maintenance: We should keep track of modified PRs in case their titles change let miss = 0; From 4b094c4e87c68ed040bc61ba6cf065f197ef8241 Mon Sep 17 00:00:00 2001 From: Ruben Fonseca Date: Thu, 14 Jul 2022 15:44:46 +0200 Subject: [PATCH 5/6] fix(ci): typo Co-authored-by: Heitor Lessa --- .github/scripts/label_pr_based_on_title.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/label_pr_based_on_title.js b/.github/scripts/label_pr_based_on_title.js index d60d38f1dba..15980c19fd9 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -19,7 +19,7 @@ module.exports = async ({github, context, core}) => { const areas = [ "tracer", - "metric", + "metrics", "utilities", "logger", "event_handlers", From d5682bfb97f0e5ed974e92fee967aed26b8ed926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Fonseca?= Date: Fri, 15 Jul 2022 10:12:15 +0200 Subject: [PATCH 6/6] chore(ci): moved known areas to constants.js --- .github/scripts/constants.js | 19 +++++++++++++++++++ .github/scripts/label_pr_based_on_title.js | 22 ++-------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.github/scripts/constants.js b/.github/scripts/constants.js index 2eee0592c2d..2c1d6f9ab76 100644 --- a/.github/scripts/constants.js +++ b/.github/scripts/constants.js @@ -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", + ], }); diff --git a/.github/scripts/label_pr_based_on_title.js b/.github/scripts/label_pr_based_on_title.js index 15980c19fd9..463264155bf 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -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(\((.+)\))?(\:.+)/ @@ -17,24 +17,6 @@ module.exports = async ({github, context, core}) => { "deprecated": DEPRECATED_REGEX, } - const areas = [ - "tracer", - "metrics", - "utilities", - "logger", - "event_handlers", - "middleware_factory", - "idempotency", - "event_sources", - "feature_flags", - "parameters", - "batch", - "parser", - "validator", - "jmespath_util", - "lambda-layers", - ]; - // Maintenance: We should keep track of modified PRs in case their titles change let miss = 0; try { @@ -52,7 +34,7 @@ module.exports = async ({github, context, core}) => { }) const area = matches[2]; // second capture group contains the area - if (areas.indexOf(area) > -1) { + if (AREAS.indexOf(area) > -1) { core.info(`Auto-labeling PR ${PR_NUMBER} with area ${area}`); await github.rest.issues.addLabels({ issue_number: PR_NUMBER,