Skip to content

Commit b475245

Browse files
dreamiurgclaude
andauthored
chore: add commit and PR templates with validation (#1)
* chore: add no-commit-to-branch hook to prevent direct commits to master/main Adds pre-commit hook that prevents accidental commits directly to protected branches (master and main). Works in conjunction with GitHub branch protection rules as an additional safeguard. This ensures all changes go through pull requests and proper review workflow. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: add commit and PR templates with validation Adds comprehensive templates and validation for conventional commits: Templates: - .gitmessage: Git commit message template with conventional commit format guide - .github/pull_request_template.md: PR template with clear instructions on title format - scripts/setup-git-hooks.sh: Setup script to configure git templates and pre-commit hooks Validation: - .github/workflows/validate-pr-title.yml: GitHub Action to enforce conventional commit format in PR titles - Uses amannn/action-semantic-pull-request to validate PR titles match semantic-release requirements Documentation: - Updated CLAUDE.md with development setup instructions - Added section explaining PR title enforcement This ensures all PRs follow conventional commit format, which is required for semantic-release to properly version releases. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: simplify PR template to compact format Reduces PR template verbosity while keeping essential information: - Shortened conventional commit format instructions - Simplified type selection checkboxes - Removed unnecessary sections (testing, checklist, etc.) - Kept GitHub Action validation notice 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e96faa0 commit b475245

File tree

6 files changed

+146
-1
lines changed

6 files changed

+146
-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+
<!--
2+
⚠️ PR TITLE FORMAT: type: description ⚠️
3+
4+
feat: → minor bump | fix: → patch bump | feat!/fix!: → major bump
5+
chore/docs/refactor/test/ci: → no release
6+
7+
A GitHub Action validates your title format.
8+
-->
9+
10+
## Summary
11+
12+
13+
## Type
14+
- [ ] feat (minor bump)
15+
- [ ] fix (patch bump)
16+
- [ ] feat!/fix! (major bump)
17+
- [ ] chore/docs/refactor/test/ci (no release)
18+
19+
## Changes
20+
21+
-
22+
-
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Validate PR Title
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened]
6+
7+
jobs:
8+
validate-title:
9+
name: Validate PR title follows conventional commit format
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: amannn/action-semantic-pull-request@v5
13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
with:
16+
# Configure which types are allowed (must match semantic-release config)
17+
types: |
18+
feat
19+
fix
20+
docs
21+
style
22+
refactor
23+
perf
24+
test
25+
chore
26+
ci
27+
build
28+
# Allow scope in format: type(scope): description
29+
requireScope: false
30+
# Subject must not be empty
31+
subjectPattern: ^.+$
32+
subjectPatternError: |
33+
The subject "{subject}" found in the PR title "{title}"
34+
must not be empty.
35+
# Validate the entire title
36+
validateSingleCommit: false
37+
# Ignore bot PRs (dependabot, etc.)
38+
ignoreLabels: |
39+
bot
40+
dependencies

.gitmessage

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# <type>: <subject>
2+
#
3+
# <body>
4+
#
5+
# <footer>
6+
7+
# --- COMMIT TYPES ---
8+
# feat: New feature (triggers MINOR version bump)
9+
# fix: Bug fix (triggers PATCH version bump)
10+
# docs: Documentation only changes (no release)
11+
# style: Code style/formatting (no release)
12+
# refactor: Code refactoring (no release)
13+
# perf: Performance improvement (triggers PATCH version bump)
14+
# test: Adding or updating tests (no release)
15+
# chore: Maintenance, dependencies, tooling (no release)
16+
# ci: CI/CD configuration (no release)
17+
# build: Build system changes (no release)
18+
#
19+
# --- BREAKING CHANGES ---
20+
# Use ! after type for breaking changes: feat!: or fix!:
21+
# OR add "BREAKING CHANGE:" in footer
22+
# Breaking changes trigger MAJOR version bump
23+
#
24+
# --- RULES ---
25+
# - Subject line: max 50 chars, imperative mood, lowercase after colon, no period
26+
# - Body: wrap at 72 chars, explain WHY not WHAT
27+
# - Footer: reference issues, breaking changes
28+
#
29+
# --- EXAMPLES ---
30+
# feat: add batch peak lookup with rate limiting
31+
#
32+
# fix: handle missing elevation data in scraper
33+
#
34+
# feat!: restructure CLI to resource-action pattern
35+
#
36+
# BREAKING CHANGE: all command names changed to use resource-action pattern
37+
#
38+
# docs: update README with new command examples
39+
#
40+
# chore: update dependencies to latest versions

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
77
rev: v5.0.0
88
hooks:
9+
# Branch protection
10+
- id: no-commit-to-branch
11+
args: [--branch, master, --branch, main]
12+
913
# Formatting and whitespace
1014
- id: trailing-whitespace
1115
args: [--markdown-linebreak-ext=md]

CLAUDE.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ A Python CLI tool for scraping mountain peak data from PeakBagger.com. Uses Clic
1717
- **Version Management**: python-semantic-release
1818
- **Pre-commit**: Configured with multiple hooks
1919

20+
## Development Setup
21+
22+
```bash
23+
# First time setup - configure git hooks and commit template
24+
bash scripts/setup-git-hooks.sh
25+
26+
# This will:
27+
# - Install pre-commit hooks (prevents commits to master/main)
28+
# - Configure commit message template with conventional commit format
29+
```
30+
2031
## Development Commands
2132

2233
```bash
@@ -43,7 +54,7 @@ uv build
4354
npx semantic-release --dry-run
4455

4556
# Create release (done automatically via GitHub Actions)
46-
# Just push to main/master with conventional commit
57+
# Just merge PR to main/master with conventional commit title
4758
```
4859

4960
## Commit Message Format

scripts/setup-git-hooks.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
# Setup git hooks and commit message template for peakbagger-cli
3+
4+
set -e
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
8+
9+
echo "Setting up git hooks and commit message template..."
10+
11+
# Set commit message template
12+
git config commit.template "${PROJECT_ROOT}/.gitmessage"
13+
echo "✓ Commit message template configured"
14+
15+
# Install pre-commit hooks
16+
if command -v pre-commit &> /dev/null; then
17+
pre-commit install
18+
echo "✓ Pre-commit hooks installed"
19+
else
20+
echo "⚠ pre-commit not found. Install with: uv tool install pre-commit"
21+
echo " Then run: pre-commit install"
22+
fi
23+
24+
echo ""
25+
echo "Git configuration complete!"
26+
echo ""
27+
echo "Your commits will now use the conventional commit template."
28+
echo "The template will appear when you run: git commit"

0 commit comments

Comments
 (0)