AOSSIE-Org / AOSSIE-Org/OrgExplorer

[BUG]: fetchContributors, fetchIssues, and fetchPulls crash with "TypeError: data is not iterable" when GitHub API returns non-array objects

未關閉 適合新手
#225 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug
主要語言
JavaScript
星號
34
分支
92
平均合併
8 天 7 小時
30 天內合併 PR
12

描述

### Bug Description
In `src/services/github.js`, `fetchContributors()`, `fetchIssues()`, and `fetchPulls()` spread the response from `fetchWithCache()` directly into an array using `all.push(...data)`.

However, several GitHub API endpoints return non-array JSON objects or 204 No Content responses under valid conditions:
- Querying issues for repositories where issues are disabled returns `{ "message": "Issues are disabled in this repository" }`.
- Querying contributors for empty repositories returns `{ "message": "Git Repository is empty." }` or HTTP 204 No Content.
- Querying restricted repositories returns warning/error payload objects.

When `data` is a non-array object, `all.push(...data)` throws an uncaught JavaScript error:
`TypeError: data is not iterable` (or `SyntaxError: Unexpected end of JSON input`), causing the data fetching pipeline to crash and stall.

### Where the Bug Occurs
- `src/services/github.js` (lines 55-83): `fetchWithCache` attempts `res.json()` on 204 No Content responses without checking status.
- `src/services/github.js` (lines 101-135): `fetchContributors()`, `fetchIssues()`, and `fetchPulls()` execute `all.push(...data)` without validating `Array.isArray(data)`.

### Expected Behavior
1. `fetchWithCache()` should handle 204 No Content responses gracefully (e.g. returning `[]`).
2. `fetchContributors()`, `fetchIssues()`, and `fetchPulls()` should check `if (Array.isArray(data))` before spreading into `all.push(...data)`, and break gracefully if `data` is not an array.

### Steps to Reproduce
1. Run `explore()` on an organization that has repositories with disabled issues or empty repositories.
2. Observe the browser console.
3. The fetch pipeline encounters `TypeError: data is not iterable` and fails to complete analytics aggregation.

### Note
Please do not post AI-generated spam or generic template comments on this issue.

### Logs and Screenshots

_No response_

### Environment Details

_No response_

### Impact

High - Major feature is broken

### Code of Conduct

- [x] I have joined the [Discord server](https://discord.gg/hjUhu33uAn) and will post updates there
- [x] I have searched existing issues to avoid duplicates
- [x] I am ready to submit a pr for this issue

貢獻指南

開啟貢獻指南

研究方向

Start in src/services/github.js, reviewing fetchWithCache() around lines 55-83 and the fetchContributors(), fetchIssues(), and fetchPulls() pagination logic around lines 101-135. Reproduce the issue with disabled-issue, empty, restricted, or 204-response repositories, then verify the pipeline completes without JSON or iterable errors and returns empty results where appropriate.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
github, javascript
領域
api, backend
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
活躍
描述清晰度
描述清楚
新手友好度
78/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。