-
Notifications
You must be signed in to change notification settings - Fork 19
134 lines (116 loc) · 5 KB
/
pr-description-check.yaml
File metadata and controls
134 lines (116 loc) · 5 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
name: PR Description Check
on:
pull_request:
types: [opened, synchronize, reopened, edited]
branches: [ main, 'feature/**', 'release/**' ]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
validate-pr-description:
runs-on: ubuntu-latest
steps:
- name: Validate PR Description
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
echo "Validating PR description..."
echo "----------------------------------------"
# Initialize error tracking
has_errors=false
error_messages=""
# Check 1: Verify Issue # is present (case-insensitive)
if ! echo "$PR_BODY" | grep -qiE "Issue (#[0-9]+|#None|- None)"; then
has_errors=true
error_messages="${error_messages}
❌ ERROR: Missing or invalid Issue reference
The PR description must include an issue reference in the format:
'Issue #XX' (where XX is a number) or 'Issue - None'
(Case-insensitive: 'issue #123' or 'ISSUE #None' are also valid)
Example:
Issue #123
Issue - None
issue #42
"
else
echo "✅ Issue reference found"
fi
# Check 2: Verify all checklist items in the Checklist section are checked
# Extract only the Checklist section - more robust approach
# Save PR body to a temp file for easier processing
echo "$PR_BODY" > /tmp/pr_body.txt
# Extract checklist section: from "## Checklist" to next "##" or end of file
checklist_section=$(awk '
/^## [Cc]hecklist/ { in_checklist=1; next }
in_checklist && /^##/ { exit }
in_checklist { print }
' /tmp/pr_body.txt)
# Check if we found a checklist section
if [ -z "$checklist_section" ]; then
has_errors=true
error_messages="${error_messages}
❌ ERROR: Missing Checklist section
The PR description must include a '## Checklist' section.
Please see the PR template: .github/PULL_REQUEST_TEMPLATE.md
"
else
# Count checkbox items in the checklist
total_checkboxes=$(echo "$checklist_section" | grep -cE "^- \[[ xX]\]" || true)
unchecked_items=$(echo "$checklist_section" | grep -cE "^- \[ \]" || true)
if [ "$total_checkboxes" -eq 0 ]; then
has_errors=true
error_messages="${error_messages}
❌ ERROR: No checklist items found
The ## Checklist section exists but contains no checkbox items.
Please see the PR template: .github/PULL_REQUEST_TEMPLATE.md
"
elif [ "$unchecked_items" -gt 0 ]; then
has_errors=true
error_messages="${error_messages}
❌ ERROR: Incomplete checklist
All checklist items must be completed before the PR can be merged.
Found $unchecked_items unchecked item(s) out of $total_checkboxes in the ## Checklist section.
Please check all boxes in the checklist:
- [x] I am familiar with the Contributing Guidelines
- [x] New or existing tests cover these changes
- [x] The documentation is up to date with these changes
"
else
echo "✅ All $total_checkboxes checklist items are checked"
fi
fi
# Clean up temp file
rm -f /tmp/pr_body.txt
# Report results
if [ "$has_errors" = true ]; then
echo ""
echo "========================================"
echo "PR DESCRIPTION VALIDATION FAILED"
echo "========================================"
echo "$error_messages"
echo ""
echo "Please update your PR description to meet the requirements."
echo "See the PR template: .github/PULL_REQUEST_TEMPLATE.md"
echo "========================================"
exit 1
else
echo ""
echo "========================================"
echo "✅ PR description validation passed!"
echo "========================================"
fi