11import { Octokit as OctokitCore } from '@octokit/core' ;
22import { paginateRest } from "@octokit/plugin-paginate-rest" ;
33import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods" ;
4+ import { retry as retryPlugin } from '@octokit/plugin-retry' ;
45import { z } from 'zod' ;
56import type { components } from '@octokit/openapi-types' ;
67import { createAppAuth } from '@octokit/auth-app' ;
@@ -17,7 +18,6 @@ import {
1718 isRecord ,
1819 mapObjectEntries ,
1920 resultOf ,
20- retry ,
2121 unique ,
2222} from './common/common-utils.js' ;
2323import {
@@ -39,7 +39,7 @@ import {logger} from './logger.js';
3939import { RestEndpointMethodTypes } from '@octokit/rest' ;
4040
4141const Octokit = OctokitCore
42- . plugin ( restEndpointMethods ) . plugin ( paginateRest ) ;
42+ . plugin ( restEndpointMethods , paginateRest , retryPlugin ) ;
4343
4444const ACCESS_POLICY_MAX_SIZE = 100 * 1024 ; // 100kb
4545const GITHUB_API_CONCURRENCY_LIMIT = limit ( 8 ) ;
@@ -604,12 +604,11 @@ async function getAccessPolicy<T extends typeof GitHubAccessPolicySchema>(client
604604 preprocessor : ( value : unknown ) => unknown ,
605605} ) : Promise < z . infer < T > > {
606606 const policyValue = await findFirstNotNull ( paths , async ( path ) => {
607- try {
608- return await getRepositoryFileContent ( client , { owner, repo, path, maxSize : ACCESS_POLICY_MAX_SIZE } ) ;
609- } catch ( error ) {
610- logger . error ( { owner, repo, path, error : String ( error ) } , 'Failed to get access policy file content' ) ;
611- return null ;
612- }
607+ return getRepositoryFileContent ( client , { owner, repo, path, maxSize : ACCESS_POLICY_MAX_SIZE } )
608+ . catch ( ( error ) => {
609+ logger . error ( { owner, repo, path, error : String ( error ) } , 'Failed to get access policy file content' ) ;
610+ return null ;
611+ } ) ;
613612 } ) ;
614613 if ( ! policyValue ) {
615614 throw new GithubAccessPolicyError ( `Access policy not found` ) ;
@@ -920,17 +919,9 @@ function formatAccessPolicyError(error: GithubAccessPolicyError) {
920919async function getAppInstallation ( client : Octokit , { owner} : {
921920 owner : string
922921} ) : Promise < GitHubAppInstallation | null > {
923- // WORKAROUND: for some reason sometimes the request connection gets closed unexpectedly (line closed),
924- // therefore, we retry on any error
925- return retry (
926- async ( ) => client . rest . apps . getUserInstallation ( { username : owner } )
927- . then ( ( res ) => res . data )
928- . catch ( async ( error ) => ( error . status === Status . NOT_FOUND ? null : _throw ( error ) ) ) ,
929- {
930- delay : 1000 ,
931- retries : 3 ,
932- } ,
933- ) ;
922+ return client . rest . apps . getUserInstallation ( { username : owner } )
923+ . then ( ( res ) => res . data )
924+ . catch ( async ( error ) => ( error . status === Status . NOT_FOUND ? null : _throw ( error ) ) ) ;
934925}
935926
936927/**
0 commit comments