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:
+26
-7
@@ -1,20 +1,39 @@
|
||||
import { log } from "../logging/logger.js";
|
||||
import { GiteaClient, PullFile } from "./client.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: {
|
||||
gitea: GiteaClient;
|
||||
owner: string;
|
||||
repo: string;
|
||||
prNumber: number;
|
||||
botLogin: string;
|
||||
correlationId?: string;
|
||||
}): Promise<void> {
|
||||
const reviews = await input.gitea.getReviews(input.owner, input.repo, input.prNumber);
|
||||
const botReviews = reviews.filter((review) => review.user?.login === input.botLogin);
|
||||
await Promise.all(
|
||||
botReviews.map((review) =>
|
||||
input.gitea.deleteReview(input.owner, input.repo, input.prNumber, review.id)
|
||||
)
|
||||
);
|
||||
try {
|
||||
const reviews = await input.gitea.getReviews(input.owner, input.repo, input.prNumber);
|
||||
const botReviews = reviews.filter((review) => review.user?.login === input.botLogin);
|
||||
|
||||
for (const review of botReviews) {
|
||||
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: {
|
||||
|
||||
@@ -167,18 +167,12 @@ async function executeReview(params: {
|
||||
shouldRetry: (error) => !isTimeoutError(error)
|
||||
});
|
||||
|
||||
await retry({
|
||||
fn: () =>
|
||||
deletePriorBotReviews({
|
||||
gitea,
|
||||
owner,
|
||||
repo,
|
||||
prNumber,
|
||||
botLogin: input.env.GITEA_BOT_LOGIN
|
||||
}),
|
||||
retries: 2,
|
||||
initialDelayMs: 300,
|
||||
operationName: "deletePriorBotReviews",
|
||||
await deletePriorBotReviews({
|
||||
gitea,
|
||||
owner,
|
||||
repo,
|
||||
prNumber,
|
||||
botLogin: input.env.GITEA_BOT_LOGIN,
|
||||
correlationId: input.correlationId
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user