mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 04:15:30 +00:00
fix throttling types
This commit is contained in:
parent
c84d1e3ab5
commit
c4c4d100f0
1 changed files with 8 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ import { WebhookEventDefinition} from "@octokit/webhooks/types";
|
||||||
import { EndpointDefaults } from "@octokit/types";
|
import { EndpointDefaults } from "@octokit/types";
|
||||||
import { env } from "@sourcebot/shared";
|
import { env } from "@sourcebot/shared";
|
||||||
import { processGitHubPullRequest } from "@/features/agents/review-agent/app";
|
import { processGitHubPullRequest } from "@/features/agents/review-agent/app";
|
||||||
import { throttling } from "@octokit/plugin-throttling";
|
import { throttling, type ThrottlingOptions } from "@octokit/plugin-throttling";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { GitHubPullRequest } from "@/features/agents/review-agent/types";
|
import { GitHubPullRequest } from "@/features/agents/review-agent/types";
|
||||||
import { createLogger } from "@sourcebot/shared";
|
import { createLogger } from "@sourcebot/shared";
|
||||||
|
|
@ -14,7 +14,7 @@ import { createLogger } from "@sourcebot/shared";
|
||||||
const logger = createLogger('github-webhook');
|
const logger = createLogger('github-webhook');
|
||||||
|
|
||||||
const DEFAULT_GITHUB_API_BASE_URL = "https://api.github.com";
|
const DEFAULT_GITHUB_API_BASE_URL = "https://api.github.com";
|
||||||
type GitHubAppBaseOptions = Omit<ConstructorParameters<typeof App>[0], "Octokit">;
|
type GitHubAppBaseOptions = Omit<ConstructorParameters<typeof App>[0], "Octokit"> & { throttle: ThrottlingOptions };
|
||||||
|
|
||||||
let githubAppBaseOptions: GitHubAppBaseOptions | undefined;
|
let githubAppBaseOptions: GitHubAppBaseOptions | undefined;
|
||||||
const githubAppCache = new Map<string, App>();
|
const githubAppCache = new Map<string, App>();
|
||||||
|
|
@ -30,7 +30,8 @@ if (env.GITHUB_REVIEW_AGENT_APP_ID && env.GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET
|
||||||
secret: env.GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET,
|
secret: env.GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET,
|
||||||
},
|
},
|
||||||
throttle: {
|
throttle: {
|
||||||
onRateLimit: (retryAfter: number, options: Required<EndpointDefaults>, octokit: Octokit, retryCount: number) => {
|
enabled: true,
|
||||||
|
onRateLimit: (retryAfter, _options, _octokit, retryCount) => {
|
||||||
if (retryCount > 3) {
|
if (retryCount > 3) {
|
||||||
logger.warn(`Rate limit exceeded: ${retryAfter} seconds`);
|
logger.warn(`Rate limit exceeded: ${retryAfter} seconds`);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -38,6 +39,10 @@ if (env.GITHUB_REVIEW_AGENT_APP_ID && env.GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
onSecondaryRateLimit: (_retryAfter, options) => {
|
||||||
|
// no retries on secondary rate limits
|
||||||
|
logger.warn(`SecondaryRateLimit detected for ${options.method} ${options.url}`);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue