Skip to content

Commit 1f97cfa

Browse files
committed
ci: add PR title validator
1 parent 2d8ad29 commit 1f97cfa

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: PR Title Check
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
jobs:
11+
check-pr-title:
12+
name: Validate PR Title
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Check PR Title Format
17+
run: |
18+
PR_TITLE="${{ github.event.pull_request.title }}"
19+
20+
# Rule 1: PR title must not be empty
21+
if [ -z "$PR_TITLE" ]; then
22+
echo "❌ PR title cannot be empty."
23+
exit 1
24+
fi
25+
26+
# Rule 2: PR title must follow Conventional Commits format
27+
# Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
28+
PATTERN="^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?: .+"
29+
if ! echo "$PR_TITLE" | grep -Eq "$PATTERN"; then
30+
echo "❌ PR title does not follow the required format."
31+
echo ""
32+
echo "Expected format: <type>: <description>"
33+
echo " or: <type>(scope): <description>"
34+
echo ""
35+
echo "Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
36+
echo ""
37+
echo "Examples:"
38+
echo " feat: add new block palette"
39+
echo " fix: resolve audio issue"
40+
echo " docs: update contributing guidelines"
41+
echo ""
42+
echo "Your title: \"$PR_TITLE\""
43+
exit 1
44+
fi
45+
46+
echo "✅ PR title is valid: \"$PR_TITLE\""

0 commit comments

Comments
 (0)