Fix GitHub API crashes on non-array responses (#225) - #227
Conversation
|
Warning Review limit reachedNext included review available in 54 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (1)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. WalkthroughThe paginated GitHub fetch functions now stop processing when ChangesGitHub pagination handling
Priority: ⬆️ High Estimated code review effort: 1 (Trivial) | ~3 minutes Change: Bug fix · Severity of issue fixed: High Merge Risk: ⚪ Minimal · up to GitHub pagination now returns collected valid items instead of crashing on non-array responses. The change is narrowly scoped and ready to merge. Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation The guards fix the reported TypeError for non-array responses in the pagination functions [ ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit checks each page with care Comment |
There was a problem hiding this comment.
🟡 Changes recommended
fetchWithCache() can still throw on 204 No Content (and can cache 202 placeholder payloads), so crashes/incorrect early termination can still occur before the new array guards run.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR aims to prevent OrgExplorer’s GitHub pagination helpers from crashing when the GitHub API returns a non-array JSON payload by guarding the spread merge operations.
Changes:
- Added
Array.isArrayguards beforeall.push(...data)infetchRepos,fetchContributors,fetchIssues, andfetchPulls. - Pagination loops now terminate safely when a non-array response is encountered, returning items collected so far.
File summaries
| File | Description |
|---|---|
| src/services/github.js | Adds array-type guards in pagination loops to avoid TypeError: data is not iterable when API payloads aren’t arrays. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const url = `https://api.github.com/orgs/${org}/repos?per_page=100&page=${page}&sort=updated` | ||
| const data = await fetchWithCache(url, pat) | ||
| if (!Array.isArray(data)) break | ||
| all.push(...data) |
Link your account with GitcordThanks for opening this PR, @dhruvv16-hash! To receive Discord notifications and contributor tracking for this organization:
Once linked, Gitcord can notify you about reviews, merges, and more. — Posted by Gitcord |
Hey everyone! 👋
The Problem:
In
src/services/github.js, paginated results are merged using the spread operator (all.push(...data)). When the GitHub API returns a non-array response (such as an error object, or a 202 Accepted status object, or an empty repository payload), the spread syntax throws aTypeError: data is not iterable, crashing the application.The Fix:
I added a
if (!Array.isArray(data)) break;guard inside the pagination loops forfetchRepos,fetchContributors,fetchIssues, andfetchPulls. Now, if a non-array response is received, the loop safely terminates and returns the valid array of items collected so far, preventing any crashes.Fixes #225
Summary by CodeRabbit