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
@@ -8,7 +8,6 @@ on:
|
|||||||
- reopened
|
- reopened
|
||||||
- ready_for_review
|
- ready_for_review
|
||||||
- edited
|
- edited
|
||||||
- closed
|
|
||||||
issues:
|
issues:
|
||||||
types:
|
types:
|
||||||
- opened
|
- opened
|
||||||
|
|||||||
+3
-3
@@ -46,7 +46,7 @@ goose 的审核结果固定包含四个顶层字段:
|
|||||||
|
|
||||||
新 commit 触发 `synchronize` 后,workflow 会恢复该 PR 最新的缓存。goose 同时收到旧审核结果和当前完整 PR diff,重新验证所有旧问题、移除已经修复的问题,并检查新 commit 引入的回归。旧的合并结论不会在没有新审核的情况下直接复用。
|
新 commit 触发 `synchronize` 后,workflow 会恢复该 PR 最新的缓存。goose 同时收到旧审核结果和当前完整 PR diff,重新验证所有旧问题、移除已经修复的问题,并检查新 commit 引入的回归。旧的合并结论不会在没有新审核的情况下直接复用。
|
||||||
|
|
||||||
PR 标题、描述或 base branch 变化触发 `edited` 时也会重新审核。PR 被关闭或合并后,机器人会删除本地缓存文件,并通过 Actions Cache API 删除该 PR 的远端缓存。缓存不保存 API key、完整 diff 或 prompt。
|
PR 标题、描述或 base branch 变化触发 `edited` 时也会重新审核。关闭或合并 PR 不会主动删除 Actions cache;旧条目由 GitHub 的常规缓存保留策略自然清理。缓存不保存 API key、完整 diff 或 prompt。
|
||||||
|
|
||||||
## 可自我改进的仓库认知缓存
|
## 可自我改进的仓库认知缓存
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ workflow 自动获得 `github.token`,无需额外创建名为 `GITHUB_TOKEN`
|
|||||||
|
|
||||||
workflow 声明以下权限:
|
workflow 声明以下权限:
|
||||||
|
|
||||||
- `actions: write`:保存、恢复和删除 Actions cache。
|
- `actions: write`:保存和恢复 Actions cache。
|
||||||
- `contents: write`:可选自动合并和仓库操作。
|
- `contents: write`:可选自动合并和仓库操作。
|
||||||
- `pull-requests: write`:列出 PR、提交 review 和合并。
|
- `pull-requests: write`:列出 PR、提交 review 和合并。
|
||||||
- `issues: write`:列出 Issue/PR、管理标签和发布评论。
|
- `issues: write`:列出 Issue/PR、管理标签和发布评论。
|
||||||
@@ -160,7 +160,7 @@ GitHub App 建议配置以下 Repository permissions:
|
|||||||
|
|
||||||
GitHub Actions Secret 和 Variable 名称不能以 `GITHUB_` 开头,所以使用上述 `GH_APP_*` 名称。
|
GitHub Actions Secret 和 Variable 名称不能以 `GITHUB_` 开头,所以使用上述 `GH_APP_*` 名称。
|
||||||
|
|
||||||
GitHub App 和 workflow token 在拥有对应权限时都可以列出 Issue、PR 和标签。删除 Actions cache 需要 `actions: write`;如果 App 没有该权限,ghbot 会尝试使用 workflow token 回退。
|
GitHub App 和 workflow token 在拥有对应权限时都可以列出 Issue、PR 和标签。Actions cache 由 workflow 的 `github.token` 和 `actions/cache` 管理,不会在 PR 关闭时由 App 主动删除。
|
||||||
|
|
||||||
## 在其他仓库中复用
|
## 在其他仓库中复用
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ Each successful review stores this metadata in GitHub Actions cache:
|
|||||||
|
|
||||||
When a new commit triggers `synchronize`, or PR metadata/base changes trigger `edited`, the latest cache for that PR is restored. goose receives an earlier-head result plus the current complete PR patch, revalidates old findings, removes fixed findings, and checks the newest content. The previous merge decision is never reused without a fresh review. An `edited` event on the same head still runs a fresh complete review so title, description, and base-branch changes are respected.
|
When a new commit triggers `synchronize`, or PR metadata/base changes trigger `edited`, the latest cache for that PR is restored. goose receives an earlier-head result plus the current complete PR patch, revalidates old findings, removes fixed findings, and checks the newest content. The previous merge decision is never reused without a fresh review. An `edited` event on the same head still runs a fresh complete review so title, description, and base-branch changes are respected.
|
||||||
|
|
||||||
Cache keys are isolated by repository ID and PR number. A `closed` event, including a merged PR, deletes all remote caches for that PR and removes the local cache file. Cache data contains no API keys, full diff, or prompt.
|
Cache keys are isolated by repository ID and PR number. Closing or merging a PR does not proactively delete its Actions cache; GitHub's normal cache retention policy removes old entries. Cache data contains no API keys, full diff, or prompt.
|
||||||
|
|
||||||
### Self-improving repository knowledge cache
|
### Self-improving repository knowledge cache
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ The workflow always receives `github.token`, so no `GITHUB_TOKEN` repository sec
|
|||||||
|
|
||||||
Workflow permissions:
|
Workflow permissions:
|
||||||
|
|
||||||
- `actions: write`: save/restore Actions cache and delete PR caches on close or merge.
|
- `actions: write`: save and restore Actions cache.
|
||||||
- `contents: write`: optional merge and repository operations.
|
- `contents: write`: optional merge and repository operations.
|
||||||
- `pull-requests: write`: list PRs, create reviews, and merge.
|
- `pull-requests: write`: list PRs, create reviews, and merge.
|
||||||
- `issues: write`: list issues/PRs, add labels, create labels, and post comments.
|
- `issues: write`: list issues/PRs, add labels, create labels, and post comments.
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { processPullRequestChat } from "../chat/processor.js";
|
|||||||
import { processIssueTriage, processPullRequestTriage } from "../triage/processor.js";
|
import { processIssueTriage, processPullRequestTriage } from "../triage/processor.js";
|
||||||
import { deleteLocalReviewCache } from "../review/cache.js";
|
import { deleteLocalReviewCache } from "../review/cache.js";
|
||||||
import {
|
import {
|
||||||
cleanupPullRequestReviewCache,
|
|
||||||
processRecheckComment,
|
processRecheckComment,
|
||||||
processPullRequest,
|
processPullRequest,
|
||||||
processScheduledPendingMerges,
|
processScheduledPendingMerges,
|
||||||
@@ -104,17 +103,6 @@ async function main(): Promise<void> {
|
|||||||
pullNumber: prPayload.pull_request.number
|
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)) {
|
if (["opened", "edited", "reopened"].includes(prPayload.action)) {
|
||||||
try {
|
try {
|
||||||
await processPullRequestTriage(octokit, {
|
await processPullRequestTriage(octokit, {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { Octokit } from "@octokit/rest";
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { config } from "../config.js";
|
|
||||||
import { logger } from "../logger.js";
|
import { logger } from "../logger.js";
|
||||||
import type { ReviewDecision } from "../types.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 });
|
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 {
|
export function reviewCacheKeyPrefix(repositoryId: string, pullNumber: number): string {
|
||||||
return `ghbot-review-${repositoryId}-pr-${pullNumber}-`;
|
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`);
|
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 {
|
function isFileNotFound(error: unknown): boolean {
|
||||||
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
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 type { PullRequestFile, PullRequestRef, ReviewDecision, ReviewMode } from "../types.js";
|
||||||
import {
|
import {
|
||||||
deleteLocalReviewCache,
|
deleteLocalReviewCache,
|
||||||
deleteRemoteReviewCaches,
|
|
||||||
loadPreviousReview,
|
loadPreviousReview,
|
||||||
saveReviewCache
|
saveReviewCache
|
||||||
} from "./cache.js";
|
} 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(
|
export async function shouldReviewPullRequest(
|
||||||
octokit: Octokit,
|
octokit: Octokit,
|
||||||
params: { owner: string; repo: string; pullNumber: number }
|
params: { owner: string; repo: string; pullNumber: number }
|
||||||
|
|||||||
Reference in new issue
Block a user