Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 187 additions & 0 deletions src/queue/processors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5574,6 +5574,22 @@ async function processGitHubWebhook(
return;
}

if (
eventName === "issue_comment" &&
(await maybeProcessReviewCommand(env, deliveryId, payload))
) {
await recordWebhookEvent(env, {
deliveryId,
eventName,
action: payload.action,
installationId: payload.installation?.id,
repositoryFullName: payload.repository?.full_name,
payloadHash: "processed",
status: "processed",
});
return;
}

if (
eventName === "issue_comment" &&
(await maybeProcessGateOverrideCommand(env, deliveryId, payload))
Expand Down Expand Up @@ -10343,6 +10359,177 @@ export async function resolveOverrideHeadSha(
* payload.comment.author_association. The override is intentionally NOT persisted: a follow-up push
* re-evaluates the Gate from scratch (no permanent bypass).
*/
/**
* `@gittensory review` / `re-review` (#2163): dispatch a manual auto-review re-run via the existing
* `reReviewStoredPullRequest` path. Affects only auto-review scheduling/output — never gate disposition
* (#1960). Honors the shared PR-command classifier, real repo permission auth, and pause/dry-run like
* gate-override/resolve.
*/
async function maybeProcessReviewCommand(
env: Env,
deliveryId: string,
payload: GitHubWebhookPayload,
): Promise<boolean> {
const command = parseGittensoryMentionCommand(payload.comment?.body);
if (!command || command.name !== "review") return false;

const req = classifyPrCommandRequest(payload, getInstallationId(payload));
if (!req.ok) {
await recordReviewCommandSkip(
env,
deliveryId,
req.repoFullName,
req.targetKey,
req.actor,
req.reason,
);
return true;
}

const [pr, settings] = await Promise.all([
getPullRequest(env, req.repoFullName, req.pr.number),
resolveRepositorySettings(env, req.repoFullName),
]);
const targetKey = `${req.repoFullName}#${req.pr.number}`;
if (!pr) {
await recordReviewCommandSkip(
env,
deliveryId,
req.repoFullName,
targetKey,
req.actor,
"cached_pr_missing",
);
return true;
}

const { authorization } = await authorizePrActionActor({
env,
deliveryId,
installationId: req.installationId,
repoFullName: req.repoFullName,
issue: payload.issue!,
actor: req.actor,
commandName: "review" as GittensoryMentionCommandName,
settings,
pr,
needsMinerDetection: true,
});
if (!authorization.authorized) {
await recordAuditEvent(env, {
eventType: "github_app.review_command_denied",
actor: req.actor,
targetKey,
outcome: "denied",
detail: authorization.reason,
metadata: {
deliveryId,
repoFullName: req.repoFullName,
allowedRoles: commandAuthorizationAllowedRoles(
settings.commandAuthorization,
"review",
),
},
});
await recordGithubProductUsage(env, "review_command_denied", {
actor: req.actor,
repoFullName: req.repoFullName,
targetKey,
outcome: "denied",
metadata: {
reason: authorization.reason,
actorKind: authorization.actorKind,
allowedRoles: commandAuthorizationAllowedRoles(
settings.commandAuthorization,
"review",
),
},
});
return true;
}

const mode = resolveAgentActionMode({
globalPaused: isGlobalAgentPause(env) || (await isGlobalAgentFrozen(env)),
agentPaused: settings.agentPaused,
agentDryRun: settings.agentDryRun,
});
if (mode !== "live") {
const skipReason = mode === "dry_run" ? "dry_run" : "agent_paused";
await recordReviewCommandSkip(
env,
deliveryId,
req.repoFullName,
targetKey,
req.actor,
skipReason,
);
return true;
}

await reReviewStoredPullRequest(
env,
deliveryId,
req.installationId,
req.repoFullName,
req.pr.number,
undefined,
{
skipAiReview: settings.aiReviewMode === "off",
force: true,
},
);

await recordAuditEvent(env, {
eventType: "github_app.review_command_completed",
actor: req.actor,
targetKey,
outcome: "completed",
metadata: {
deliveryId,
repoFullName: req.repoFullName,
headSha: pr.headSha ?? null,
commentId: payload.comment?.id ?? null,
},
});
await recordGithubProductUsage(env, "review_command_completed", {
actor: req.actor,
repoFullName: req.repoFullName,
targetKey,
outcome: "completed",
metadata: {
actorKind: authorization.actorKind,
headSha: pr.headSha ?? null,
commentId: payload.comment?.id ?? null,
},
});
return true;
}

async function recordReviewCommandSkip(
env: Env,
deliveryId: string,
repoFullName: string | null | undefined,
targetKey: string | null | undefined,
actor: string | null,
reason: string,
): Promise<void> {
await recordAuditEvent(env, {
eventType: "github_app.review_command_skipped",
actor,
targetKey,
outcome: "completed",
detail: reason,
metadata: { deliveryId, repoFullName: repoFullName ?? null, reason },
});
await recordGithubProductUsage(env, "review_command_skipped", {
actor,
repoFullName,
targetKey,
outcome: "skipped",
metadata: { reason },
});
}

async function maybeProcessGateOverrideCommand(
env: Env,
deliveryId: string,
Expand Down
Loading