You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix GitHub comment upload failure for large SQL linting reports (#605)
## Summary
This PR fixes issue #603 where Squawk fails to upload large linting reports to GitHub with a 422 "Unprocessable Entity" error.
## Problem
When performing linting on large SQL migrations (14,000+ lines across multiple files), Squawk generates GitHub comments that exceed the API's 65,536 character limit, causing upload failures.
## Solution
### 1. Size Limit Enforcement
- Added `GITHUB_COMMENT_MAX_SIZE` constant (65,000 chars) with safety margin
- Pre-check comment size before API calls to provide better error messages
### 2. Smart Comment Truncation
- Limit SQL preview to 50 lines per file with truncation notice
- Preserve all violation information while reducing content size
### 3. Summary Mode Fallback
- For very large reports, switch to summary mode that omits SQL content
- Display file statistics, line counts, and violation details
- Clear notice about content omission
### 4. Enhanced Error Handling
- New `CommentTooLarge` error variant with descriptive messages
- Better user feedback when size limits are exceeded
## Changes Made
- **`crates/squawk/src/github.rs`**: Main comment generation logic with size checking and fallback modes
- **`crates/squawk_github/src/app.rs`**: Enhanced error handling for comment size limits
- **`crates/squawk_github/src/lib.rs`**: New error variant for size-related failures
## Testing
### Successful Tests
#### Normal comment generation (6 violations)
<img width="790" height="1090" alt="image" src="https://github.com/user-attachments/assets/54246721-3902-4f2b-898c-ce915f89d97d" />
Reference: #608 (comment)
#### SQL truncation (33 violations)
<img width="863" height="651" alt="image" src="https://github.com/user-attachments/assets/fd191aaa-deb4-4967-b213-0ffade69c98c" />
Reference: #608 (comment)
#### Multiple files handling
<img width="853" height="1003" alt="image" src="https://github.com/user-attachments/assets/356271a8-4754-4ae7-b57c-f0adc208ed64" />
Reference: #608 (comment)
#### Error handling for oversized content
```
Error: Upload to GitHub failed
Caused by:
Comment size error: Comment body is too large (1165116 characters). GitHub API limit is 65,536 characters.
```
Large File Tests:
- File: 60,000+ lines
- Violations: 30,003 issues
- Comment size: 1,165,116 characters (18x over limit)
- Error caught: 'Comment body is too large'
Analysis:
- The fix is working for normal use cases
- Error handling prevents GitHub API failures
- Summary mode logic may need adjustment for extreme cases
All existing tests continue to pass.
Fixes#603
let summary_notice = Some("⚠️ **Large Report**: This report was summarized due to size constraints. SQL content has been omitted but all violations were analyzed.");
0 commit comments