UNPKG

@claude-powers/slash-commands

Version:

πŸš€ Claude Powers - Essential slash commands for Claude Code

389 lines (317 loc) β€’ 10.4 kB
# Auto Commit Command Generates automatic commits with intelligent descriptions based on detected changes in the project. ## Description The `/auto-commit` command analyzes pending changes in the Git repository and automatically generates: - **Descriptive commit messages** following standard conventions - **Impact analysis** of changes made - **Automatic categorization** of change type (feat, fix, docs, etc.) - **Detection of breaking changes** and important changes - **Validation** before commit to prevent errors - **Improvement suggestions** in the generated message ## Usage ``` /auto-commit [--type] [--scope] [--message] [--validate] [--format] ``` ### Parameters - `--type`: Force a specific type (feat, fix, docs, style, refactor, test, chore) - `--scope`: Specify the scope of the change (component, module, etc.) - `--message`: Add additional custom message - `--validate`: Run validations before commit (lint, tests, build) - `--format`: Commit format (conventional, angular, simple) - `--interactive`: Interactive mode to review before committing - `--dry-run`: Show the generated message without committing ### Examples ``` /auto-commit /auto-commit --type=feat --scope=authentication /auto-commit --message="implement social login" --validate=true /auto-commit --format=conventional --interactive /auto-commit --dry-run /auto-commit --type=fix --validate=lint,test ``` ## Automatic Change Analysis ### Change Type Detection #### πŸš€ feat (New features) - New files added - New functions or methods - New React components - New routes or endpoints - New main dependencies #### πŸ› fix (Bug fixes) - Changes in conditionals or logic - Typo corrections - Improved error handling - CSS or style fixes - Import corrections #### πŸ“š docs (Documentation) - Changes in .md files - Comment updates - README modified - JSDoc changes #### πŸ’„ style (Formatting/style) - Format-only changes - Linting adjustments - Whitespace - Import organization #### ♻️ refactor (Refactoring) - Code reorganization - Function extraction - Name changes - Optimizations without functional change #### βœ… test (Tests) - .test.* or .spec.* files - __tests__ folders - Testing configuration #### πŸ”§ chore (Maintenance tasks) - package.json modified - Build configuration - Automation scripts - .gitignore updated ### Scope Detection ```javascript // Automatically detects scope based on: src/components/auth/ β†’ scope: "auth" src/pages/dashboard/ β†’ scope: "dashboard" backend/api/users/ β†’ scope: "users-api" styles/theme/ β†’ scope: "theme" docs/setup/ β†’ scope: "docs" ``` ### Impact Analysis - **Breaking Changes**: Changes in public APIs, function removal - **Major**: Important new features, large refactors - **Minor**: Minor new features, improvements - **Patch**: Bug fixes, documentation, style ## Configuration The command uses `.claude/auto-commit-config.json`: ```json { "format": "conventional", "validation": { "runLint": true, "runTests": false, "checkBuild": false, "maxFileChanges": 50 }, "templates": { "feat": "{type}({scope}): {description}\\n\\n{details}\\n\\n{footer}", "fix": "{type}({scope}): {description}\\n\\n{details}\\n\\n{footer}", "docs": "{type}({scope}): {description}", "style": "{type}: {description}", "refactor": "{type}({scope}): {description}\\n\\n{details}", "test": "{type}({scope}): {description}", "chore": "{type}: {description}" }, "scopes": { "autoDetect": true, "predefined": [ "auth", "api", "ui", "components", "utils", "config", "docs", "tests" ] }, "rules": { "maxSubjectLength": 100, "bodyWrap": 72, "requireBody": ["feat", "fix", "refactor"], "requireBreakingChange": true, "requireTicketNumber": false }, "ai": { "useIntelligentDescriptions": true, "contextAnalysis": true, "suggestImprovements": true, "detectBreakingChanges": true } } ``` ## Command Output ### Change Analysis ``` πŸ€– CLAUDE POWER - AUTO COMMIT ANALYSIS ====================================== πŸ“Š DETECTED CHANGES: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Type β”‚ filesβ”‚ Lines β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Modified β”‚ 8 β”‚ +156 -42 β”‚ β”‚ New β”‚ 3 β”‚ +203 β”‚ β”‚ Deleted β”‚ 1 β”‚ -67 β”‚ β”‚ Renamed β”‚ 2 β”‚ ~ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ πŸ” INTELLIGENT ANALYSIS: πŸ“ src/components/auth/ ✨ [FEAT] LoginForm.tsx - New login component ✨ [FEAT] AuthContext.tsx - Auth context πŸ“ src/pages/ πŸ› [FIX] dashboard.tsx - Fix navigation error πŸ“ docs/ πŸ“š [DOCS] README.md - Update installation guide 🎯 DETECTED TYPE: feat 🏷️ SUGGESTED SCOPE: auth ⚑ IMPACT: Minor (new functionality) ``` ### Generated Message ``` πŸ’¬ GENERATED COMMIT MESSAGE: ===================================== feat(auth): implement authentication system with social login - Add LoginForm component with validation - Implement AuthContext for state management - Fix navigation in dashboard after login - Update setup documentation Allows users to authenticate using: - Traditional email/password - Login with Google OAuth - Login with GitHub OAuth Breaking changes: None Closes: #123, #124 ``` ### Pre-commit Validations ``` πŸ” PRE-COMMIT VALIDATIONS: ========================== βœ… ESLint: 0 errors, 2 warnings βœ… Prettier: Correct format βœ… TypeScript: Successful compilation ⚠️ Tests: 2 pending tests for new components βœ… Build: Successful generation βœ… File size: Within limits 🚦 RESULT: βœ… READY TO COMMIT ``` ### Interactive Options ``` πŸ“ PROCEED WITH COMMIT? Proposed message: > feat(auth): implement authentication system with social login Options: [Y] Yes, commit [E] Edit message [A] Add details [C] Change type/scope [V] View full diff [N] Cancel Choice: ``` ## Advanced Integrations ### Webhooks and Notifications ```json { "integrations": { "slack": { "enabled": true, "webhook": "https://hooks.slack.com/...", "channel": "#dev-commits" }, "jira": { "enabled": true, "autoLink": true, "transitionTickets": false }, "github": { "autoLabel": true, "linkIssues": true, "assignReviewers": true } } } ``` ### Custom Templates ```json { "customTemplates": { "hotfix": "hotfix: {description}\\n\\nUrgent fix for: {issue}\\n\\nTested: {testDetails}", "release": "release: version {version}\\n\\n{changelogSummary}\\n\\nBreaking Changes:\\n{breakingChanges}", "security": "security: {description}\\n\\n⚠️ Security fix\\n\\nCVE: {cve}\\nSeverity: {severity}" } } ``` ## Special Use Cases ### Merge/Release Commits ```bash # Auto-generate message for merge /auto-commit --type=merge --message="feat/user-dashboard into main" # Release commit with automatic changelog /auto-commit --type=release --message="v2.1.0" --changelog=true # Urgent hotfix /auto-commit --type=hotfix --validate=minimal --priority=high ``` ### Multiple Contexts ```bash # Commit for specific feature /auto-commit --scope=dashboard --context=feature/user-dashboard # Cross-platform commit /auto-commit --platform=web,mobile --sync=true # Commit with dependencies /auto-commit --dependencies=updated --security-check=true ``` ### AI Contextual Analysis ``` 🧠 AI CONTEXTUAL ANALYSIS: ========================= πŸ“ˆ DETECTED PATTERNS: β€’ This commit continues the work on authentication started 3 commits ago β€’ Component-driven development pattern detected β€’ Code follows established project conventions πŸ’‘ SUGGESTIONS: β€’ Consider adding tests for LoginForm.tsx β€’ Change in AuthContext may affect other components β€’ Document new OAuth providers in wiki 🎯 COMMIT QUALITY: β€’ Message: 9/10 (clear and descriptive) β€’ Scope: 10/10 (well defined) β€’ Impact: 8/10 (important change well documented) ``` ## Automation and CI/CD ### GitHub Actions ```yaml name: Auto Commit Quality Check on: push: branches: [feature/*, develop] jobs: commit-quality: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Validate commit message run: | COMMIT_MSG=$(git log -1 --pretty=%B) npx claude-power validate-commit "$COMMIT_MSG" - name: Analyze commit quality run: | npx claude-power analyze-commit --output=json > commit-analysis.json - name: Comment on PR if quality issues if: github.event_name == 'pull_request' uses: actions/github-script@v6 with: script: | const fs = require('fs'); const analysis = JSON.parse(fs.readFileSync('commit-analysis.json')); if (analysis.score < 8) { github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: `## πŸ“ Commit Quality Analysis\n\nScore: ${analysis.score}/10\n\n${analysis.suggestions.join('\n')}` }); } ``` ### Pre-commit Hook Integration ```bash #!/bin/sh # .git/hooks/prepare-commit-msg # If no message or very basic, generate an automatic one if [ -z "$2" ] || [ "$2" = "message" ]; then echo "πŸ€– Generating intelligent commit message..." AUTO_MSG=$(npx claude-power auto-commit --dry-run --format=conventional) echo "$AUTO_MSG" > "$1" echo "βœ… Message generated. Edit if necessary." fi ``` --- *Part of the **Claude Power** ecosystem - Automate your workflow with AI* πŸš€