Skip to content

Commit 56189d5

Browse files
committed
feat(devindex): Enhance Top Repo logic with Owner and increase sample size (#9171)
- Fetch owner { login } in commitContributionsByRepository to uniquely identify repos. - Use ${owner}/${name} as the aggregation key to handle forks and common names correctly. - Increase maxRepositories from 5 to 10 per year to improve statistical accuracy for prolific contributors. - Add architectural documentation explaining the Top Repo heuristic strategy.
1 parent 50ba9a0 commit 56189d5

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

apps/devindex/services/Updater.mjs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@ class Updater extends Base {
307307

308308
// 3. Build Multi-Year Contribution Query
309309
// BATCHING: We split the years into chunks of 4 to prevent 502/504 errors on large accounts.
310+
//
311+
// TOP REPO STRATEGY:
312+
// We want to identify the user's "Lifetime Top Repository" (highest commit count).
313+
// - Ideally, we would fetch ALL contributions for ALL years, but fetching `commitContributionsByRepository`
314+
// without a limit is too expensive and slow.
315+
// - GitHub API sorts this list by `OCCURRED_AT` (default), not by count.
316+
// - We use `maxRepositories: 10` as a statistical trade-off. For prolific users (contributing to >10 repos/year),
317+
// we might miss a high-count repo if it wasn't recently active in that year.
318+
// - We aggregate these counts across all years.
319+
// - We MUST use `${owner}/${name}` as the key, because `name` alone is ambiguous (forks, common names).
310320
const contribData = {};
311321

312322
const fetchYears = async (fromYear, toYear) => {
@@ -321,8 +331,8 @@ class Updater extends Base {
321331
totalPullRequestReviewContributions
322332
totalRepositoryContributions
323333
restrictedContributionsCount
324-
commitContributionsByRepository(maxRepositories: 5) {
325-
repository { name }
334+
commitContributionsByRepository(maxRepositories: 10) {
335+
repository { name, owner { login } }
326336
contributions { totalCount }
327337
}
328338
}`;
@@ -387,9 +397,12 @@ class Updater extends Base {
387397
// Aggregate Repos (Focus Metric)
388398
if (collection?.commitContributionsByRepository) {
389399
collection.commitContributionsByRepository.forEach(repo => {
390-
const name = repo.repository.name;
391-
const count = repo.contributions.totalCount;
392-
repoMap.set(name, (repoMap.get(name) || 0) + count);
400+
const name = repo.repository.name;
401+
const owner = repo.repository.owner.login;
402+
const fullName = `${owner}/${name}`;
403+
const count = repo.contributions.totalCount;
404+
405+
repoMap.set(fullName, (repoMap.get(fullName) || 0) + count);
393406
});
394407
}
395408

0 commit comments

Comments
 (0)