|
| 1 | +--- |
| 2 | +name: "bugfix" |
| 3 | +description: "Automatically fix GitHub issues labeled as 'bug'. Fetches bug issues, analyzes them, implements fixes, and creates PRs against the main branch." |
| 4 | +--- |
| 5 | + |
| 6 | +# Bug Fix Automation |
| 7 | + |
| 8 | +## What This Skill Does |
| 9 | + |
| 10 | +Automates the bug fixing workflow by: |
| 11 | +1. Fetching GitHub issues labeled as "bug" |
| 12 | +2. Analyzing the issue and understanding the problem |
| 13 | +3. Implementing the fix |
| 14 | +4. Running tests to verify the fix |
| 15 | +5. Creating a PR against the main branch |
| 16 | + |
| 17 | +## Quick Start |
| 18 | + |
| 19 | +When invoked, this skill will: |
| 20 | + |
| 21 | +1. **Fetch bug issues** from the current repository |
| 22 | +2. **Present issues** for selection (or work on the most recent one) |
| 23 | +3. **Analyze the bug** by reading related code |
| 24 | +4. **Implement the fix** with proper testing |
| 25 | +5. **Create a PR** with detailed description |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +## Step-by-Step Process |
| 30 | + |
| 31 | +### Step 1: Fetch Bug Issues |
| 32 | + |
| 33 | +```bash |
| 34 | +# List all open bug issues |
| 35 | +gh issue list --label "bug" --state open --json number,title,body,labels,createdAt --limit 20 |
| 36 | +``` |
| 37 | + |
| 38 | +### Step 2: Select and Analyze Issue |
| 39 | + |
| 40 | +For each bug issue, analyze: |
| 41 | +- Issue title and description |
| 42 | +- Steps to reproduce |
| 43 | +- Expected vs actual behavior |
| 44 | +- Related code files mentioned |
| 45 | +- Stack traces or error messages |
| 46 | + |
| 47 | +### Step 3: Create Fix Branch |
| 48 | + |
| 49 | +```bash |
| 50 | +# Create a branch for the fix |
| 51 | +git checkout -b fix/issue-<number>-<short-description> |
| 52 | +``` |
| 53 | + |
| 54 | +### Step 4: Implement the Fix |
| 55 | + |
| 56 | +1. Locate the relevant code files |
| 57 | +2. Understand the root cause |
| 58 | +3. Implement the minimal fix |
| 59 | +4. Add or update tests |
| 60 | +5. Run the test suite |
| 61 | + |
| 62 | +### Step 5: Create Pull Request |
| 63 | + |
| 64 | +```bash |
| 65 | +# Stage and commit changes |
| 66 | +git add -A |
| 67 | +git commit -m "fix: <description> (fixes #<issue-number>)" |
| 68 | + |
| 69 | +# Push and create PR |
| 70 | +git push -u origin fix/issue-<number>-<short-description> |
| 71 | + |
| 72 | +gh pr create \ |
| 73 | + --title "fix: <description>" \ |
| 74 | + --body "## Summary |
| 75 | +Fixes #<issue-number> |
| 76 | +
|
| 77 | +## Changes |
| 78 | +- <change 1> |
| 79 | +- <change 2> |
| 80 | +
|
| 81 | +## Testing |
| 82 | +- [ ] Unit tests pass |
| 83 | +- [ ] Manual testing completed |
| 84 | +
|
| 85 | +## Checklist |
| 86 | +- [ ] Code follows project style |
| 87 | +- [ ] Tests added/updated |
| 88 | +- [ ] Documentation updated if needed" |
| 89 | +``` |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## Execution Instructions |
| 94 | + |
| 95 | +When this skill is invoked, follow these steps: |
| 96 | + |
| 97 | +### 1. Get Repository Info |
| 98 | +```bash |
| 99 | +gh repo view --json owner,name,defaultBranchRef |
| 100 | +``` |
| 101 | + |
| 102 | +### 2. List Bug Issues |
| 103 | +```bash |
| 104 | +gh issue list --label "bug" --state open --json number,title,body,createdAt,url --limit 10 |
| 105 | +``` |
| 106 | + |
| 107 | +### 3. For Each Bug (or Selected Bug): |
| 108 | + |
| 109 | +**a) Read the issue details:** |
| 110 | +```bash |
| 111 | +gh issue view <number> --json title,body,comments |
| 112 | +``` |
| 113 | + |
| 114 | +**b) Create a fix branch:** |
| 115 | +```bash |
| 116 | +git checkout main |
| 117 | +git pull origin main |
| 118 | +git checkout -b fix/issue-<number>-<short-slug> |
| 119 | +``` |
| 120 | + |
| 121 | +**c) Analyze and implement:** |
| 122 | +- Search codebase for related files |
| 123 | +- Read the relevant code |
| 124 | +- Understand the bug |
| 125 | +- Implement the fix |
| 126 | +- Write/update tests |
| 127 | + |
| 128 | +**d) Verify the fix:** |
| 129 | +```bash |
| 130 | +# For Rust projects |
| 131 | +cargo test |
| 132 | +cargo clippy |
| 133 | + |
| 134 | +# For Node projects |
| 135 | +npm test |
| 136 | +npm run lint |
| 137 | +``` |
| 138 | + |
| 139 | +**e) Commit and push:** |
| 140 | +```bash |
| 141 | +git add -A |
| 142 | +git commit -m "fix: <description> |
| 143 | +
|
| 144 | +Fixes #<issue-number>" |
| 145 | +git push -u origin fix/issue-<number>-<short-slug> |
| 146 | +``` |
| 147 | + |
| 148 | +**f) Create the PR:** |
| 149 | +```bash |
| 150 | +gh pr create --base main --title "fix: <title>" --body "<body>" |
| 151 | +``` |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## Issue Selection |
| 156 | + |
| 157 | +If multiple bug issues exist, present them to the user: |
| 158 | + |
| 159 | +``` |
| 160 | +Found N open bug issues: |
| 161 | +
|
| 162 | +1. #123 - Login fails with special characters |
| 163 | + Created: 2 days ago |
| 164 | +
|
| 165 | +2. #118 - API returns 500 on empty request |
| 166 | + Created: 5 days ago |
| 167 | +
|
| 168 | +3. #115 - Memory leak in worker process |
| 169 | + Created: 1 week ago |
| 170 | +
|
| 171 | +Which issue would you like to work on? (Enter number or 'all' for batch mode) |
| 172 | +``` |
| 173 | + |
| 174 | +--- |
| 175 | + |
| 176 | +## PR Template |
| 177 | + |
| 178 | +Use this template for bug fix PRs: |
| 179 | + |
| 180 | +```markdown |
| 181 | +## Summary |
| 182 | + |
| 183 | +Fixes #<issue-number> |
| 184 | + |
| 185 | +## Problem |
| 186 | + |
| 187 | +<Brief description of the bug> |
| 188 | + |
| 189 | +## Solution |
| 190 | + |
| 191 | +<Description of the fix and why it works> |
| 192 | + |
| 193 | +## Changes |
| 194 | + |
| 195 | +- <File 1>: <What changed> |
| 196 | +- <File 2>: <What changed> |
| 197 | + |
| 198 | +## Testing |
| 199 | + |
| 200 | +- [ ] Existing tests pass |
| 201 | +- [ ] New tests added for the fix |
| 202 | +- [ ] Manually verified the fix |
| 203 | + |
| 204 | +## Screenshots/Logs |
| 205 | + |
| 206 | +<If applicable, add before/after screenshots or log output> |
| 207 | +``` |
| 208 | + |
| 209 | +--- |
| 210 | + |
| 211 | +## Best Practices |
| 212 | + |
| 213 | +1. **Minimal Changes**: Only fix the bug, don't refactor unrelated code |
| 214 | +2. **Add Tests**: Every bug fix should include a test that would have caught it |
| 215 | +3. **Link Issues**: Always reference the issue number in commits and PR |
| 216 | +4. **Verify First**: Run tests before creating the PR |
| 217 | +5. **Clear Description**: Explain the root cause and the fix |
| 218 | + |
| 219 | +--- |
| 220 | + |
| 221 | +## Troubleshooting |
| 222 | + |
| 223 | +### No bug issues found |
| 224 | +```bash |
| 225 | +# Check if label exists |
| 226 | +gh label list | grep -i bug |
| 227 | + |
| 228 | +# Create bug label if missing |
| 229 | +gh label create bug --color d73a4a --description "Something isn't working" |
| 230 | +``` |
| 231 | + |
| 232 | +### Authentication issues |
| 233 | +```bash |
| 234 | +# Check gh auth status |
| 235 | +gh auth status |
| 236 | + |
| 237 | +# Re-authenticate if needed |
| 238 | +gh auth login |
| 239 | +``` |
| 240 | + |
| 241 | +### Branch already exists |
| 242 | +```bash |
| 243 | +# Delete local branch and recreate |
| 244 | +git branch -D fix/issue-<number>-<slug> |
| 245 | +git checkout -b fix/issue-<number>-<slug> |
| 246 | +``` |
0 commit comments