@@ -6,15 +6,15 @@ import { WebhookEventDefinition} from "@octokit/webhooks/types";
66import { EndpointDefaults } from "@octokit/types" ;
77import { env } from "@sourcebot/shared" ;
88import { processGitHubPullRequest } from "@/features/agents/review-agent/app" ;
9- import { throttling } from "@octokit/plugin-throttling" ;
9+ import { throttling , type ThrottlingOptions } from "@octokit/plugin-throttling" ;
1010import fs from "fs" ;
1111import { GitHubPullRequest } from "@/features/agents/review-agent/types" ;
1212import { createLogger } from "@sourcebot/shared" ;
1313
1414const logger = createLogger ( 'github-webhook' ) ;
1515
1616const DEFAULT_GITHUB_API_BASE_URL = "https://api.github.com" ;
17- type GitHubAppBaseOptions = Omit < ConstructorParameters < typeof App > [ 0 ] , "Octokit" > ;
17+ type GitHubAppBaseOptions = Omit < ConstructorParameters < typeof App > [ 0 ] , "Octokit" > & { throttle : ThrottlingOptions } ;
1818
1919let githubAppBaseOptions : GitHubAppBaseOptions | undefined ;
2020const githubAppCache = new Map < string , App > ( ) ;
@@ -30,14 +30,19 @@ if (env.GITHUB_REVIEW_AGENT_APP_ID && env.GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET
3030 secret : env . GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET ,
3131 } ,
3232 throttle : {
33- onRateLimit : ( retryAfter : number , options : Required < EndpointDefaults > , octokit : Octokit , retryCount : number ) => {
33+ enabled : true ,
34+ onRateLimit : ( retryAfter , _options , _octokit , retryCount ) => {
3435 if ( retryCount > 3 ) {
3536 logger . warn ( `Rate limit exceeded: ${ retryAfter } seconds` ) ;
3637 return false ;
3738 }
3839
3940 return true ;
4041 } ,
42+ onSecondaryRateLimit : ( _retryAfter , options ) => {
43+ // no retries on secondary rate limits
44+ logger . warn ( `SecondaryRateLimit detected for ${ options . method } ${ options . url } ` ) ;
45+ }
4146 } ,
4247 } ;
4348 } catch ( error ) {
0 commit comments