|
| 1 | +--- |
| 2 | +description: Git commit message formatting rules, for use when generating commit messages |
| 3 | +alwaysApply: false |
| 4 | +--- |
| 5 | +# Commit Message Formatting Rules |
| 6 | + |
| 7 | +**When to apply**: When generating commit messages or discussing commit practices |
| 8 | + |
| 9 | +**Description**: Rules for formatting commit messages with conventional commits and Jira issue integration |
| 10 | + |
| 11 | +## Commit Message Format |
| 12 | + |
| 13 | +Use conventional commits format: |
| 14 | + |
| 15 | +``` |
| 16 | +<type>(<scope>): <description> |
| 17 | + |
| 18 | +[optional body] |
| 19 | + |
| 20 | +Signed-off-by: <name> <email> |
| 21 | +Assisted-by: <model-name> (via Cursor) |
| 22 | +``` |
| 23 | + |
| 24 | +## Line Length Requirements |
| 25 | + |
| 26 | +Follow conventional commit line length standards: |
| 27 | + |
| 28 | +- **Subject line**: Maximum 50 characters (hard limit: 72 characters) |
| 29 | +- **Body**: Wrap at 72 characters per line |
| 30 | +- **Blank line**: Always include blank line between subject and body |
| 31 | +- **Footer**: Each footer on separate line |
| 32 | + |
| 33 | +## Scope Rules |
| 34 | + |
| 35 | +1. **For branches with Jira issues** (pattern: `SRVKP-XXX-description` or `OCP-XXX-description`): |
| 36 | + - Extract Jira issue number using regex: `[A-Z]{2,}-[0-9]+` |
| 37 | + - Use as scope: `feat(SRVKP-123): description` |
| 38 | + |
| 39 | +2. **For main/master branches or non-Jira branches**: |
| 40 | + - Ask user for Jira issue number |
| 41 | + - Look up issue on issues.redhat.com using web search |
| 42 | + - Use component name as fallback: `feat(webhook)`, `fix(controller)`, `docs(README)` |
| 43 | + |
| 44 | +## Commit Types |
| 45 | + |
| 46 | +- **feat**: New features |
| 47 | +- **fix**: Bug fixes |
| 48 | +- **docs**: Documentation changes |
| 49 | +- **style**: Code style changes |
| 50 | +- **refactor**: Code refactoring |
| 51 | +- **test**: Adding/updating tests |
| 52 | +- **chore**: Maintenance tasks |
| 53 | +- **build**: Build system or dependencies |
| 54 | +- **ci**: CI/CD changes |
| 55 | +- **perf**: Performance improvements |
| 56 | +- **revert**: Revert previous commit |
| 57 | + |
| 58 | +## Required Footers |
| 59 | + |
| 60 | +### Signed-off-by |
| 61 | + |
| 62 | +- Always include: `Signed-off-by: <name> <email>` |
| 63 | +- Get name and email using this priority order: |
| 64 | + 1. Environment variables: `$GIT_AUTHOR_NAME` and `$GIT_AUTHOR_EMAIL` |
| 65 | + 2. Git config: `git config user.name` and `git config user.email` |
| 66 | + 3. If neither configured, ask user to provide details |
| 67 | +- Common in dev containers: environment variables are preferred method |
| 68 | + |
| 69 | +### Assisted-by |
| 70 | + |
| 71 | +- Always include: `Assisted-by: <model-name> (via Cursor)` |
| 72 | +- Format examples: |
| 73 | + - `Assisted-by: Claude-3.5-Sonnet (via Cursor)` |
| 74 | + - `Assisted-by: Gemini (via Cursor)` |
| 75 | +- Use the actual model name being used for the commit message generation |
| 76 | + |
| 77 | +## Examples |
| 78 | + |
| 79 | +```bash |
| 80 | +feat(SRVKP-123): Add webhook controller for GitHub integration |
| 81 | + |
| 82 | +Signed-off-by: Developer Name <developer@redhat.com> |
| 83 | +Assisted-by: Claude-3.5-Sonnet (via Cursor) |
| 84 | +``` |
| 85 | + |
| 86 | +```bash |
| 87 | +fix(controller): Update pipeline reconciliation logic |
| 88 | + |
| 89 | +Resolves issue with concurrent pipeline runs |
| 90 | + |
| 91 | +Signed-off-by: Developer Name <developer@redhat.com> |
| 92 | +Assisted-by: Claude-3.5-Sonnet (via Cursor) |
| 93 | +``` |
| 94 | + |
| 95 | +## Auto-Detection Rules |
| 96 | + |
| 97 | +When generating commit messages: |
| 98 | + |
| 99 | +1. Check current branch name for Jira issue pattern |
| 100 | +2. If no Jira issue in branch, ask user for issue number |
| 101 | +3. Look up issue details on issues.redhat.com if provided |
| 102 | +4. Analyze staged files to determine commit type |
| 103 | +5. Generate appropriate scope and description |
| 104 | +6. Detect author info from environment variables ($GIT_AUTHOR_NAME, $GIT_AUTHOR_EMAIL) or git config |
| 105 | +7. Ensure subject line is ≤50 characters (max 72 characters) |
| 106 | +8. Wrap body text at 72 characters per line |
| 107 | +9. Add required footers (Signed-off-by and Assisted-by) |
| 108 | +10. Format according to conventional commits standard |
| 109 | + |
| 110 | +## Commit Process |
| 111 | + |
| 112 | +**IMPORTANT**: Always ask for user confirmation before executing `git commit`: |
| 113 | + |
| 114 | +1. **Generate** the commit message following the rules above |
| 115 | +2. **Display** the generated commit message to the user |
| 116 | +3. **Ask for confirmation**: "Should I commit with this message? (y/n)" |
| 117 | +4. **Wait for user response** before running `git commit` |
| 118 | +5. **Only commit** if user confirms with "yes", "y", or similar affirmative response |
| 119 | + |
| 120 | +**Example interaction:** |
| 121 | + |
| 122 | +``` |
| 123 | +Generated commit message: |
| 124 | +--- |
| 125 | +feat(SRVKP-456): ensure webhook logs output to stdout |
| 126 | + |
| 127 | +Configure webhook controller to direct all logs to stdout for container compatibility |
| 128 | + |
| 129 | +Signed-off-by: Developer Name <developer@redhat.com> |
| 130 | +Assisted-by: Claude-3.5-Sonnet (via Cursor) |
| 131 | +--- |
| 132 | + |
| 133 | +Should I commit with this message? (y/n) |
| 134 | +``` |
| 135 | + |
| 136 | +## Jira Issue Lookup Process |
| 137 | + |
| 138 | +When no Jira issue is found in branch name: |
| 139 | + |
| 140 | +1. Ask user: "What Jira issue number should I use for this commit?" |
| 141 | +2. If provided, search issues.redhat.com for issue details |
| 142 | +3. Use issue summary and description to enhance commit message |
| 143 | +4. Suggest creating a new branch if desired |
| 144 | + |
| 145 | +## Gitlint Integration |
| 146 | + |
| 147 | +- The project uses gitlint to enforce commit message format |
| 148 | +- Ensure all commit messages pass gitlint validation |
| 149 | +- Common gitlint rules to follow: |
| 150 | + - Conventional commit format |
| 151 | + - Proper line length limits |
| 152 | + - Required footers |
| 153 | + - No trailing whitespace |
0 commit comments