(
repoRef: MaybeRefOrGetter<RepoRef | null | undefined>,
evolutionOptions: MaybeRefOrGetter<EvolutionOptions>,
)
| 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[]>, |
nothing calls this directly
no test coverage detected