Final fix for stats cards: robust data fetching and complete features#9
Merged
Merged
Conversation
Owner
Chintanpatel24
commented
May 14, 2026
- Resolved Issue Enhancement for the PR card #3: Enhanced PR summary card layout (Merged, Total, Open).
- Resolved Issue A new card is wanted for the gitlyy !! #4: Implemented Issue card with requested layout (Open, Total, Closed) and red accent.
- Resolved Issue mastercard SVG #5: Fully implemented Mastercard (Dashboard) with aggregated stats.
- Resolved Issue [issue]: Workflow run fails. #6: Added Node.js CI workflow and package-lock.json.
- Robustness: Refactored src/github.js with safeFetch, timeouts, and better error handling to prevent broken images.
- Documentation: Updated README.md and public/index.html with new cards and examples.
- Corrected totalCommits handling in Mastercard.
- Resolved Issue #3: Enhanced PR summary card layout (Merged, Total, Open). - Resolved Issue #4: Implemented Issue card with requested layout (Open, Total, Closed) and red accent. - Resolved Issue #5: Fully implemented Mastercard (Dashboard) with aggregated stats. - Resolved Issue #6: Added Node.js CI workflow and package-lock.json. - Robustness: Refactored src/github.js with safeFetch, timeouts, and better error handling to prevent broken images. - Documentation: Updated README.md and public/index.html with new cards and examples. - Corrected totalCommits handling in Mastercard. Co-authored-by: Chintanpatel24 <216989679+Chintanpatel24@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors GitHub data-fetching helpers to make the stats-card APIs more resilient and to support PR, issue, overview, language, streak, and master-card metrics.
Changes:
- Adds a shared
safeFetchwrapper with timeout/error handling. - Updates PR, issue, profile, commit, star, and language fetchers to use safer fallbacks.
- Adjusts pagination and aggregation behavior for PRs, repositories, and languages.
Comments suppressed due to low confidence (2)
src/github.js:264
- Capping repository pagination at five pages silently ignores repositories after the first 500.
fetchUserTotalStarsis used for the overview card's total stars, so users with more than 500 owned repositories will get an undercounted total.
while (page <= 5) {
const url = `${GITHUB_API}/users/${encodeURIComponent(username)}/repos?type=owner&per_page=100&page=${page}`;
const data = await safeFetch(url);
if (!data || !Array.isArray(data) || data.length === 0) break;
src/github.js:400
- The activity-by-language calculation only fetches language data for the first 20 eligible repositories on each page, excluding the remaining repos from
totalActivityand percentages. This makes themode=commitslanguage card materially inaccurate for users with many repositories.
const promises = repos
.filter((r) => !r.fork && r.size > 0)
.slice(0, 20)
.map(async (repo) => {
const langs = await safeFetch(repo.languages_url);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
27
to
+29
| if (!res.ok) { | ||
| throw new Error(`GitHub API error: ${res.status} ${res.statusText}`); | ||
| console.warn(`GitHub API warning: ${res.status} for ${url}`); | ||
| return null; |
Comment on lines
+47
to
+53
| while (page <= 5) { | ||
| const url = `${GITHUB_API}/search/issues?q=author:${encodeURIComponent(username)}+type:pr&per_page=${perPage}&page=${page}`; | ||
| const data = await safeFetch(url); | ||
| if (!data || !data.items || data.items.length === 0) break; | ||
|
|
||
| allPRs = allPRs.concat(data.items); | ||
| if (allPRs.length >= data.total_count || data.items.length < perPage) break; |
Comment on lines
+132
to
+137
| const res = await fetch(url, { | ||
| headers: { | ||
| "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", | ||
| Accept: "text/html", | ||
| }, | ||
| }); |
| const promises = repos | ||
| .filter((r) => !r.fork && r.size > 0) | ||
| .slice(0, 30) // limit to 30 repos to avoid rate limits | ||
| .slice(0, 20) |
| if (!res.ok) break; | ||
| const repos = await res.json(); | ||
| if (!repos.length) break; | ||
| while (page <= 3) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.