From 5673b9d40ac3bfad954eb263fe885e9dadc1c837 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Wed, 12 Apr 2023 00:50:20 +0100 Subject: [PATCH] maintenance(opened-pr): add missing ack section --- .github/scripts/constants.js | 3 ++ .../label_missing_acknowledgement_section.js | 41 +++++++++++++++++++ .github/workflows/on_opened_pr.yml | 17 ++++++++ 3 files changed, 61 insertions(+) create mode 100644 .github/scripts/label_missing_acknowledgement_section.js diff --git a/.github/scripts/constants.js b/.github/scripts/constants.js index deeaddd9c41..96f599b58ed 100644 --- a/.github/scripts/constants.js +++ b/.github/scripts/constants.js @@ -24,6 +24,9 @@ module.exports = Object.freeze({ /** @type {string} */ "LABEL_BLOCK_REASON": "need-issue", + /** @type {string} */ + "LABEL_BLOCK_MISSING_LICENSE_AGREEMENT": "need-license-agreement-acknowledge", + /** @type {string} */ "LABEL_PENDING_RELEASE": "pending-release", diff --git a/.github/scripts/label_missing_acknowledgement_section.js b/.github/scripts/label_missing_acknowledgement_section.js new file mode 100644 index 00000000000..1c9996c3897 --- /dev/null +++ b/.github/scripts/label_missing_acknowledgement_section.js @@ -0,0 +1,41 @@ +const { + PR_ACTION, + PR_AUTHOR, + PR_BODY, + PR_NUMBER, + IGNORE_AUTHORS, + LABEL_BLOCK, + LABEL_BLOCK_MISSING_LICENSE_AGREEMENT +} = 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_ACTION != "opened") { + return core.notice("Only newly open PRs are labelled to avoid spam; skipping") + } + + const RELATED_ACK_SECTION_REGEX = /## Acknowledgment\n\nBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.\n\n\*\*Disclaimer\*\*: We value your time and bandwidth\. As such, any pull requests created on non-triaged issues might not be successful\./; + + const isMatch = RELATED_ACK_SECTION_REGEX.exec(PR_BODY); + if (isMatch == null) { + core.info(`No acknowledgement section found, maybe the author didn't use the template but there is one.`) + + let msg = "No acknowledgement section found. Please make sure you used the template to open a PR and didn't remove the acknowledgment section. Check the template here: https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/.github/PULL_REQUEST_TEMPLATE.md#acknowledgment"; + 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_MISSING_LICENSE_AGREEMENT] + }) + } +} diff --git a/.github/workflows/on_opened_pr.yml b/.github/workflows/on_opened_pr.yml index 6c5979c8b80..043ff9628cd 100644 --- a/.github/workflows/on_opened_pr.yml +++ b/.github/workflows/on_opened_pr.yml @@ -32,3 +32,20 @@ jobs: script: | const script = require('.github/scripts/label_missing_related_issue.js') await script({github, context, core}) + check_acknowledge_section: + needs: get_pr_details + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: "Ensure acknowledgement section is present" + uses: actions/github-script@v6 + env: + PR_BODY: ${{ needs.get_pr_details.outputs.prBody }} + PR_NUMBER: ${{ needs.get_pr_details.outputs.prNumber }} + PR_ACTION: ${{ needs.get_pr_details.outputs.prAction }} + PR_AUTHOR: ${{ needs.get_pr_details.outputs.prAuthor }} + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const script = require('.github/scripts/label_missing_acknowledgement_section.js') + await script({github, context, core})