Convert reviewer to GitHub Actions workflow

This commit is contained in:
lezi-fun committed 2026-05-16 13:15:14 +08:00
1 parent 9d40d7850f
commit 50d0ae5be9
18 files changed
+541 -2641

No files matched your search

-17
View File
@@ -1,17 +0,0 @@
import { createAppAuth } from "@octokit/auth-app";
import { Octokit } from "@octokit/rest";
import { config } from "../config.js";
export async function getInstallationOctokit(installationId: number): Promise<Octokit> {
const auth = createAppAuth({
appId: config.githubAppId,
privateKey: config.githubPrivateKey,
installationId
});
const installationAuthentication = await auth({ type: "installation" });
return new Octokit({
auth: installationAuthentication.token
});
}
+6
View File
@@ -1,5 +1,7 @@
import type { Octokit } from "@octokit/rest";
const IGNORED_CHECK_RUN_NAMES = new Set(["ghbot review", "bot-review"]);
export async function requiredChecksAreGreen(
octokit: Octokit,
params: {
@@ -22,6 +24,10 @@ export async function requiredChecksAreGreen(
]);
const failedCheck = checks.data.check_runs.find((check) => {
if (IGNORED_CHECK_RUN_NAMES.has(check.name)) {
return false;
}
return (
check.status !== "completed" ||
!["success", "neutral", "skipped"].includes(check.conclusion ?? "")
+8
View File
@@ -0,0 +1,8 @@
import { Octokit } from "@octokit/rest";
import { config } from "../config.js";
export function createGitHubClient(): Octokit {
return new Octokit({
auth: config.githubToken
});
}
-84
View File
@@ -1,84 +0,0 @@
import { Webhooks } from "@octokit/webhooks";
import { config } from "../config.js";
import { getInstallationOctokit } from "./app.js";
import { logger } from "../logger.js";
import {
isLenientCheckAction,
processLenientCheckRunAction,
processPullRequest,
processPullRequestReviewApproval
} from "../review/processor.js";
export function createGitHubWebhooks(): Webhooks {
const webhooks = new Webhooks({
secret: config.webhookSecret
});
webhooks.on(
["pull_request.opened", "pull_request.synchronize", "pull_request.reopened", "pull_request.ready_for_review"],
async ({ payload }) => {
const installationId = payload.installation?.id;
if (!installationId) {
logger.warn({ repository: payload.repository.full_name, pullNumber: payload.pull_request.number }, "Skipping PR without installation id.");
return;
}
const octokit = await getInstallationOctokit(installationId);
await processPullRequest(octokit, {
owner: payload.repository.owner.login,
repo: payload.repository.name,
pullNumber: payload.pull_request.number
});
}
);
webhooks.on("check_run.requested_action", async ({ payload }) => {
const actionIdentifier = payload.requested_action?.identifier;
if (!actionIdentifier || !isLenientCheckAction(actionIdentifier)) {
return;
}
const installationId = payload.installation?.id;
if (!installationId) {
logger.warn({ repository: payload.repository.full_name, checkRun: payload.check_run.id }, "Skipping check action without installation id.");
return;
}
const octokit = await getInstallationOctokit(installationId);
await processLenientCheckRunAction(octokit, {
owner: payload.repository.owner.login,
repo: payload.repository.name,
headSha: payload.check_run.head_sha
});
});
webhooks.on("pull_request_review.submitted", async ({ payload }) => {
const reviewerLogin = payload.review.user?.login;
if (!reviewerLogin) {
logger.warn({ repository: payload.repository.full_name, pullNumber: payload.pull_request.number }, "Skipping review without reviewer login.");
return;
}
const installationId = payload.installation?.id;
if (!installationId) {
logger.warn({ repository: payload.repository.full_name, pullNumber: payload.pull_request.number }, "Skipping review without installation id.");
return;
}
const octokit = await getInstallationOctokit(installationId);
await processPullRequestReviewApproval(octokit, {
owner: payload.repository.owner.login,
repo: payload.repository.name,
pullNumber: payload.pull_request.number,
reviewerLogin,
state: payload.review.state,
commitId: payload.review.commit_id
});
});
webhooks.onError((error) => {
logger.error({ error }, "Webhook handler failed.");
});
return webhooks;
}