Make prior review cleanup best-effort so post review still runs.
Gitea can return 500 when deleting old reviews; log and continue instead of failing the whole webhook after a successful Cursor run. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+24
-5
@@ -1,20 +1,39 @@
|
|||||||
|
import { log } from "../logging/logger.js";
|
||||||
import { GiteaClient, PullFile } from "./client.js";
|
import { GiteaClient, PullFile } from "./client.js";
|
||||||
import { ReviewResult } from "../cursor/review-schema.js";
|
import { ReviewResult } from "../cursor/review-schema.js";
|
||||||
|
|
||||||
|
/** Best-effort cleanup; never throws (Gitea may return 500 for some review states). */
|
||||||
export async function deletePriorBotReviews(input: {
|
export async function deletePriorBotReviews(input: {
|
||||||
gitea: GiteaClient;
|
gitea: GiteaClient;
|
||||||
owner: string;
|
owner: string;
|
||||||
repo: string;
|
repo: string;
|
||||||
prNumber: number;
|
prNumber: number;
|
||||||
botLogin: string;
|
botLogin: string;
|
||||||
|
correlationId?: string;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
|
try {
|
||||||
const reviews = await input.gitea.getReviews(input.owner, input.repo, input.prNumber);
|
const reviews = await input.gitea.getReviews(input.owner, input.repo, input.prNumber);
|
||||||
const botReviews = reviews.filter((review) => review.user?.login === input.botLogin);
|
const botReviews = reviews.filter((review) => review.user?.login === input.botLogin);
|
||||||
await Promise.all(
|
|
||||||
botReviews.map((review) =>
|
for (const review of botReviews) {
|
||||||
input.gitea.deleteReview(input.owner, input.repo, input.prNumber, review.id)
|
try {
|
||||||
)
|
await input.gitea.deleteReview(input.owner, input.repo, input.prNumber, review.id);
|
||||||
);
|
} catch (error) {
|
||||||
|
log("warn", "Failed to delete prior bot review (continuing)", {
|
||||||
|
correlation_id: input.correlationId,
|
||||||
|
review_id: review.id,
|
||||||
|
pr_number: input.prNumber,
|
||||||
|
error: error instanceof Error ? error.message : String(error)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log("warn", "Failed to list prior bot reviews for cleanup (continuing)", {
|
||||||
|
correlation_id: input.correlationId,
|
||||||
|
pr_number: input.prNumber,
|
||||||
|
error: error instanceof Error ? error.message : String(error)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function postReview(input: {
|
export async function postReview(input: {
|
||||||
|
|||||||
@@ -167,18 +167,12 @@ async function executeReview(params: {
|
|||||||
shouldRetry: (error) => !isTimeoutError(error)
|
shouldRetry: (error) => !isTimeoutError(error)
|
||||||
});
|
});
|
||||||
|
|
||||||
await retry({
|
await deletePriorBotReviews({
|
||||||
fn: () =>
|
|
||||||
deletePriorBotReviews({
|
|
||||||
gitea,
|
gitea,
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
prNumber,
|
prNumber,
|
||||||
botLogin: input.env.GITEA_BOT_LOGIN
|
botLogin: input.env.GITEA_BOT_LOGIN,
|
||||||
}),
|
|
||||||
retries: 2,
|
|
||||||
initialDelayMs: 300,
|
|
||||||
operationName: "deletePriorBotReviews",
|
|
||||||
correlationId: input.correlationId
|
correlationId: input.correlationId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user