Stop deleting review caches on PR close
This commit is contained in:
1 parent
f9c632e6ab
commit
14a30a3695
6 files changed
+5
-89
No files matched your search
@@ -7,7 +7,6 @@ import { processPullRequestChat } from "../chat/processor.js";
|
||||
import { processIssueTriage, processPullRequestTriage } from "../triage/processor.js";
|
||||
import { deleteLocalReviewCache } from "../review/cache.js";
|
||||
import {
|
||||
cleanupPullRequestReviewCache,
|
||||
processRecheckComment,
|
||||
processPullRequest,
|
||||
processScheduledPendingMerges,
|
||||
@@ -104,17 +103,6 @@ async function main(): Promise<void> {
|
||||
pullNumber: prPayload.pull_request.number
|
||||
};
|
||||
|
||||
if (prPayload.action === "closed") {
|
||||
await cleanupPullRequestReviewCache(octokit, {
|
||||
...ref,
|
||||
repositoryId:
|
||||
process.env.GHBOT_REPOSITORY_ID ||
|
||||
process.env.GITHUB_REPOSITORY_ID ||
|
||||
prPayload.repository.full_name.replace("/", "-")
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (["opened", "edited", "reopened"].includes(prPayload.action)) {
|
||||
try {
|
||||
await processPullRequestTriage(octokit, {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import { z } from "zod";
|
||||
import { config } from "../config.js";
|
||||
import { logger } from "../logger.js";
|
||||
import type { ReviewDecision } from "../types.js";
|
||||
|
||||
@@ -104,32 +102,6 @@ export async function deleteLocalReviewCache(pullNumber: number): Promise<void>
|
||||
await fs.rm(cachePath(pullNumber), { force: true });
|
||||
}
|
||||
|
||||
export async function deleteRemoteReviewCaches(
|
||||
octokit: Octokit,
|
||||
params: { owner: string; repo: string; repositoryId: string; pullNumber: number }
|
||||
): Promise<number> {
|
||||
const keyPrefix = reviewCacheKeyPrefix(params.repositoryId, params.pullNumber);
|
||||
|
||||
try {
|
||||
return await deleteRemoteReviewCachesWithClient(octokit, params.owner, params.repo, keyPrefix);
|
||||
} catch (error) {
|
||||
if (!config.githubToken) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
logger.warn(
|
||||
{ error, owner: params.owner, repo: params.repo, pullNumber: params.pullNumber },
|
||||
"GitHub App could not delete Actions caches; retrying with GITHUB_TOKEN."
|
||||
);
|
||||
return deleteRemoteReviewCachesWithClient(
|
||||
new Octokit({ auth: config.githubToken }),
|
||||
params.owner,
|
||||
params.repo,
|
||||
keyPrefix
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function reviewCacheKeyPrefix(repositoryId: string, pullNumber: number): string {
|
||||
return `ghbot-review-${repositoryId}-pr-${pullNumber}-`;
|
||||
}
|
||||
@@ -138,34 +110,6 @@ function cachePath(pullNumber: number): string {
|
||||
return path.join(process.cwd(), ".ghbot-cache", `pr-${pullNumber}.json`);
|
||||
}
|
||||
|
||||
async function deleteRemoteReviewCachesWithClient(
|
||||
octokit: Octokit,
|
||||
owner: string,
|
||||
repo: string,
|
||||
keyPrefix: string
|
||||
): Promise<number> {
|
||||
const caches = await octokit.paginate(octokit.rest.actions.getActionsCacheList, {
|
||||
owner,
|
||||
repo,
|
||||
key: keyPrefix,
|
||||
per_page: 100
|
||||
});
|
||||
|
||||
for (const cache of caches) {
|
||||
if (cache.id === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await octokit.rest.actions.deleteActionsCacheById({
|
||||
owner,
|
||||
repo,
|
||||
cache_id: cache.id
|
||||
});
|
||||
}
|
||||
|
||||
return caches.length;
|
||||
}
|
||||
|
||||
function isFileNotFound(error: unknown): boolean {
|
||||
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import { withRetry } from "../retry.js";
|
||||
import type { PullRequestFile, PullRequestRef, ReviewDecision, ReviewMode } from "../types.js";
|
||||
import {
|
||||
deleteLocalReviewCache,
|
||||
deleteRemoteReviewCaches,
|
||||
loadPreviousReview,
|
||||
saveReviewCache
|
||||
} from "./cache.js";
|
||||
@@ -306,20 +305,6 @@ export async function processScheduledPendingMerges(
|
||||
}
|
||||
}
|
||||
|
||||
export async function cleanupPullRequestReviewCache(
|
||||
octokit: Octokit,
|
||||
params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
repositoryId: string;
|
||||
pullNumber: number;
|
||||
}
|
||||
): Promise<void> {
|
||||
await deleteLocalReviewCache(params.pullNumber);
|
||||
const deleted = await deleteRemoteReviewCaches(octokit, params);
|
||||
logger.info({ ...params, deleted }, "Deleted review caches for closed pull request.");
|
||||
}
|
||||
|
||||
export async function shouldReviewPullRequest(
|
||||
octokit: Octokit,
|
||||
params: { owner: string; repo: string; pullNumber: number }
|
||||
|
||||
Reference in new issue
Block a user