(stats: GitHubContributorStats[])
| 186 | } |
| 187 | |
| 188 | function buildContributorCounts(stats: GitHubContributorStats[]) { |
| 189 | const weeklyCounts = new Map<number, number>() |
| 190 | const monthlyCounts = new Map<string, number>() |
| 191 | const yearlyCounts = new Map<string, number>() |
| 192 | |
| 193 | for (const contributor of stats ?? []) { |
| 194 | const monthSet = new Set<string>() |
| 195 | const yearSet = new Set<string>() |
| 196 | |
| 197 | for (const week of contributor?.weeks ?? []) { |
| 198 | if (!week || week.c <= 0) continue |
| 199 | |
| 200 | weeklyCounts.set(week.w, (weeklyCounts.get(week.w) ?? 0) + 1) |
| 201 | |
| 202 | const weekStartDate = new Date(week.w * 1000) |
| 203 | monthSet.add(toIsoMonthKey(weekStartDate)) |
| 204 | yearSet.add(String(weekStartDate.getUTCFullYear())) |
| 205 | } |
| 206 | |
| 207 | for (const key of monthSet) { |
| 208 | monthlyCounts.set(key, (monthlyCounts.get(key) ?? 0) + 1) |
| 209 | } |
| 210 | for (const key of yearSet) { |
| 211 | yearlyCounts.set(key, (yearlyCounts.get(key) ?? 0) + 1) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | return { weeklyCounts, monthlyCounts, yearlyCounts } |
| 216 | } |
| 217 | |
| 218 | async function fetchDailyRangeCached(packageName: string, startIso: string, endIso: string) { |
| 219 | const cache = npmDailyRangeCache |
no test coverage detected