Repository navigation
112 lines (102 loc) · 4.37 KB
/
Copy pathpr-validator.yml
File metadata and controls
112 lines (102 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: PR Validation Bot
on:
pull_request:
types: [opened, edited, synchronize, reopened]
branches: [main]
permissions:
pull-requests: write
contents: read
jobs:
validate-pr:
name: Validate PR Title & Template Sections
runs-on: ubuntu-latest
steps:
- name: Validate PR Title (Conventional Commits)
id: title-check
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
echo "Validating PR title: '$PR_TITLE'"
REGEX="^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|task|revert)(\([a-zA-Z0-9_\.\-]+\))?: .{3,120}$"
if [[ ! "$PR_TITLE" =~ $REGEX ]]; then
echo "::error::PR Title '$PR_TITLE' does not conform to Conventional Commits standard."
echo "Expected format: '<type>(<optional-scope>): <description>'"
echo "Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, task, revert"
echo "Example: 'feat(planter): add self-watering dual wick geometry'"
echo "TITLE_OK=false" >> $GITHUB_ENV
else
echo "✓ PR Title follows Conventional Commits format."
echo "TITLE_OK=true" >> $GITHUB_ENV
fi
- name: Validate PR Body Sections
id: body-check
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
REQUIRED_SECTIONS=(
"## Summary"
"## Motivation / Context"
"## Changes"
"## Verification & Testing"
"## Checklist"
)
MISSING=()
for section in "${REQUIRED_SECTIONS[@]}"; do
if ! grep -qiF "$section" <<< "$PR_BODY"; then
MISSING+=("$section")
fi
done
if [ ${#MISSING[@]} -ne 0 ]; then
echo "::error::PR Description is missing required template sections:"
for m in "${MISSING[@]}"; do
echo " - $m"
done
echo "BODY_OK=false" >> $GITHUB_ENV
else
echo "✓ All required PR description sections are present."
echo "BODY_OK=true" >> $GITHUB_ENV
fi
- name: Post PR Validation Status Comment
if: always() && github.event.pull_request.number
uses: actions/github-script@v7
with:
script: |
const titleOk = process.env.TITLE_OK === 'true';
const bodyOk = process.env.BODY_OK === 'true';
const issue_number = context.issue.number;
let message = '';
if (titleOk && bodyOk) {
message = `### ✅ PR Validation Passed\n\n- [x] Conventional Commit title syntax\n- [x] Required template sections present\n- [x] Slicing & CAD verification recorded\n\n*Ready for review by @${context.repo.owner}!*`;
} else {
message = `### ⚠️ PR Validation Requirements Incomplete\n\nPlease address the following before this PR can be merged:\n\n`;
if (!titleOk) {
message += `- ❌ **PR Title**: Must conform to Conventional Commits: \`type(scope): description\` (e.g. \`feat(cad): add threaded connector module\`).\n`;
}
if (!bodyOk) {
message += `- ❌ **PR Body**: Missing one or more required sections from \`.github/pull_request_template.md\` (\`## Summary\`, \`## Motivation / Context\`, \`## Changes\`, \`## Verification & Testing\`, \`## Checklist\`).\n`;
}
}
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
});
const botComment = comments.data.find(c => c.body.includes('PR Validation'));
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: message
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
}
if (!titleOk || !bodyOk) {
core.setFailed('PR does not meet validation standards.');
}