Skip to content

chore(maintenance): validate acknowledgement section is present #2112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down
41 changes: 41 additions & 0 deletions .github/scripts/label_missing_acknowledgement_section.js
Original file line number Diff line number Diff line change
@@ -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]
})
}
}
17 changes: 17 additions & 0 deletions .github/workflows/on_opened_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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})