-
-
Notifications
You must be signed in to change notification settings - Fork 424
feat: add github stars, issues and created at to comparison page #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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
19 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 5b37d61
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { setTimeout } from 'node:timers/promises' | ||
| import { CACHE_MAX_AGE_ONE_HOUR } from '#shared/utils/constants' | ||
|
|
||
| const GITHUB_HEADERS = { | ||
| 'Accept': 'application/vnd.github.v3+json', | ||
| 'User-Agent': 'npmx', | ||
| 'X-GitHub-Api-Version': '2022-11-28', | ||
|
alexdln marked this conversation as resolved.
Outdated
|
||
| } as const | ||
|
|
||
| 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` | ||
|
|
||
| const maxAttempts = 3 | ||
| let delayMs = 1000 | ||
|
|
||
| for (let attempt = 0; attempt < maxAttempts; attempt += 1) { | ||
| try { | ||
| const response = await $fetch.raw<GitHubSearchResponse>(url, { | ||
| headers: GITHUB_HEADERS, | ||
| timeout: 10000, | ||
| }) | ||
|
|
||
| if (response.status === 200) { | ||
| return { | ||
| owner, | ||
|
alexdln marked this conversation as resolved.
Outdated
|
||
| repo, | ||
| issues: | ||
| typeof response._data?.total_count === 'number' ? response._data.total_count : null, | ||
| } | ||
| } | ||
|
|
||
| if (response.status === 202) { | ||
| if (attempt === maxAttempts - 1) break | ||
| await setTimeout(delayMs) | ||
| delayMs = Math.min(delayMs * 2, 16_000) | ||
| continue | ||
| } | ||
|
|
||
| break | ||
| } catch (error: any) { | ||
| if (attempt === maxAttempts - 1) { | ||
| throw createError({ | ||
| statusCode: error.response?.status || 500, | ||
| statusMessage: | ||
| error.response?._data?.message || 'Failed to fetch issue count from GitHub', | ||
| }) | ||
| } | ||
| await setTimeout(delayMs) | ||
| delayMs = Math.min(delayMs * 2, 16_000) | ||
| } | ||
| } | ||
|
|
||
| throw createError({ | ||
| statusCode: 500, | ||
| statusMessage: 'Failed to fetch issue count from GitHub after retries', | ||
| }) | ||
| }, | ||
| { | ||
| 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
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
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.
The formatter for createdAt is unused and should be removed.
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.
Addressed in f64fd04