@@ -250,9 +250,11 @@ export const GITHUB_CACHE_TTL_MS = 5 * 60 * 1000;
250250const contributionsCache = new DistributedCache < ExtendedContributionData > ( 1000 ) ;
251251const profileCache = new DistributedCache < GitHubUserProfile > ( 1000 ) ;
252252const reposCache = new DistributedCache < GitHubRepo [ ] > ( 500 ) ;
253+ const contributedReposCache = new DistributedCache < Record < string , unknown > [ ] > ( 500 ) ;
253254const pendingContributions = new Map < string , Promise < ExtendedContributionData > > ( ) ;
254255const pendingProfiles = new Map < string , Promise < GitHubUserProfile > > ( ) ;
255256const pendingRepos = new Map < string , Promise < GitHubRepo [ ] > > ( ) ;
257+ const pendingContributedRepos = new Map < string , Promise < Record < string , unknown > [ ] > > ( ) ;
256258
257259interface GitHubUserProfile {
258260 login : string ;
@@ -269,18 +271,18 @@ interface GitHubUserProfile {
269271}
270272
271273export function cacheKey (
272- kind : 'contributions' | 'profile' | 'repos' ,
274+ kind : 'contributions' | 'profile' | 'repos' | 'repos:contributed' ,
273275 username : string ,
274276 year ?: string
275277) : string ;
276278export function cacheKey (
277- kind : 'contributions' | 'profile' | 'repos' ,
279+ kind : 'contributions' | 'profile' | 'repos' | 'repos:contributed' ,
278280 username : string ,
279281 from ?: string ,
280282 to ?: string
281283) : string ;
282284export function cacheKey (
283- kind : 'contributions' | 'profile' | 'repos' ,
285+ kind : 'contributions' | 'profile' | 'repos' | 'repos:contributed' ,
284286 username : string ,
285287 yearOrFrom ?: string ,
286288 to ?: string
@@ -297,9 +299,11 @@ export function clearGitHubApiCacheForTests(): void {
297299 contributionsCache . clear ( ) ;
298300 profileCache . clear ( ) ;
299301 reposCache . clear ( ) ;
302+ contributedReposCache . clear ( ) ;
300303 pendingContributions . clear ( ) ;
301304 pendingProfiles . clear ( ) ;
302305 pendingRepos . clear ( ) ;
306+ pendingContributedRepos . clear ( ) ;
303307}
304308
305309function dedupeRequest < T > (
@@ -940,38 +944,54 @@ export async function fetchContributedRepos(
940944 username : string ,
941945 options : FetchOptions = { }
942946) : Promise < Record < string , unknown > [ ] > {
943- const query = `
944- query($login: String!) {
945- user(login: $login) {
946- repositoriesContributedTo(first: 100, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY], orderBy: {field: UPDATED_AT, direction: DESC}) {
947- nodes {
948- name
949- nameWithOwner
950- owner { login }
951- stargazerCount
952- forkCount
953- primaryLanguage { name }
954- updatedAt
947+ const key = cacheKey ( 'repos:contributed' , username ) ;
948+ if ( ! options . bypassCache ) {
949+ const cached = await contributedReposCache . get ( key ) ;
950+ if ( cached ) return cached ;
951+ }
952+
953+ const load = async ( ) => {
954+ const query = `
955+ query($login: String!) {
956+ user(login: $login) {
957+ repositoriesContributedTo(first: 100, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY], orderBy: {field: UPDATED_AT, direction: DESC}) {
958+ nodes {
959+ name
960+ nameWithOwner
961+ owner { login }
962+ stargazerCount
963+ forkCount
964+ primaryLanguage { name }
965+ updatedAt
966+ }
955967 }
956968 }
957969 }
958- }
959- ` ;
970+ ` ;
960971
961- const res = await fetchWithRetry ( GITHUB_GRAPHQL_URL , {
962- method : 'POST' ,
963- headers : getHeaders ( ) ,
964- body : JSON . stringify ( {
965- query,
966- variables : { login : username } ,
967- } ) ,
968- cache : 'no-store' ,
969- signal : options . signal ,
970- } ) ;
972+ const res = await fetchWithRetry ( GITHUB_GRAPHQL_URL , {
973+ method : 'POST' ,
974+ headers : getHeaders ( ) ,
975+ body : JSON . stringify ( {
976+ query,
977+ variables : { login : username } ,
978+ } ) ,
979+ cache : 'no-store' ,
980+ signal : options . signal ,
981+ } ) ;
982+
983+ if ( ! res . ok ) return [ ] ;
984+ const data = await res . json ( ) ;
985+ const result = data ?. data ?. user ?. repositoriesContributedTo ?. nodes || [ ] ;
986+
987+ if ( ! options . bypassCache ) {
988+ await contributedReposCache . set ( key , result , GITHUB_CACHE_TTL_MS ) ;
989+ }
990+ return result ;
991+ } ;
971992
972- if ( ! res . ok ) return [ ] ;
973- const data = await res . json ( ) ;
974- return data ?. data ?. user ?. repositoriesContributedTo ?. nodes || [ ] ;
993+ if ( options . bypassCache ) return load ( ) ;
994+ return dedupeRequest ( pendingContributedRepos , key , load ) ;
975995}
976996
977997export interface DeveloperScoreInput {
0 commit comments