-
-
Notifications
You must be signed in to change notification settings - Fork 408
feat: add github stars, github issues & created at to comparison page (#2460) #2479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
t128n
wants to merge
18
commits into
npmx-dev:main
Choose a base branch
from
t128n:feat/compare
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
144e806
feat: add poc for github stars, github issues & created at comparison
t128n e4886a5
[autofix.ci] apply automated fixes
autofix-ci[bot] 8d2cff7
Merge branch 'main' into feat/compare
t128n 3a99631
refactor(compare): optimize github metadata fetching and repository p…
t128n 9c6f4d8
feat(compare): add scatter chart support and formatters for facets
t128n b517792
chore(i18n): update schema for facets
t128n 0127286
fix(compare): add missing cases for scatter chart
t128n 8434189
test(compare): add coverage for github metadata and created at facets
t128n 3865fc1
test(compare): update facet mock data to include github and creation …
t128n 2693e16
feat(compare): mirror contributors-evolution retry logic and timeout …
t128n 3e4fccd
fix(compare): rename facet i18n keys to camelCase for convention cons…
t128n 9df70fe
refactor(compare): return null for missing or malformed GitHub metrics
t128n f64fd04
fix(compare): remove unused formatter
t128n 85c59be
refactor: use shared fetch logic for github api
t128n 9cb87b1
chore: remove maxAttempts=3 as this is the default value
t128n e29ae1f
fix: remove type import from unlisted depndency
t128n 2adcf4a
fix: headers merge to support all NitroFetchOptions header types
t128n 96fdccf
Merge branch 'main' into feat/compare
t128n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { CACHE_MAX_AGE_ONE_HOUR } from '#shared/utils/constants' | ||
|
|
||
| interface GitHubSearchResponse { | ||
| total_count: number | ||
| } | ||
|
|
||
| export interface GithubIssueCountResponse { | ||
| owner: string | ||
| repo: string | ||
| issues: number | null | ||
| } | ||
|
|
||
| export default defineCachedEventHandler( | ||
| async (event): Promise<GithubIssueCountResponse> => { | ||
| const owner = getRouterParam(event, 'owner') | ||
| const repo = getRouterParam(event, 'repo') | ||
|
|
||
| if (!owner || !repo) { | ||
| throw createError({ | ||
| statusCode: 400, | ||
| statusMessage: 'Owner and repo are required parameters.', | ||
| }) | ||
| } | ||
|
|
||
| const query = `repo:${owner}/${repo} is:issue is:open` | ||
| const url = `https://api.github.com/search/issues?q=${encodeURIComponent(query)}&per_page=1` | ||
|
|
||
| try { | ||
| const data = await fetchGitHubWithRetries<GitHubSearchResponse>(url, { | ||
| timeout: 10000, | ||
| }) | ||
|
|
||
| return { | ||
| owner, | ||
| repo, | ||
| issues: typeof data?.total_count === 'number' ? data.total_count : null, | ||
| } | ||
| } catch { | ||
| throw createError({ | ||
| statusCode: 500, | ||
| statusMessage: 'Failed to fetch issue count from GitHub', | ||
| }) | ||
| } | ||
| }, | ||
| { | ||
| maxAge: CACHE_MAX_AGE_ONE_HOUR, | ||
| swr: true, | ||
| name: 'github-issue-count', | ||
| getKey: event => { | ||
| const owner = getRouterParam(event, 'owner') | ||
| const repo = getRouterParam(event, 'repo') | ||
| return `${owner}/${repo}` | ||
| }, | ||
| }, | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { setTimeout } from 'node:timers/promises' | ||
|
|
||
| export interface GitHubFetchOptions extends NonNullable<Parameters<typeof $fetch.raw>[1]> { | ||
| maxAttempts?: number | ||
| } | ||
|
|
||
| export async function fetchGitHubWithRetries<T>( | ||
| url: string, | ||
| options: GitHubFetchOptions = {}, | ||
| ): Promise<T | null> { | ||
| const { maxAttempts = 3, ...fetchOptions } = options | ||
| let delayMs = 1000 | ||
alexdln marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const defaultHeaders = { | ||
| 'Accept': 'application/vnd.github+json', | ||
| 'User-Agent': 'npmx', | ||
| 'X-GitHub-Api-Version': '2026-03-10', | ||
| } | ||
|
|
||
| for (let attempt = 0; attempt < maxAttempts; attempt += 1) { | ||
| try { | ||
| const headers = new Headers(defaultHeaders) | ||
| for (const [key, value] of new Headers(fetchOptions.headers)) { | ||
| headers.set(key, value) | ||
| } | ||
| const response = await $fetch.raw(url, { | ||
| ...fetchOptions, | ||
| headers, | ||
| }) | ||
|
|
||
| if (response.status === 200) { | ||
| return (response._data as T) ?? null | ||
| } | ||
|
|
||
| if (response.status === 204) { | ||
| return null | ||
| } | ||
|
|
||
| if (response.status === 202) { | ||
| if (attempt === maxAttempts - 1) break | ||
| await setTimeout(delayMs) | ||
| delayMs = Math.min(delayMs * 2, 16_000) | ||
| continue | ||
| } | ||
|
|
||
| break | ||
| } catch (error: unknown) { | ||
| if (attempt === maxAttempts - 1) { | ||
| throw error | ||
| } | ||
| await setTimeout(delayMs) | ||
| delayMs = Math.min(delayMs * 2, 16_000) | ||
| } | ||
| } | ||
|
|
||
| throw new Error(`Failed to fetch from GitHub after ${maxAttempts} attempts`) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 88
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 88
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 125
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 2684
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 6996
🏁 Script executed:
# Read the full implementation of fetchGitHubWithRetries head -100 server/utils/github.tsRepository: npmx-dev/npmx.dev
Length of output: 1485
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 941
Add an explicit timeout for the GitHub call.
The
fetchGitHubWithRetriesfunction supports timeout viaNitroFetchOptions. Line 30–32 configures 6 retry attempts but lacks a request timeout, leaving each attempt vulnerable to indefinite blocking. The same pattern is used elsewhere in the codebase withtimeout: 10000(seeserver/api/github/issues/[owner]/[repo].get.ts).Suggested fix
const data = await fetchGitHubWithRetries<GitHubContributorStats[]>(url, { maxAttempts: 6, + timeout: 10_000, })📝 Committable suggestion
🤖 Prompt for AI Agents