@@ -647,33 +647,23 @@ export class GitHubCache {
647647 * @param owner the GitHub organization name
648648 * @returns a list of members, or `undefined` if not existing
649649 */
650- async getOrganizationMembers ( owner : string ) : Promise < Member [ ] | undefined > {
651- const cacheKey = this . #getOwnerKey( owner , "members" ) ;
652-
653- const cachedMembers = await this . #redis. json . get < Member [ ] > ( cacheKey ) ;
654- if ( cachedMembers ) {
655- console . log ( `Cache hit for members of ${ owner } ` ) ;
656- return cachedMembers . length ? cachedMembers : undefined ; // technically we can have a real empty list, but we ignore this case here
657- }
658-
659- console . log ( `Cache miss for members of ${ owner } , fetching from GitHub API` ) ;
660-
661- try {
662- const { data : members } = await this . #octokit. rest . orgs . listPublicMembers ( {
663- org : owner ,
664- per_page
665- } ) ;
666-
667- await this . #redis. json . set ( cacheKey , "$" , members ) ;
668- await this . #redis. expire ( cacheKey , MEMBERS_TTL ) ;
669-
670- return members ;
671- } catch {
672- await this . #redis. json . set ( cacheKey , "$" , [ ] ) ;
673- await this . #redis. expire ( cacheKey , MEMBERS_TTL ) ;
674-
675- return undefined ;
676- }
650+ async getOrganizationMembers ( owner : string ) {
651+ return await this . #processCached< Member [ ] > ( ) (
652+ this . #getOwnerKey( owner , "members" ) ,
653+ async ( ) => {
654+ try {
655+ const { data : members } = await this . #octokit. rest . orgs . listPublicMembers ( {
656+ org : owner ,
657+ per_page
658+ } ) ;
659+ return members ;
660+ } catch {
661+ return [ ] as Member [ ] ;
662+ }
663+ } ,
664+ members => members ,
665+ MEMBERS_TTL
666+ ) ;
677667 }
678668
679669 /**
@@ -683,34 +673,24 @@ export class GitHubCache {
683673 * @param repo the GitHub repository name
684674 * @returns a list of issues, or `undefined` if not existing
685675 */
686- async getAllIssues ( owner : string , repo : string ) : Promise < Issue [ ] | undefined > {
687- const cacheKey = this . #getRepoKey( owner , repo , "issues" ) ;
688-
689- const cachedIssues = await this . #redis. json . get < Issue [ ] > ( cacheKey ) ;
690- if ( cachedIssues ) {
691- console . log ( `Cache hit for issues for ${ owner } ` ) ;
692- return cachedIssues . length ? cachedIssues : undefined ;
693- }
694-
695- console . log ( `Cache miss for issues for ${ owner } ` ) ;
696-
697- try {
698- const { data : issues } = await this . #octokit. rest . issues . listForRepo ( {
699- owner,
700- repo,
701- per_page
702- } ) ;
703-
704- await this . #redis. json . set ( cacheKey , "$" , issues ) ;
705- await this . #redis. expire ( cacheKey , FULL_DETAILS_TTL ) ;
706-
707- return issues ;
708- } catch {
709- await this . #redis. json . set ( cacheKey , "$" , [ ] ) ;
710- await this . #redis. expire ( cacheKey , FULL_DETAILS_TTL ) ;
711-
712- return undefined ;
713- }
676+ async getAllIssues ( owner : string , repo : string ) {
677+ return await this . #processCached< Issue [ ] > ( ) (
678+ this . #getRepoKey( owner , repo , "issues" ) ,
679+ async ( ) => {
680+ try {
681+ const { data : issues } = await this . #octokit. rest . issues . listForRepo ( {
682+ owner,
683+ repo,
684+ per_page
685+ } ) ;
686+ return issues ;
687+ } catch {
688+ return [ ] as Issue [ ] ;
689+ }
690+ } ,
691+ issues => issues ,
692+ FULL_DETAILS_TTL
693+ ) ;
714694 }
715695
716696 /**
@@ -720,34 +700,24 @@ export class GitHubCache {
720700 * @param repo the GitHub repository name
721701 * @returns a list of pull requests, or `undefined` if not existing
722702 */
723- async getAllPRs ( owner : string , repo : string ) : Promise < ListedPullRequest [ ] | undefined > {
724- const cacheKey = this . #getRepoKey( owner , repo , "prs" ) ;
725-
726- const cachedPrs = await this . #redis. json . get < ListedPullRequest [ ] > ( cacheKey ) ;
727- if ( cachedPrs ) {
728- console . log ( `Cache hit for PRs for ${ owner } ` ) ;
729- return cachedPrs . length ? cachedPrs : undefined ;
730- }
731-
732- console . log ( `Cache miss for PRs for PRs for ${ owner } ` ) ;
733-
734- try {
735- const { data : prs } = await this . #octokit. rest . pulls . list ( {
736- owner,
737- repo,
738- per_page
739- } ) ;
740-
741- await this . #redis. json . set ( cacheKey , "$" , prs ) ;
742- await this . #redis. expire ( cacheKey , FULL_DETAILS_TTL ) ;
743-
744- return prs ;
745- } catch {
746- await this . #redis. json . set ( cacheKey , "$" , [ ] ) ;
747- await this . #redis. expire ( cacheKey , FULL_DETAILS_TTL ) ;
748-
749- return undefined ;
750- }
703+ async getAllPRs ( owner : string , repo : string ) {
704+ return await this . #processCached< ListedPullRequest [ ] > ( ) (
705+ this . #getRepoKey( owner , repo , "prs" ) ,
706+ async ( ) => {
707+ try {
708+ const { data : prs } = await this . #octokit. rest . pulls . list ( {
709+ owner,
710+ repo,
711+ per_page
712+ } ) ;
713+ return prs ;
714+ } catch {
715+ return [ ] as ListedPullRequest [ ] ;
716+ }
717+ } ,
718+ issues => issues ,
719+ FULL_DETAILS_TTL
720+ ) ;
751721 }
752722
753723 /**
0 commit comments