Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 72 additions & 80 deletions plugins/sentry-skills/skills/iterate-pr/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,133 +7,125 @@ description: Iterate on a PR until CI passes. Use when you need to fix CI failur

Continuously iterate on the current branch until all CI checks pass and review feedback is addressed.

**Requires**: GitHub CLI (`gh`) authenticated and available.
**Requires**: GitHub CLI (`gh`) authenticated.

## Process
## Bundled Scripts

### Step 1: Identify the PR
### `scripts/fetch_pr_checks.py`

Fetches CI check status and extracts failure snippets from logs.

```bash
gh pr view --json number,url,headRefName,baseRefName
python scripts/fetch_pr_checks.py [--pr NUMBER]
```

If no PR exists for the current branch, stop and inform the user.
Returns JSON:
```json
{
"pr": {"number": 123, "branch": "feat/foo"},
"summary": {"total": 5, "passed": 3, "failed": 2, "pending": 0},
"checks": [
{"name": "tests", "status": "fail", "log_snippet": "...", "run_id": 123},
{"name": "lint", "status": "pass"}
]
}
```

### Step 2: Check CI Status First
### `scripts/fetch_pr_feedback.py`

Always check CI/GitHub Actions status before looking at review feedback:
Fetches and categorizes PR review feedback using the [LOGAF scale](https://develop.sentry.dev/engineering-practices/code-review/#logaf-scale).

```bash
gh pr checks --json name,state,bucket,link,workflow
python scripts/fetch_pr_feedback.py [--pr NUMBER]
```

The `bucket` field categorizes state into: `pass`, `fail`, `pending`, `skipping`, or `cancel`.

**Important:** If any of these checks are still `pending`, wait before proceeding:
- `sentry` / `sentry-io`
- `codecov`
- `cursor` / `bugbot` / `seer`
- Any linter or code analysis checks
Returns JSON with feedback categorized as:
- `high` - Must address before merge (`h:`, blocker, changes requested)
- `medium` - Should address (`m:`, standard feedback)
- `low` - Optional (`l:`, nit, style, suggestion)
- `bot` - Automated comments (Codecov, Sentry, etc.)
- `resolved` - Already resolved threads

These bots may post additional feedback comments once their checks complete. Waiting avoids duplicate work.
## Workflow

### Step 3: Gather Review Feedback
### 1. Identify PR

Once CI checks have completed (or at least the bot-related checks), gather human and bot feedback:

**Review Comments and Status:**
```bash
gh pr view --json reviews,comments,reviewDecision
gh pr view --json number,url,headRefName
```

**Inline Code Review Comments:**
```bash
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments
```
Stop if no PR exists for the current branch.

**PR Conversation Comments (includes bot comments):**
```bash
gh api repos/{owner}/{repo}/issues/{pr_number}/comments
```
### 2. Check CI Status

Look for bot comments from: Sentry, Codecov, Cursor, Bugbot, Seer, and other automated tools.
Run `scripts/fetch_pr_checks.py` to get structured failure data.

### Step 4: Investigate Failures
**Wait if pending:** If bot-related checks (sentry, codecov, cursor, bugbot, seer) are still running, wait before proceeding—they may post additional feedback.

For each CI failure, get the actual logs:
### 3. Fix CI Failures

```bash
# List recent runs for this branch
gh run list --branch $(git branch --show-current) --limit 5 --json databaseId,name,status,conclusion
For each failure in the script output:
1. Read the `log_snippet` to understand the failure
2. Read the relevant code before making changes
3. Fix the issue with minimal, targeted changes

# View failed logs for a specific run
gh run view <run-id> --log-failed
```

Do NOT assume what failed based on the check name alone. Always read the actual logs.
Do NOT assume what failed based on check name alone—always read the logs.

### Step 5: Validate Feedback
### 4. Gather Review Feedback

For each piece of feedback (CI failure or review comment):
Run `scripts/fetch_pr_feedback.py` to get categorized feedback.

1. **Read the relevant code** - Understand the context before making changes
2. **Verify the issue is real** - Not all feedback is correct; reviewers and bots can be wrong
3. **Check if already addressed** - The issue may have been fixed in a subsequent commit
4. **Skip invalid feedback** - If the concern is not legitimate, move on
### 5. Handle Feedback by LOGAF Priority

### Step 6: Address Valid Issues
**Auto-fix (no prompt):**
- `high` - must address (blockers, security, changes requested)
- `medium` - should address (standard feedback)

Make minimal, targeted code changes. Only fix what is actually broken.
**Prompt user for selection:**
- `low` - present numbered list and ask which to address:

### Step 7: Commit and Push
```
Found 3 low-priority suggestions:
1. [l] "Consider renaming this variable" - @reviewer in api.py:42
2. [nit] "Could use a list comprehension" - @reviewer in utils.py:18
3. [style] "Add a docstring" - @reviewer in models.py:55

```bash
git add -A
git commit -m "fix: <descriptive message of what was fixed>"
git push origin $(git branch --show-current)
Which would you like to address? (e.g., "1,3" or "all" or "none")
```

### Step 8: Wait for CI
**Skip silently:**
- `resolved` threads
- `bot` comments (informational only)

Use the built-in watch functionality:
### 6. Commit and Push

```bash
gh pr checks --watch --interval 30
git add <files>
git commit -m "fix: <descriptive message>"
git push
```

This waits until all checks complete. Exit code 0 means all passed, exit code 1 means failures.

Alternatively, poll manually if you need more control:
### 7. Wait for CI

```bash
gh pr checks --json name,state,bucket | jq '.[] | select(.bucket != "pass")'
gh pr checks --watch --interval 30
```

### Step 9: Repeat

Return to Step 2 if:
- Any CI checks failed
- New review feedback appeared
### 8. Repeat

Continue until all checks pass and no unaddressed feedback remains.
Return to step 2 if CI failed or new feedback appeared.

## Exit Conditions

**Success:**
- All CI checks are green (`bucket: pass`)
- No unaddressed human review feedback
**Success:** All checks pass, no unaddressed high/medium feedback, user has decided on low-priority items.

**Ask for Help:**
- Same failure persists after 3 attempts (likely a flaky test or deeper issue)
- Review feedback requires clarification or decision from the user
- CI failure is unrelated to branch changes (infrastructure issue)
**Ask for help:** Same failure after 3 attempts, feedback needs clarification, infrastructure issues.

**Stop Immediately:**
- No PR exists for the current branch
- Branch is out of sync and needs rebase (inform user)
**Stop:** No PR exists, branch needs rebase.

## Tips
## Fallback

- Use `gh pr checks --required` to focus only on required checks
- Use `gh run view <run-id> --verbose` to see all job steps, not just failures
- If a check is from an external service, the `link` field in checks JSON provides the URL to investigate
If scripts fail, use `gh` CLI directly:
- `gh pr checks --json name,state,bucket,link`
- `gh run view <run-id> --log-failed`
- `gh api repos/{owner}/{repo}/pulls/{number}/comments`
Loading