Skip to content

Commit 3ece66e

Browse files
authored
[NDR-309] Add checkbox requirements to a PR (#877)
1 parent 6facb71 commit 3ece66e

File tree

7 files changed

+105
-1
lines changed

7 files changed

+105
-1
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- markdownlint-disable-next-line first-line-heading -->
2+
3+
## Description
4+
5+
<!-- Describe your changes in detail. -->
6+
7+
## Context
8+
9+
<!-- Why is this change required? What problem does it solve? -->
10+
11+
## Checklist
12+
13+
<!-- Go over all the following points, and put an `x` in all the boxes that apply. -->
14+
15+
- [ ] I have followed the code style of the project.
16+
- [ ] I have added tests to cover my changes.
17+
- [ ] I have updated the documentation accordingly.
18+
- [ ] I have considered the cross-team impact when creating this PR and where possible written tests to validate for all affected.
19+
- [ ] I have built a sandbox with code from this PR and ensured the unit tests and end-to-end tests have run successfully.
20+
- [ ] A member of all teams has approved this PR if there is a major code change. (If this is a minor change and you are confident this is not necessary then you may accept the standard approval process of 2 approvals from any teams.)
21+
22+
---
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "Z-AUTOMATED: PR Validator"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types: [opened, edited, synchronize]
8+
9+
permissions:
10+
contents: read
11+
pull-requests: read
12+
13+
jobs:
14+
checklist_validator:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v5
19+
20+
- name: Set up Python 3.11
21+
uses: actions/setup-python@v6
22+
with:
23+
python-version: 3.11
24+
25+
- name: Run checklist validator
26+
run: |
27+
python3 scripts/github/checklist_validator/main.py
28+
env:
29+
PR_BODY: ${{ github.event.pull_request.body }}

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ test-bulk-upload-e2e:
8383
cd ./lambdas && ./venv/bin/python3 -m pytest tests/e2e/bulk_upload -vv
8484

8585
test-unit:
86-
cd ./lambdas && ./venv/bin/python3 -m pytest tests/unit
86+
cd ./lambdas && \
87+
PYTHONPATH=.. ./venv/bin/python3 -m pytest tests/unit ../scripts/github/checklist_validator/tests
8788

8889
test-unit-coverage:
8990
cd ./lambdas && ./venv/bin/python3 -m pytest tests/unit --cov=. --cov-report xml:coverage.xml

scripts/github/checklist_validator/__init__.py

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
def validate_checklist(body: str) -> bool:
2+
"""
3+
Check if all PR checklist items are ticked.
4+
Returns True if all boxes are checked, False otherwise.
5+
"""
6+
if not body:
7+
return False
8+
9+
lines = body.splitlines()
10+
for line in lines:
11+
line = line.strip()
12+
if line.startswith("- [ ]"):
13+
return False
14+
return True
15+
16+
17+
def main():
18+
import os
19+
20+
pr_body = os.environ.get("PR_BODY", "")
21+
if validate_checklist(pr_body):
22+
print("All checklist items are checked ✅")
23+
exit(0)
24+
else:
25+
print("Some checklist items are not checked ❌")
26+
exit(1)
27+
28+
29+
if __name__ == "__main__":
30+
main()

scripts/github/checklist_validator/tests/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
from scripts.github.checklist_validator.main import validate_checklist
3+
4+
5+
def test_all_checked():
6+
body = """
7+
- [x] Task 1
8+
- [x] Task 2
9+
"""
10+
assert validate_checklist(body) is True
11+
12+
13+
def test_some_unchecked():
14+
body = """
15+
- [x] Task 1
16+
- [ ] Task 2
17+
"""
18+
assert validate_checklist(body) is False
19+
20+
21+
def test_empty_body():
22+
assert validate_checklist("") is False

0 commit comments

Comments
 (0)