Skip to content

Commit cd83ddf

Browse files
machado144claude
andcommitted
ci: add PR title conventional commit validation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5ce5028 commit cd83ddf

File tree

4 files changed

+76
-49
lines changed

4 files changed

+76
-49
lines changed

.github/workflows/pr.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened]
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
13+
jobs:
14+
title:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Validate PR title follows Conventional Commits
18+
env:
19+
TITLE: ${{ github.event.pull_request.title }}
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
run: |
22+
if echo "$TITLE" | grep -qE "^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\(.+\))?(!)?: .+"; then
23+
echo "PR title is valid: $TITLE"
24+
exit 0
25+
fi
26+
27+
BODY=$(cat <<'COMMENT'
28+
### ⚠️ Invalid PR Title
29+
30+
PR title must follow the **Conventional Commits** format since we use squash merge:
31+
32+
```
33+
<type>[optional scope][!]: <description>
34+
```
35+
36+
**Allowed types:** `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`, `build`, `ci`, `perf`, `revert`
37+
38+
**Examples:**
39+
- `feat: add new feature`
40+
- `fix(api): resolve null pointer`
41+
- `feat!: breaking change`
42+
- `chore(deps): update dependencies`
43+
COMMENT
44+
)
45+
46+
# Post comment on PR
47+
gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
48+
-X POST -f body="$BODY"
49+
50+
echo "::error::PR title must follow Conventional Commits format"
51+
exit 1
52+
53+
review:
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
- uses: AxeForging/reviewforge@main
58+
with:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
AI_PROVIDER: gemini
61+
AI_MODEL: gemini-2.5-flash
62+
AI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
63+
SHOW_TOKEN_USAGE: true
64+
INCREMENTAL: false
65+
REVIEW_RULES: concise
66+
67+
validate:
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v4
71+
- uses: AxeForging/structlint@main
72+
with:
73+
config: .structlint.yaml
74+
comment-on-pr: "true"
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/review.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/validate.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

lefthook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ commit-msg:
2727
run: |
2828
msg=$(cat {1})
2929
# Check for conventional commit format
30-
if ! echo "$msg" | grep -qE "^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\(.+\))?: .+"; then
30+
if ! echo "$msg" | grep -qE "^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\(.+\))?(!)?: .+"; then
3131
echo "Error: Commit message must follow conventional commits format"
3232
echo "Examples:"
3333
echo " feat: add new feature"

0 commit comments

Comments
 (0)