From 8057cadd145c469ef21da488cf2a03bdfa95273b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Fonseca?= Date: Fri, 15 Jul 2022 11:32:28 +0200 Subject: [PATCH 1/5] fix(ci): typo on variable name --- .github/scripts/label_pr_based_on_title.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/label_pr_based_on_title.js b/.github/scripts/label_pr_based_on_title.js index 463264155bf..63292c884f3 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -22,8 +22,8 @@ module.exports = async ({github, context, core}) => { try { for (const label in labels) { const matcher = new RegExp(labels[label]) - const isMatch = matcher.exec(PR_TITLE) - if (isMatch != null) { + const matches = matcher.exec(PR_TITLE) + if (matches != null) { core.info(`Auto-labeling PR ${PR_NUMBER} with ${label}`) await github.rest.issues.addLabels({ From 58fdec46819dd02f9cd55bda3c19a42457c932db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Fonseca?= Date: Fri, 15 Jul 2022 13:43:27 +0200 Subject: [PATCH 2/5] chore(ci): remove unnecessary escape in regex --- .github/scripts/label_pr_based_on_title.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/scripts/label_pr_based_on_title.js b/.github/scripts/label_pr_based_on_title.js index 63292c884f3..f1089617294 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -1,12 +1,12 @@ const { PR_NUMBER, PR_TITLE, AREAS } = require("./constants") module.exports = async ({github, context, core}) => { - const FEAT_REGEX = /feat(\((.+)\))?(\:.+)/ - const BUG_REGEX = /(fix|bug)(\((.+)\))?(\:.+)/ - const DOCS_REGEX = /(docs|doc)(\((.+)\))?(\:.+)/ - const CHORE_REGEX = /(chore)(\((.+)\))?(\:.+)/ - const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(\:.+)/ - const REFACTOR_REGEX = /(refactor)(\((.+)\))?(\:.+)/ + const FEAT_REGEX = /feat(\((.+)\))?(:.+)/ + const BUG_REGEX = /(fix|bug)(\((.+)\))?(:.+)/ + const DOCS_REGEX = /(docs|doc)(\((.+)\))?(:.+)/ + const CHORE_REGEX = /(chore)(\((.+)\))?(:.+)/ + const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(:.+)/ + const REFACTOR_REGEX = /(refactor)(\((.+)\))?(:.+)/ const labels = { "feature": FEAT_REGEX, From f2e1ce239b3a1ae450f316bc437e9308382f8d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Fonseca?= Date: Fri, 15 Jul 2022 13:43:48 +0200 Subject: [PATCH 3/5] chore(ci): remove dangerous return inside finally block https://eslint.org/docs/latest/rules/no-unsafe-finally --- .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 f1089617294..4ae3c1ff321 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -54,7 +54,7 @@ module.exports = async ({github, context, core}) => { } } finally { if (miss == Object.keys(labels).length) { - return core.notice(`PR ${PR_NUMBER} title '${PR_TITLE}' doesn't follow semantic titles; skipping...`) + core.notice(`PR ${PR_NUMBER} title '${PR_TITLE}' doesn't follow semantic titles; skipping...`) } } } From aeac12a4397c3840d9cc0e3ffc66918b471f77d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Fonseca?= Date: Fri, 15 Jul 2022 13:44:16 +0200 Subject: [PATCH 4/5] chore(ci): prevent crash when labeling related issues The variable `issue` was not defined before. --- .github/scripts/label_related_issue.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/scripts/label_related_issue.js b/.github/scripts/label_related_issue.js index 93ac1583a1c..e01868d36dc 100644 --- a/.github/scripts/label_related_issue.js +++ b/.github/scripts/label_related_issue.js @@ -19,8 +19,9 @@ module.exports = async ({github, context, core}) => { const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?\d+)/; + const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY); + try { - const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY); if (!isMatch) { core.setFailed(`Unable to find related issue for PR number ${PR_NUMBER}.\n\n Body details: ${PR_BODY}`); return await github.rest.issues.createComment({ @@ -30,11 +31,16 @@ module.exports = async ({github, context, core}) => { issue_number: PR_NUMBER, }); } + } catch (error) { + core.setFailed(`Unable to create comment on PR number ${PR_NUMBER}.\n\n Error details: ${error}`); + throw new Error(error); + } - const { groups: {issue} } = isMatch + const { groups: {issue} } = isMatch + try { core.info(`Auto-labeling related issue ${issue} for release`) - return await github.rest.issues.addLabels({ + await github.rest.issues.addLabels({ issue_number: issue, owner: context.repo.owner, repo: context.repo.repo, From 65887ce560ca4c1c51d9a286ee87922a5e8f5a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Fonseca?= Date: Fri, 15 Jul 2022 13:44:49 +0200 Subject: [PATCH 5/5] chore(ci): remove unused variable --- .github/scripts/save_pr_details.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/save_pr_details.js b/.github/scripts/save_pr_details.js index bc3de6734c9..83bd3bf70d4 100644 --- a/.github/scripts/save_pr_details.js +++ b/.github/scripts/save_pr_details.js @@ -1,4 +1,4 @@ -module.exports = async ({github, context, core}) => { +module.exports = async ({context, core}) => { const fs = require('fs'); const filename = "pr.txt"; @@ -10,4 +10,4 @@ module.exports = async ({github, context, core}) => { core.setFailed("Failed to save PR details"); console.error(err); } -} \ No newline at end of file +}