From c9d605a4a0bf2db79709b83c6a558aa0231e1c95 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Wed, 3 May 2023 16:08:52 +0200 Subject: [PATCH 1/9] chore: update PR template --- .github/PULL_REQUEST_TEMPLATE.md | 39 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index a199f2ea66..154b532a46 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,29 +1,32 @@ - - + ## Description of your changes - + +Please include also relevant motivation and context. - +Add any applicable code snippets, links, screenshots, or other resources +that can help us verify your changes. +--> - - -### How to verify this change - - - +### Related issues, RFCs - - + - +Example: +**Issue number:** #42 +--> **Issue number:** + ## Checklist @@ -31,12 +34,8 @@ - [ ] I have performed a *self-review* of my own code - [ ] I have *commented* my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas - [ ] I have made corresponding changes to the *documentation* -- [ ] I have made corresponding changes to the *examples* - [ ] My changes generate *no new warnings* -- [ ] The *code coverage* hasn't decreased - [ ] I have *added tests* that prove my change is effective and works -- [ ] New and existing *unit tests pass* locally and in Github Actions -- [ ] Any *dependent changes have been merged and published* - [ ] The PR title follows the [conventional commit semantics](https://github.com/awslabs/aws-lambda-powertools-typescript/blob/main/.github/semantic.yml#L2) ### Breaking change checklist From 0c38079f168927d787965658ab46399d8d8eb4bf Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Wed, 3 May 2023 16:50:44 +0200 Subject: [PATCH 2/9] chore: updated semantic config to include scopes --- .github/semantic.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/semantic.yml b/.github/semantic.yml index 39119da8d0..e07898ce24 100644 --- a/.github/semantic.yml +++ b/.github/semantic.yml @@ -13,6 +13,23 @@ types: - revert - improv +scopes: + - tracer + - logger + - metrics + - parameters + - idempotency + - commons + - parser + - validator + - batch + - layers + - ci + - docs + - tests + - internal + - maintenance + # Always validate the PR title # and ignore the commits to lower the entry bar for contribution # while titles make up the Release notes to ease maintenance overhead From 30121ca15b406ca4fba415dd69689f599de2af97 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Wed, 3 May 2023 19:31:12 +0200 Subject: [PATCH 3/9] chore: update pr, issue, and release automation --- .github/boring-cyborg.yml | 170 ++++++++++++++++++ .github/scripts/constants.js | 8 +- .../scripts/label_missing_related_issue.js | 80 ++++++--- .github/scripts/label_pr_based_on_title.js | 2 - .github/scripts/label_related_issue.js | 110 ++++++++---- .github/scripts/post_release.js | 16 +- .github/workflows/post-release.yml | 33 ++++ MAINTAINERS.md | 1 + 8 files changed, 341 insertions(+), 79 deletions(-) create mode 100644 .github/boring-cyborg.yml create mode 100644 .github/workflows/post-release.yml diff --git a/.github/boring-cyborg.yml b/.github/boring-cyborg.yml new file mode 100644 index 0000000000..0b983e11dd --- /dev/null +++ b/.github/boring-cyborg.yml @@ -0,0 +1,170 @@ +##### Labeler ########################################################################################################## +labelPRBasedOnFilePath: + area/logger: + - packages/logger/src/* + - packages/logger/src/**/* + area/tracer: + - packages/tracer/src/* + - packages/tracer/src/**/* + area/metrics: + - packages/metrics/src/* + - packages/metrics/src/**/* + area/idempotency: + - packages/idempotency/src/* + - packages/idempotency/src/**/* + area/parameters: + - packages/parameters/src/* + - packages/parameters/src/**/* + area/parser: + - packages/parser/src/* + - packages/parser/src/**/* + area/validator: + - packages/validator/src/* + - packages/validator/src/**/* + area/batch: + - packages/batch/src/* + - packages/batch/src/**/* + area/commons: + - packages/commons/src/* + - packages/commons/src/**/* + area/layers: + - layers/src/* + - layers/src/**/* + - layers/bin/* + - layers/cdk.json + + type/tests: + - packages/logger/tests/* + - packages/logger/tests/**/* + - packages/logger/jest.config.js + - packages/tracer/tests/* + - packages/tracer/tests/**/* + - packages/tracer/jest.config.js + - packages/metrics/tests/* + - packages/metrics/tests/**/* + - packages/metrics/jest.config.js + - packages/idempotency/tests/* + - packages/idempotency/tests/**/* + - packages/idempotency/jest.config.js + - packages/parameters/tests/* + - packages/parameters/tests/**/* + - packages/parameters/jest.config.js + - packages/parser/tests/* + - packages/parser/tests/**/* + - packages/parser/jest.config.js + - packages/validator/tests/* + - packages/validator/tests/**/* + - packages/validator/jest.config.js + - packages/batch/tests/* + - packages/batch/tests/**/* + - packages/batch/jest.config.js + - packages/commons/tests/* + - packages/commons/tests/**/* + - packages/commons/jest.config.js + - layers/jest.config.js + - layers/tests/* + - layers/tests/**/* + + area/documentation: + - docs/* + - docs/**/* + - mkdocs.yml + - typedoc.js + - examples/cdk/bin/* + - examples/cdk/functions/* + - examples/cdk/functions/**/* + - examples/cdk/src/* + - examples/cdk/src/**/* + - examples/cdk/tests/* + - examples/cdk/tests/**/* + - examples/cdk/README.md + - examples/cdk/cdk.json + - examples/sam/events/* + - examples/sam/src/* + - examples/sam/src/**/* + - examples/sam/tests/* + - examples/sam/tests/**/* + - examples/sam/README.md + - examples/sam/template.yaml + + area/automation: + - .github/scripts/* + - .github/scripts/**/* + - .github/workflows/* + - .github/workflows/**/* + - .github/release-drafter.yml + - .github/boring-cyborg.yml + - .github/semantic.yml + + type/internal: + - .github/CODEOWNERS + - .github/PULL_REQUEST_TEMPLATE.md + - .github/ISSUE_TEMPLATE/* + - CONTRIBUTING.md + - MAINTAINERS.md + - CODE_OF_CONDUCT.md + - SECURITY.md + - LICENSE + - LICENSE-THIRD-PARTY + - lerna.json + - .nvmrc + - .eslintrc.js + - .eslintignore + - .npmignore + - .gitpod.yml + - .husky/* + - .devcontainer/* + - packages/logger/tsconfig*.json + - packages/logger/README.md + - packages/metrics/tsconfig*.json + - packages/metrics/README.md + - packages/tracer/tsconfig*.json + - packages/tracer/README.md + - packages/parser/tsconfig*.json + - packages/parser/README.md + - packages/idempotency/tsconfig*.json + - packages/idempotency/README.md + - packages/batch/tsconfig*.json + - packages/batch/README.md + - packages/commons/tsconfig*.json + - packages/commons/README.md + - packages/validator/tsconfig*.json + - packages/validator/README.md + - packages/parser/tsconfig*.json + - packages/parser/README.md + - layers/tsconfig*.json + - layers/README.md + - examples/sam/tsconfig*.json + - examples/cdk/tsconfig*.json + + type/dependencies: + - package.json + - package-lock.json + - packages/tracer/package.json + - packages/metrics/package.json + - packages/logger/package.json + - packages/commons/package.json + - packages/parameters/package.json + - packages/idempotency/package.json + - packages/parser/package.json + - packages/validator/package.json + - packages/batch/package.json + - layers/package.json + - examples/cdk/package.json + - examples/sam/package.json + +##### Greetings ######################################################################################################## +firstPRWelcomeComment: > + Thanks a lot for your first contribution! Please check out our [contributing guidelines](https://github.com/awslabs/aws-lambda-powertools-typescript/blob/chore/pr_automation/CONTRIBUTING.md) and don't hesitate to ask whatever you need. + + In the meantime, check out the #typescript channel on our AWS Lambda Powertools Discord: [Invite link](https://discord.gg/B8zZKbbyET) + +# Comment to be posted to congratulate user on their first merged PR +firstPRMergeComment: > + Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! + +# Comment to be posted to on first time issues +firstIssueWelcomeComment: > + Thanks for opening your first issue here! We'll come back to you as soon as we can. + + In the meantime, check out the #typescript channel on our AWS Lambda Powertools Discord: [Invite link](https://discord.gg/B8zZKbbyET) \ No newline at end of file diff --git a/.github/scripts/constants.js b/.github/scripts/constants.js index 2e3cb78f91..e74a17928d 100644 --- a/.github/scripts/constants.js +++ b/.github/scripts/constants.js @@ -36,10 +36,6 @@ module.exports = Object.freeze({ /** @type {string[]} */ "IGNORE_AUTHORS": ["dependabot[bot]"], - /** @type {string[]} */ - "AREAS": [ - "tracer", - "metrics", - "logger", - ], + /** @type {RegExp} */ + "RELATED_ISSUE_REGEX": /\bIssue number:(?:closes?|close|fix|fixes?|fixed|resolves?|resolved)?\s*#(?\d+)\b/ }); \ No newline at end of file diff --git a/.github/scripts/label_missing_related_issue.js b/.github/scripts/label_missing_related_issue.js index 53400935f2..b265f97f65 100644 --- a/.github/scripts/label_missing_related_issue.js +++ b/.github/scripts/label_missing_related_issue.js @@ -5,36 +5,64 @@ const { PR_NUMBER, IGNORE_AUTHORS, LABEL_BLOCK, - LABEL_BLOCK_REASON + LABEL_BLOCK_REASON, + RELATED_ISSUE_REGEX, } = require("./constants"); -module.exports = async ({github, context, core}) => { - if (IGNORE_AUTHORS.includes(PR_AUTHOR)) { - return core.notice("Author in IGNORE_AUTHORS list; skipping..."); - } +module.exports = async ({ github, context, core }) => { + if (IGNORE_AUTHORS.includes(PR_AUTHOR)) { + return core.notice("Author in IGNORE_AUTHORS list; skipping..."); + } - if (PR_ACTION != "opened") { - return core.notice("Only newly open PRs are labelled to avoid spam; skipping"); - } + if ( + ["opened", "edited", "ready_for_review", "reopened"].includes(PR_ACTION) + ) { + return core.notice( + "Only newly opened or updated PRs are labelled to avoid spam; skipping" + ); + } + + const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY); + if (isMatch == null) { + core.info( + `No related issue found, maybe the author didn't use the template but there is one.` + ); - const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?\d+)/; - const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY); - if (isMatch == null) { - core.info(`No related issue found, maybe the author didn't use the template but there is one.`); + let msg = + "No related issues found. Please ensure there is an open issue related to this change to avoid significant delays or closure."; + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + body: msg, + issue_number: PR_NUMBER, + }); - let msg = "No related issues found. Please ensure there is an open issue related to this change to avoid significant delays or closure."; - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - body: msg, - issue_number: PR_NUMBER, - }); + return await github.rest.issues.addLabels({ + issue_number: PR_NUMBER, + owner: context.repo.owner, + repo: context.repo.repo, + labels: [LABEL_BLOCK, LABEL_BLOCK_REASON], + }); + } else { + const { closingWord, issue } = isMatch.groups; + if (closingWord == null) { + core.info( + `Found related issue #${issue} without closing word, adding one...` + ); + // Add closing word to the PR body + const msg = `Issue number: closes ${issue}`; + const updatedPRBody = PR_BODY.replace(RELATED_ISSUE_REGEX, msg); - return await github.rest.issues.addLabels({ - issue_number: PR_NUMBER, - owner: context.repo.owner, - repo: context.repo.repo, - labels: [LABEL_BLOCK, LABEL_BLOCK_REASON] - }); + await github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + body: updatedPRBody, + issue_number: PR_NUMBER, + }); + } else { + core.info( + `Found related issue #${issue} with closing word '${closingWord}'` + ); } -} \ No newline at end of file + } +}; diff --git a/.github/scripts/label_pr_based_on_title.js b/.github/scripts/label_pr_based_on_title.js index 12465eab1a..0ba337233f 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -3,14 +3,12 @@ const { PR_NUMBER, PR_TITLE } = require("./constants"); module.exports = async ({github, context, core}) => { const BUG_REGEX = /(fix|bug)(\((.+)\))?(:.+)/ const FEAT_REFACTOR_REGEX = /(feat|refactor)(\((.+)\))?(:.+)/ - const DOCS_REGEX = /(docs|doc)(\((.+)\))?(:.+)/ const CHORE_REGEX = /(chore)(\((.+)\))?(:.+)/ const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(:.+)/ const labels = { "type/feature": FEAT_REFACTOR_REGEX, "type/bug": BUG_REGEX, - "area/documentation": DOCS_REGEX, "type/internal": CHORE_REGEX, "type/deprecation": DEPRECATED_REGEX, } diff --git a/.github/scripts/label_related_issue.js b/.github/scripts/label_related_issue.js index 6cfebbdf9b..e3d26e1c2b 100644 --- a/.github/scripts/label_related_issue.js +++ b/.github/scripts/label_related_issue.js @@ -8,46 +8,84 @@ const { PR_IS_MERGED, } = require("./constants"); -module.exports = async ({github, context, core}) => { - if (IGNORE_AUTHORS.includes(PR_AUTHOR)) { - return core.notice("Author in IGNORE_AUTHORS list; skipping..."); - } - - if (PR_IS_MERGED == "false") { - return core.notice("Only merged PRs to avoid spam; skipping"); - } +module.exports = async ({ github, context, core }) => { + if (IGNORE_AUTHORS.includes(PR_AUTHOR)) { + return core.notice("Author in IGNORE_AUTHORS list; skipping..."); + } - const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?\d+)/; - - const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY); - - try { - 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({ - owner: context.repo.owner, - repo: context.repo.repo, - body: `${HANDLE_MAINTAINERS_TEAM} No related issues found. Please ensure '${LABEL_PENDING_RELEASE}' label is applied before releasing.`, - 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); - } + if (PR_IS_MERGED == "false") { + return core.notice("Only merged PRs to avoid spam; skipping"); + } - const { groups: {issue} } = isMatch; + const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY); - try { - core.info(`Auto-labeling related issue ${issue} for release`); - return await github.rest.issues.addLabels({ - issue_number: issue, + try { + 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({ owner: context.repo.owner, repo: context.repo.repo, - labels: [LABEL_PENDING_RELEASE], + body: `${HANDLE_MAINTAINERS_TEAM} No related issues found. Please ensure '${LABEL_PENDING_RELEASE}' label is applied before releasing.`, + issue_number: PR_NUMBER, }); - } catch (error) { - core.setFailed(`Is this issue number (${issue}) valid? Perhaps a discussion?`); - throw new Error(error); } -} + } 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; + + let currentLabels = []; + try { + core.info(`Getting labels for issue ${issue}`); + currentLabels = await github.rest.issues.listLabelsOnIssue({ + issue_number: issue, + owner: context.repo.owner, + repo: context.repo.repo, + }); + } catch (error) { + core.setFailed( + `Unable to get labels for issue ${issue}.\n\n Error details: ${error}` + ); + throw new Error(error); + } + + /** + * Keep all labels except those that start with 'status/' or 'need-' or equal to 'help-wanted' + * as those are contextual to issues still in progress. + */ + const newLabels = currentLabels.data + .filter( + (label) => + !label.name.startsWith("status/") && + !label.name.startsWith("need-") && + label.name !== "help-wanted" + ) + .map((label) => label.name); + // Add the status/pending-release label + newLabels.push(LABEL_PENDING_RELEASE); + + try { + core.info( + `Auto-labeling related issue ${issue} for release while removing 'status/*' and 'need-*' labels` + ); + return await github.rest.issues.replaceLabels({ + issue_number: issue, + owner: context.repo.owner, + repo: context.repo.repo, + labels: newLabels, + }); + } catch (error) { + core.setFailed( + `Is this issue number (${issue}) valid? Perhaps a discussion?` + ); + throw new Error(error); + } +}; diff --git a/.github/scripts/post_release.js b/.github/scripts/post_release.js index 5b6781c475..67b3257b3e 100644 --- a/.github/scripts/post_release.js +++ b/.github/scripts/post_release.js @@ -11,7 +11,6 @@ const { LABEL_PENDING_RELEASE, LABEL_RELEASED } = require("./constants"); * @return {Object[]} issues - Array of issues matching params * @see {@link https://octokit.github.io/rest.js/v18#usage|Octokit client} */ - const fetchIssues = async ({ gh_client, org, @@ -44,7 +43,6 @@ const fetchIssues = async ({ * @param {string} release_version - GitHub Release version * @see {@link https://octokit.github.io/rest.js/v18#usage|Octokit client} */ - const notifyRelease = async ({ gh_client, owner, @@ -57,6 +55,7 @@ const notifyRelease = async ({ gh_client: gh_client, org: owner, repository: repository, + state: "closed" }); issues.forEach(async (issue) => { @@ -79,15 +78,15 @@ const notifyRelease = async ({ // Close issue and remove staged label; keep existing ones const labels = issue.labels .filter((label) => label.name != LABEL_PENDING_RELEASE) - .map((label) => label.name); + .map((label) => label.name) + .push(LABEL_RELEASED); try { - await gh_client.rest.issues.update({ + await gh_client.rest.issues.replaceLabels({ repo: repository, - owner: owner, + owner, issue_number: issue.number, - state: "closed", - labels: [...labels, LABEL_RELEASED], + labels, }); } catch (error) { console.error(error); @@ -99,7 +98,6 @@ const notifyRelease = async ({ }; // context: https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts - module.exports = async ({ github, context }) => { const { RELEASE_VERSION } = process.env; console.log(`Running post-release script for ${RELEASE_VERSION} version`); @@ -108,6 +106,6 @@ module.exports = async ({ github, context }) => { gh_client: github, owner: context.repo.owner, repository: context.repo.repo, - release_version: RELEASE_VERSION, + release_version: RELEASE_VERSION.replace(/v/g, ''), }); }; \ No newline at end of file diff --git a/.github/workflows/post-release.yml b/.github/workflows/post-release.yml new file mode 100644 index 0000000000..cce883a503 --- /dev/null +++ b/.github/workflows/post-release.yml @@ -0,0 +1,33 @@ +name: Post Release + +on: + # Triggered manually + workflow_dispatch: + inputs: + versionNumber: + required: true + type: string + description: "If running this manually please insert a version number that corresponds to the latest published in the GitHub releases (i.e. v1.1.1)" + # Or triggered as result of a release + release: + types: [released] + +jobs: + post_release: + permissions: + contents: read + issues: write + discussions: write + pull-requests: write + runs-on: ubuntu-latest + env: + RELEASE_VERSION: ${{ inputs.versionNumber }} + steps: + - uses: actions/checkout@v3 + - name: Update issues related to release + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const post_release = require('.github/scripts/post_release.js') + await post_release({github, context, core}) \ No newline at end of file diff --git a/MAINTAINERS.md b/MAINTAINERS.md index d3e514f608..20246e7107 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -69,6 +69,7 @@ These are the most common labels used by maintainers to triage issues, pull requ | area/tracer | Items related to the Tracer Utility | PR automation | | area/idempotency | Items related to the Idempotency Utility | PR automation | | area/parameters | Items related to the Parameters Utility | PR automation | +| area/commons | Items related to the Commons Utility | PR automation | | area/automation | Items related to automation like GitHub workflows or CI/CD | PR automation | | size/XS | PRs between 0-9 LOC | PR automation | | size/S | PRs between 10-29 LOC | PR automation | From bf10e6c556d545eceded107e084fa77767a9b005 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 4 May 2023 22:18:55 +0200 Subject: [PATCH 4/9] chore: add path to boring-cyborg --- .github/boring-cyborg.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/boring-cyborg.yml b/.github/boring-cyborg.yml index 0b983e11dd..1fdbf98880 100644 --- a/.github/boring-cyborg.yml +++ b/.github/boring-cyborg.yml @@ -92,6 +92,8 @@ labelPRBasedOnFilePath: - .github/scripts/**/* - .github/workflows/* - .github/workflows/**/* + - .github/actions/* + - .github/actions/**/* - .github/release-drafter.yml - .github/boring-cyborg.yml - .github/semantic.yml @@ -167,4 +169,4 @@ firstPRMergeComment: > firstIssueWelcomeComment: > Thanks for opening your first issue here! We'll come back to you as soon as we can. - In the meantime, check out the #typescript channel on our AWS Lambda Powertools Discord: [Invite link](https://discord.gg/B8zZKbbyET) \ No newline at end of file + In the meantime, check out the #typescript channel on our AWS Lambda Powertools Discord: [Invite link](https://discord.gg/B8zZKbbyET) From b91735c01aba2626141a809de5966146711f0d4b Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 4 May 2023 22:22:24 +0200 Subject: [PATCH 5/9] chore: reverted multi events --- .github/scripts/label_missing_related_issue.js | 6 ++---- .github/scripts/label_related_issue.js | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/scripts/label_missing_related_issue.js b/.github/scripts/label_missing_related_issue.js index b265f97f65..89cae68440 100644 --- a/.github/scripts/label_missing_related_issue.js +++ b/.github/scripts/label_missing_related_issue.js @@ -14,11 +14,9 @@ module.exports = async ({ github, context, core }) => { return core.notice("Author in IGNORE_AUTHORS list; skipping..."); } - if ( - ["opened", "edited", "ready_for_review", "reopened"].includes(PR_ACTION) - ) { + if (["opened"].includes(PR_ACTION)) { return core.notice( - "Only newly opened or updated PRs are labelled to avoid spam; skipping" + "Only newly opened PRs are labelled to avoid spam; skipping" ); } diff --git a/.github/scripts/label_related_issue.js b/.github/scripts/label_related_issue.js index e3d26e1c2b..c86a8affd0 100644 --- a/.github/scripts/label_related_issue.js +++ b/.github/scripts/label_related_issue.js @@ -6,6 +6,7 @@ const { LABEL_PENDING_RELEASE, HANDLE_MAINTAINERS_TEAM, PR_IS_MERGED, + RELATED_ISSUE_REGEX, } = require("./constants"); module.exports = async ({ github, context, core }) => { @@ -18,7 +19,6 @@ module.exports = async ({ github, context, core }) => { } const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY); - try { if (!isMatch) { core.setFailed( From 091e5ef7ebc5e66f1611d199e915ced7a00b4786 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Fri, 5 May 2023 09:01:18 +0200 Subject: [PATCH 6/9] chore: fixed bugs in the scripts --- .github/PULL_REQUEST_TEMPLATE.md | 4 +- .../scripts/label_missing_related_issue.js | 26 ++----- .github/scripts/label_pr_based_on_title.js | 76 ++++++++++--------- .github/scripts/label_related_issue.js | 2 +- 4 files changed, 48 insertions(+), 60 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 154b532a46..ef55fb0f95 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -22,11 +22,9 @@ Add here the number (i.e. #42) to the Github Issue or RFC that is related to thi Don't include any other text, otherwise the Github Issue will not be detected. -Example: -**Issue number:** #42 +Note: If no issue is present the PR might get blocked and not be reviewed. --> **Issue number:** - ## Checklist diff --git a/.github/scripts/label_missing_related_issue.js b/.github/scripts/label_missing_related_issue.js index 89cae68440..f5def29266 100644 --- a/.github/scripts/label_missing_related_issue.js +++ b/.github/scripts/label_missing_related_issue.js @@ -43,24 +43,12 @@ module.exports = async ({ github, context, core }) => { }); } else { const { closingWord, issue } = isMatch.groups; - if (closingWord == null) { - core.info( - `Found related issue #${issue} without closing word, adding one...` - ); - // Add closing word to the PR body - const msg = `Issue number: closes ${issue}`; - const updatedPRBody = PR_BODY.replace(RELATED_ISSUE_REGEX, msg); - - await github.rest.issues.update({ - owner: context.repo.owner, - repo: context.repo.repo, - body: updatedPRBody, - issue_number: PR_NUMBER, - }); - } else { - core.info( - `Found related issue #${issue} with closing word '${closingWord}'` - ); - } + core.info( + `Found related issue #${issue} ${ + closingWord === undefined + ? "without closing word" + : `with closing word ${closingWord}` + }` + ); } }; diff --git a/.github/scripts/label_pr_based_on_title.js b/.github/scripts/label_pr_based_on_title.js index 0ba337233f..24e17191b9 100644 --- a/.github/scripts/label_pr_based_on_title.js +++ b/.github/scripts/label_pr_based_on_title.js @@ -1,43 +1,45 @@ const { PR_NUMBER, PR_TITLE } = require("./constants"); -module.exports = async ({github, context, core}) => { - const BUG_REGEX = /(fix|bug)(\((.+)\))?(:.+)/ - const FEAT_REFACTOR_REGEX = /(feat|refactor)(\((.+)\))?(:.+)/ - const CHORE_REGEX = /(chore)(\((.+)\))?(:.+)/ - const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(:.+)/ - - const labels = { - "type/feature": FEAT_REFACTOR_REGEX, - "type/bug": BUG_REGEX, - "type/internal": CHORE_REGEX, - "type/deprecation": DEPRECATED_REGEX, - } +module.exports = async ({ github, context, core }) => { + const BUG_REGEX = /(fix|bug)(\((.+)\))?(:.+)/; + const ENHANCEMENT_REGEX = /(refactor|improv)(\((.+)\))?(:.+)/; + const FEAT_REFACTOR_REGEX = /(feat)(\((.+)\))?(:.+)/; + const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(:.+)/; + + const labels = { + "type/feature": FEAT_REFACTOR_REGEX, + "type/bug": BUG_REGEX, + "type/deprecation": DEPRECATED_REGEX, + "type/enhancement": ENHANCEMENT_REGEX, + }; - // Maintenance: We should keep track of modified PRs in case their titles change - let miss = 0; - try { - for (const label in labels) { - const matcher = new RegExp(labels[label]); - const matches = matcher.exec(PR_TITLE); - if (matches != null) { - core.info(`Auto-labeling PR ${PR_NUMBER} with ${label}`); + // Maintenance: We should keep track of modified PRs in case their titles change + let miss = 0; + try { + for (const label in labels) { + const matcher = new RegExp(labels[label]); + const matches = matcher.exec(PR_TITLE); + if (matches != null) { + core.info(`Auto-labeling PR ${PR_NUMBER} with ${label}`); - 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], + }); - return; - } else { - core.debug(`'${PR_TITLE}' didn't match '${label}' semantic.`); - miss += 1; - } - } - } finally { - if (miss == Object.keys(labels).length) { - core.notice(`PR ${PR_NUMBER} title '${PR_TITLE}' doesn't follow semantic titles; skipping...`); - } + return; + } else { + core.debug(`'${PR_TITLE}' didn't match '${label}' semantic.`); + miss += 1; + } + } + } finally { + if (miss == Object.keys(labels).length) { + core.notice( + `PR ${PR_NUMBER} title '${PR_TITLE}' doesn't follow semantic titles; skipping...` + ); } -} \ No newline at end of file + } +}; diff --git a/.github/scripts/label_related_issue.js b/.github/scripts/label_related_issue.js index c86a8affd0..e57f6621ba 100644 --- a/.github/scripts/label_related_issue.js +++ b/.github/scripts/label_related_issue.js @@ -76,7 +76,7 @@ module.exports = async ({ github, context, core }) => { core.info( `Auto-labeling related issue ${issue} for release while removing 'status/*' and 'need-*' labels` ); - return await github.rest.issues.replaceLabels({ + return await github.rest.issues.setLabels({ issue_number: issue, owner: context.repo.owner, repo: context.repo.repo, From 6f475b20404d5fa02b359bd1b56dcfe7336ac636 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Fri, 5 May 2023 09:11:54 +0200 Subject: [PATCH 7/9] chore: added missing labels into document --- .github/boring-cyborg.yml | 1 + MAINTAINERS.md | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/boring-cyborg.yml b/.github/boring-cyborg.yml index 1fdbf98880..d19858b927 100644 --- a/.github/boring-cyborg.yml +++ b/.github/boring-cyborg.yml @@ -27,6 +27,7 @@ labelPRBasedOnFilePath: area/commons: - packages/commons/src/* - packages/commons/src/**/* + area/layers: - layers/src/* - layers/src/**/* diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 20246e7107..b320bdb9f9 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -71,6 +71,7 @@ These are the most common labels used by maintainers to triage issues, pull requ | area/parameters | Items related to the Parameters Utility | PR automation | | area/commons | Items related to the Commons Utility | PR automation | | area/automation | Items related to automation like GitHub workflows or CI/CD | PR automation | +| area/layers | Items related to the Lambda Layers pipeline | PR automation | | size/XS | PRs between 0-9 LOC | PR automation | | size/S | PRs between 10-29 LOC | PR automation | | size/M | PRs between 30-99 LOC | PR automation | From aa3f72a1542ad5d9fdcf03296ec7b34345324d59 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Fri, 5 May 2023 09:27:57 +0200 Subject: [PATCH 8/9] chore: fixed setLabels command --- .github/scripts/post_release.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/post_release.js b/.github/scripts/post_release.js index 67b3257b3e..2f6473e942 100644 --- a/.github/scripts/post_release.js +++ b/.github/scripts/post_release.js @@ -82,7 +82,7 @@ const notifyRelease = async ({ .push(LABEL_RELEASED); try { - await gh_client.rest.issues.replaceLabels({ + await gh_client.rest.issues.setLabels({ repo: repository, owner, issue_number: issue.number, From 4fa35bae9a7c5d9a94392ba927bb8e423ea2fc80 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Fri, 5 May 2023 09:30:00 +0200 Subject: [PATCH 9/9] chore: fix version tag in url --- .github/scripts/post_release.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/post_release.js b/.github/scripts/post_release.js index 2f6473e942..7eeebeb24b 100644 --- a/.github/scripts/post_release.js +++ b/.github/scripts/post_release.js @@ -49,7 +49,7 @@ const notifyRelease = async ({ repository, release_version, }) => { - const release_url = `https://github.com/${owner}/${repository}/releases/tag/v${release_version}`; + const release_url = `https://github.com/${owner}/${repository}/releases/tag/v${release_version.replace(/v/g, '')}`; const issues = await fetchIssues({ gh_client: gh_client, @@ -106,6 +106,6 @@ module.exports = async ({ github, context }) => { gh_client: github, owner: context.repo.owner, repository: context.repo.repo, - release_version: RELEASE_VERSION.replace(/v/g, ''), + release_version: RELEASE_VERSION, }); }; \ No newline at end of file