|
| 1 | +# Implementation Notes: `sentry-cli review` Command |
| 2 | + |
| 3 | +This document captures implementation details, edge cases, and notes for the `sentry-cli review` PoC. |
| 4 | + |
| 5 | +## Current Implementation |
| 6 | + |
| 7 | +The `review` command sends the diff of the most recent commit (HEAD vs HEAD~1) to Sentry's bug prediction API for AI-powered code review. |
| 8 | + |
| 9 | +### Endpoint |
| 10 | + |
| 11 | +`POST /api/0/bug-prediction/cli/` |
| 12 | + |
| 13 | +### Request Format |
| 14 | + |
| 15 | +```json |
| 16 | +{ |
| 17 | + "remote_url": "[email protected]:owner/repo.git", |
| 18 | + "base_commit_sha": "abc123...", |
| 19 | + "diff": "<unified diff output>" |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +### Response Format |
| 24 | + |
| 25 | +```json |
| 26 | +{ |
| 27 | + "predictions": [ |
| 28 | + { |
| 29 | + "file_path": "src/example.rs", |
| 30 | + "line_number": 42, |
| 31 | + "description": "Potential null pointer dereference", |
| 32 | + "severity": "high", |
| 33 | + "suggested_fix": "Add null check before accessing" |
| 34 | + } |
| 35 | + ] |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +## Edge Cases |
| 40 | + |
| 41 | +### Handled (with errors) |
| 42 | + |
| 43 | +| Edge Case | Behavior | |
| 44 | +|-----------|----------| |
| 45 | +| Initial commit (no parent) | Error: "HEAD has no parent commit - cannot review initial commit" | |
| 46 | +| Merge commits | Error: "HEAD is a merge commit. Merge commits are not supported for review." | |
| 47 | +| Large diffs (>500KB) | Error with size details | |
| 48 | +| No remote configured | Error: "No remote URL found for 'origin' or 'upstream'" | |
| 49 | +| Empty diff | Error: "No changes found between HEAD and HEAD~1" | |
| 50 | +| Not in a git repository | Error: "Failed to open git repository from current directory" | |
| 51 | + |
| 52 | +### Handled (silently) |
| 53 | + |
| 54 | +| Edge Case | Behavior | |
| 55 | +|-----------|----------| |
| 56 | +| Binary files in diff | Skipped (not included in diff) | |
| 57 | + |
| 58 | +### Not Handled (future work) |
| 59 | + |
| 60 | +| Edge Case | Notes | |
| 61 | +|-----------|-------| |
| 62 | +| Detached HEAD state | Currently works (uses commit SHA) but could be more user-friendly | |
| 63 | +| Rate limiting | No retry logic or rate limit handling | |
| 64 | +| Network timeouts | Uses 10-minute timeout, no retry on failure | |
| 65 | +| Partial/interrupted response | No streaming support | |
| 66 | +| Multiple remotes | Currently only checks "origin" then "upstream" | |
| 67 | +| Shallow clones | May fail if parent commit is not available | |
| 68 | + |
| 69 | +## Configuration |
| 70 | + |
| 71 | +| Setting | Value | Notes | |
| 72 | +|---------|-------|-------| |
| 73 | +| Timeout | 10 minutes | API response expected to take a long time | |
| 74 | +| Max diff size | 500 KB | Per API spec | |
| 75 | + |
| 76 | +## API Changes |
| 77 | + |
| 78 | +Added `with_timeout()` method to `ApiRequest` in `src/api/mod.rs` to support long-running requests. |
| 79 | + |
| 80 | +## Future Considerations |
| 81 | + |
| 82 | +1. **Selecting commits to review**: Currently reviews HEAD vs HEAD~1. Future versions could allow specifying a commit range or reviewing uncommitted changes. |
| 83 | + |
| 84 | +2. **Output formats**: Currently outputs human-readable text. Future versions could support JSON output for machine consumption. |
| 85 | + |
| 86 | +3. **Integration with CI**: Could add options for failing the build based on severity of issues found. |
| 87 | + |
| 88 | +4. **Caching**: Could cache results for the same commit SHA to avoid redundant API calls. |
0 commit comments