Skip to content

Commit 104be8f

Browse files
chore(maintenance): validate acknowledgement section is present (#2112)
maintenance(opened-pr): add missing ack section
1 parent 09b7b74 commit 104be8f

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.github/scripts/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ module.exports = Object.freeze({
2424
/** @type {string} */
2525
"LABEL_BLOCK_REASON": "need-issue",
2626

27+
/** @type {string} */
28+
"LABEL_BLOCK_MISSING_LICENSE_AGREEMENT": "need-license-agreement-acknowledge",
29+
2730
/** @type {string} */
2831
"LABEL_PENDING_RELEASE": "pending-release",
2932

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const {
2+
PR_ACTION,
3+
PR_AUTHOR,
4+
PR_BODY,
5+
PR_NUMBER,
6+
IGNORE_AUTHORS,
7+
LABEL_BLOCK,
8+
LABEL_BLOCK_MISSING_LICENSE_AGREEMENT
9+
} = require("./constants")
10+
11+
module.exports = async ({github, context, core}) => {
12+
if (IGNORE_AUTHORS.includes(PR_AUTHOR)) {
13+
return core.notice("Author in IGNORE_AUTHORS list; skipping...")
14+
}
15+
16+
if (PR_ACTION != "opened") {
17+
return core.notice("Only newly open PRs are labelled to avoid spam; skipping")
18+
}
19+
20+
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\./;
21+
22+
const isMatch = RELATED_ACK_SECTION_REGEX.exec(PR_BODY);
23+
if (isMatch == null) {
24+
core.info(`No acknowledgement section found, maybe the author didn't use the template but there is one.`)
25+
26+
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";
27+
await github.rest.issues.createComment({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
body: msg,
31+
issue_number: PR_NUMBER,
32+
});
33+
34+
return await github.rest.issues.addLabels({
35+
issue_number: PR_NUMBER,
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
labels: [LABEL_BLOCK, LABEL_BLOCK_MISSING_LICENSE_AGREEMENT]
39+
})
40+
}
41+
}

.github/workflows/on_opened_pr.yml

+17
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,20 @@ jobs:
3232
script: |
3333
const script = require('.github/scripts/label_missing_related_issue.js')
3434
await script({github, context, core})
35+
check_acknowledge_section:
36+
needs: get_pr_details
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v3
40+
- name: "Ensure acknowledgement section is present"
41+
uses: actions/github-script@v6
42+
env:
43+
PR_BODY: ${{ needs.get_pr_details.outputs.prBody }}
44+
PR_NUMBER: ${{ needs.get_pr_details.outputs.prNumber }}
45+
PR_ACTION: ${{ needs.get_pr_details.outputs.prAction }}
46+
PR_AUTHOR: ${{ needs.get_pr_details.outputs.prAuthor }}
47+
with:
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
script: |
50+
const script = require('.github/scripts/label_missing_acknowledgement_section.js')
51+
await script({github, context, core})

0 commit comments

Comments
 (0)