MCPcopy
hub / github.com/npmx-dev/npmx.dev / fetchRepoContributorsEvolution

Function fetchRepoContributorsEvolution

app/composables/useCharts.ts:407–452  ·  view source on GitHub ↗
(
    repoRef: MaybeRefOrGetter<RepoRef | null | undefined>,
    evolutionOptions: MaybeRefOrGetter<EvolutionOptions>,
  )

Source from the content-addressed store, hash-verified

405 }
406
407 async function fetchRepoContributorsEvolution(
408 repoRef: MaybeRefOrGetter<RepoRef | null | undefined>,
409 evolutionOptions: MaybeRefOrGetter<EvolutionOptions>,
410 ): Promise<DailyDataPoint[] | WeeklyDataPoint[] | MonthlyDataPoint[] | YearlyDataPoint[]> {
411 const resolvedRepoRef = toValue(repoRef)
412 if (!resolvedRepoRef || resolvedRepoRef.provider !== 'github') return []
413
414 const resolvedOptions = toValue(evolutionOptions)
415
416 const cache = contributorsEvolutionCache
417 const cacheKey = `${resolvedRepoRef.owner}/${resolvedRepoRef.repo}`
418
419 let statsPromise: Promise<GitHubContributorStats[]>
420
421 if (cache?.has(cacheKey)) {
422 statsPromise = cache.get(cacheKey)!
423 } else {
424 statsPromise = $fetch<GitHubContributorStats[]>(
425 `/api/github/contributors-evolution/${resolvedRepoRef.owner}/${resolvedRepoRef.repo}`,
426 )
427 .then(data => (Array.isArray(data) ? data : []))
428 .catch(error => {
429 cache?.delete(cacheKey)
430 throw error
431 })
432
433 cache?.set(cacheKey, statsPromise)
434 }
435
436 const stats = await statsPromise
437 const { start, end } = resolveDateRange(resolvedOptions, null)
438
439 const { weeklyCounts, monthlyCounts, yearlyCounts } = buildContributorCounts(stats)
440
441 if (resolvedOptions.granularity === 'week') {
442 return buildWeeklyEvolutionFromContributorCounts(weeklyCounts, start, end)
443 }
444 if (resolvedOptions.granularity === 'month') {
445 return buildMonthlyEvolutionFromContributorCounts(monthlyCounts, start, end)
446 }
447 if (resolvedOptions.granularity === 'year') {
448 return buildYearlyEvolutionFromContributorCounts(yearlyCounts, start, end)
449 }
450
451 return []
452 }
453
454 async function fetchRepoRefsForPackages(
455 packageNames: MaybeRefOrGetter<string[]>,

Callers

nothing calls this directly

Calls 8

resolveDateRangeFunction · 0.85
buildContributorCountsFunction · 0.85
getMethod · 0.65
deleteMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected