Skip to content

Commit c4c4d10

Browse files
committed
fix throttling types
1 parent c84d1e3 commit c4c4d10

File tree

1 file changed

+8
-3
lines changed
  • packages/web/src/app/api/(server)/webhook

1 file changed

+8
-3
lines changed

packages/web/src/app/api/(server)/webhook/route.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { WebhookEventDefinition} from "@octokit/webhooks/types";
66
import { EndpointDefaults } from "@octokit/types";
77
import { env } from "@sourcebot/shared";
88
import { processGitHubPullRequest } from "@/features/agents/review-agent/app";
9-
import { throttling } from "@octokit/plugin-throttling";
9+
import { throttling, type ThrottlingOptions } from "@octokit/plugin-throttling";
1010
import fs from "fs";
1111
import { GitHubPullRequest } from "@/features/agents/review-agent/types";
1212
import { createLogger } from "@sourcebot/shared";
1313

1414
const logger = createLogger('github-webhook');
1515

1616
const 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

1919
let githubAppBaseOptions: GitHubAppBaseOptions | undefined;
2020
const 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

Comments
 (0)