Workflow: Git PR Automation
Never write a "Fix bug" commit message again. Transform your code review process from a chore into a competitive advantage with AI-powered automation that ensures every PR is polished, tested, and professionally documented.
Developers spend an average of 4 hours per week on code review overhead: writing commit messages, filling out PR descriptions, waiting for CI results, and fixing linting errors discovered late in the process. For a team of 10 developers, that's 160 hours per month—nearly a full-time engineer's capacity—spent on administrative tasks rather than building features.
The Git PR Automation workflow eliminates this waste entirely. By orchestrating linting, testing, analysis, and documentation into a single intelligent pipeline, you can ensure every code submission meets your team's standards without manual intervention.
Why This Matters
Code quality is non-negotiable, but the overhead doesn't have to be. This workflow doesn't just automate checks—it elevates your entire development process:
- Consistency: Every commit follows Conventional Commits specification
- Quality: Tests and linting run before you even create the PR
- Documentation: AI-generated PR descriptions that actually explain the changes
- Speed: Eliminate the review ping-pong with comprehensive first submissions
The ROI is immediate:
- Save 30-45 minutes per PR
- Reduce review cycles by 50%
- Eliminate "fix linting" and "update tests" follow-up commits
- Maintain professional commit history automatically
The Goal: Your Complete PR Automation Pipeline
This workflow creates a comprehensive pre-submission pipeline that includes:
1. Pre-Commit Quality Checks
Before any code leaves your machine:
- Linting: Run ESLint, Prettier, Black, or your preferred linter
- Auto-fixing: Automatically correct simple formatting issues
- Type Checking: Run TypeScript or mypy to catch type errors
- Static Analysis: Security scans and complexity checks
2. Test Suite Execution
Comprehensive testing before submission:
- Unit Tests: Fast feedback on logic changes
- Integration Tests: Verify component interactions
- Coverage Analysis: Flag significant coverage drops
- Flaky Test Detection: Identify unreliable tests
3. Intelligent Diff Analysis
Claude analyzes your changes with context:
- Change Summary: High-level overview of modifications
- Impact Assessment: Identify affected components and dependencies
- Risk Indicators: Flag potentially breaking changes
- Testing Gaps: Highlight areas lacking test coverage
4. Semantic Commit Generation
AI-powered commit message creation:
- Conventional Commits: Follow
type(scope): descriptionformat - Context-Aware: Reference related issues and PRs
- Detailed Bodies: Explain the "why" behind changes
- Breaking Change Detection: Automatically flag API changes
5. Professional PR Documentation
Comprehensive pull request descriptions:
- Executive Summary: TL;DR for busy reviewers
- Detailed Changes: Bullet-point breakdown of modifications
- Testing Notes: What was tested and how
- Migration Guide: Instructions for breaking changes
- Screenshots: Auto-generated for UI changes (if applicable)
The Setup: Building Your Automation Pipeline
Prerequisites
Required Tools:
- Git: Local repository access
- Test Runner: Jest, Vitest, pytest, or equivalent
- Linter: ESLint, Prettier, Black, rubocop, etc.
- Claude Cowork: With git-assistant and code-reviewer skills
Optional Enhancements:
- Husky: Git hooks for pre-commit automation
- lint-staged: Run checks only on changed files
- GitHub CLI: For automated PR creation
- Code Coverage: Istanbul, coverage.py, or similar
Step-by-Step Configuration
Step 1: Install Git Hooks (Optional but Recommended)
Set up Husky for automatic pre-commit checks:
npm install --save-dev husky lint-staged
npx husky init
Create .husky/pre-commit:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
Configure lint-staged in package.json:
{
"lint-staged": {
"*.{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{py}": ["black", "flake8"]
}
}
Step 2: Create the Master Prompt
Save this as your PR automation prompt:
Run the Git PR Automation protocol:
1. PRE-SUBMISSION CHECKS
Run the following and report results:
- npm run lint (or equivalent)
- npm run test (or equivalent)
- npm run type-check (if applicable)
- npm run build (to verify compilation)
If any checks fail:
- Show the exact error messages
- Suggest fixes for common issues
- Ask before proceeding if errors are complex
2. DIFF ANALYSIS
Analyze the current git diff:
- Summarize the high-level purpose of changes
- Identify which components/modules are affected
- Flag any potentially breaking changes
- Note any security-sensitive modifications
- Check for test coverage on changed lines
3. COMMIT MESSAGE GENERATION
Write a commit message following Conventional Commits:
- Format: type(scope): subject
- Types: feat, fix, docs, style, refactor, test, chore
- Subject: imperative mood, max 50 chars, no period
- Body: Explain motivation and contrast with previous behavior
- Footer: Reference issues (Fixes #123) and breaking changes
Example output:
feat(auth): add OAuth2 support for Google Sign-In
Implement Google OAuth2 flow using Passport.js strategy.
Adds new /auth/google endpoints and user profile linking.
- Install passport-google-oauth20 package
- Create GoogleStrategy configuration
- Add user.googleId field to schema
- Implement callback route with JWT generation
Closes #456
BREAKING CHANGE: Requires GOOGLE_CLIENT_ID env var
4. PR DESCRIPTION GENERATION
Create a comprehensive PR description:
## Summary
[One-paragraph overview of changes]
## Changes Made
- [Specific change 1 with file path]
- [Specific change 2 with file path]
- [Specific change 3 with file path]
## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests pass
- [ ] Manual testing performed
- [ ] Edge cases considered
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Comments added for complex logic
- [ ] Documentation updated
## Breaking Changes
[List any breaking changes or "None"]
## Related Issues
Fixes #[issue number]
Relates to #[issue number]
5. EXECUTION SUMMARY
Present a clear action plan:
- Show which files will be committed
- Display the generated commit message
- Show the PR description preview
- Ask for confirmation before executing
- Offer to modify any section
Guidelines:
- Be conservative with auto-fixes; ask for complex changes
- Ensure commit messages are professional and informative
- Flag any security implications for human review
- Never commit secrets, .env files, or sensitive data
Step 3: Configure Your Environment
Create a .claude-workflow file in your project root:
{
"pr_automation": {
"test_command": "npm test",
"lint_command": "npm run lint",
"build_command": "npm run build",
"commit_convention": "conventional",
"auto_fix": true,
"require_tests": true,
"min_coverage": 80
}
}
Step 4: Create an Alias for Quick Access
Add to your shell profile (.zshrc, .bashrc):
alias pr-ready="claude 'Run the Git PR Automation protocol'"
Or create a script ~/bin/pr-ready:
#!/bin/bash
claude "Run the Git PR Automation protocol on these changes: $(git diff --stat)"
Real-World Use Cases
Case Study 1: Alex, Senior Frontend Developer
Before: Alex would spend 20-30 minutes per PR writing descriptions, checking if tests passed, and fixing linting errors discovered by CI. Reviewers often requested changes due to missing context.
After: The automation handles everything:
- Linting and formatting fixed automatically
- Tests run locally before PR creation
- PR description includes screenshots and testing notes
- Commit messages reference related tickets automatically
Result: "I went from 3-4 PR review cycles to 1-2. My team lead mentioned my PRs are now the easiest to review because everything is documented upfront."
Case Study 2: The Platform Team at TechCorp
Before: The team of 8 engineers struggled with inconsistent commit messages and PR descriptions. Code reviews were slow because reviewers lacked context.
After: Standardized automation across all repos:
- Every commit follows Conventional Commits
- PR descriptions follow a consistent template
- Automated checks catch 90% of issues before human review
- Changelog generation is now automated from commit history
Result: Code review time dropped by 40%. The team shipped 25% more features in the following quarter because less time was spent on review overhead.
Case Study 3: Maya, Open Source Maintainer
Before: Maya maintained a popular npm package with 50+ contributors. Reviewing external PRs was time-consuming due to missing descriptions and failing checks.
After: Contributors use the workflow before submitting:
- PR template auto-populated with change details
- Contributors fix linting issues before submission
- Breaking changes are clearly flagged
- Commit history is clean and readable
Result: "External PRs are now reviewable in 5 minutes instead of 20. The quality of contributions has improved because the workflow educates contributors about our standards."
Advanced Customization
Multi-Language Support
Configure for polyglot projects:
For this monorepo with Node.js and Python:
1. Run checks in both directories:
- /frontend: npm run lint && npm test
- /backend: flake8 && pytest
- /shared: type-check both TS and Python interfaces
2. Generate separate commit messages if needed:
- feat(frontend): ...
- fix(backend): ...
3. Include language-specific details in PR description
Integration with CI/CD
Enhance your GitHub Actions workflow:
name: PR Automation
on: [pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Claude PR Checks
run: |
claude "Verify this PR follows our standards: $(git diff)"
Custom Commit Types
For specialized workflows:
Additional commit types for our team:
- perf: Performance improvements
- security: Security fixes
- deps: Dependency updates
- i18n: Internationalization
- a11y: Accessibility improvements
Automated PR Creation
For fully automated submission:
# Create a script that combines everything
#!/bin/bash
BRANCH=$(git branch --show-current)
git add .
claude "Generate commit and push to origin/$BRANCH"
gh pr create --title "$(claude 'Generate PR title')" \
--body "$(claude 'Generate PR description')"
Frequently Asked Questions
Q: Will this overwrite my carefully written commit messages?
A: No. The workflow presents suggestions and asks for confirmation. You can edit, accept, or reject any generated content. Over time, you might find the AI suggestions match your style and save time.
Q: What if the tests are flaky and fail randomly?
A: Configure retry logic in your prompt: "Run tests up to 3 times. If they fail consistently, report the failure. If they pass on retry, note the flakiness but proceed." You can also maintain a list of known flaky tests to handle separately.
Q: Can this work with GitLab, Bitbucket, or other platforms?
A: Yes. The core workflow is platform-agnostic. For platform-specific features (like PR creation), use the respective CLI tools (glab for GitLab, bb for Bitbucket) in your automation scripts.
Q: How do I handle large PRs with hundreds of files?
A: Add guidance to your prompt: "For PRs with >20 files, generate a high-level summary grouped by component rather than listing every file. Flag that this is a large PR and suggest breaking it down if appropriate."
Q: Will this work with private repositories and sensitive code?
A: Yes. Claude Cowork processes everything locally. Your code never leaves your machine unless you explicitly use cloud-based tools. For maximum security, disable any cloud-based MCP servers when working with sensitive repositories.
Pro Tips for Maximum Impact
-
Start with Commit Messages: If full automation feels risky, begin with just auto-generating commit messages. Expand to full PR automation once comfortable.
-
Team Standards: Document your team's preferences in the prompt. Include examples of good commit messages and PR descriptions from your repository.
-
Review the Reviewer: Periodically ask Claude to review your PR description from a reviewer's perspective: "Would this give me enough context to review effectively?"
-
Learn from History: Analyze your recent merged PRs: "What information do reviewers typically ask for? Include that in the template by default."
-
Iterate on the Template: Your first prompt won't be perfect. Refine it based on what works and what doesn't. Add new checks as your codebase evolves.
Ready to ship better code faster? Set up Git PR Automation today and transform your development workflow from tedious to delightful.