fix: hide resolved review threads
This commit is contained in:
1 parent
ceec15bf28
commit
3adf4a41a2
4 files changed
+57
-16
No files matched your search
+1
-1
@@ -46,7 +46,7 @@ goose 的审核结果固定包含四个顶层字段:
|
||||
|
||||
新 commit 触发 `synchronize` 后,workflow 会恢复该 PR 最新的缓存。goose 同时收到旧审核结果和当前完整 PR diff,重新验证所有旧问题、移除已经修复的问题,并检查新 commit 引入的回归。旧的合并结论不会在没有新审核的情况下直接复用。
|
||||
|
||||
每次 `synchronize` 都会先发布一条绑定当前 commit 的“开始审核”进度评论;审核完成、失败,或因为 PR 再次变化而过期时,会更新同一条评论。新审核成功发布后,ghbot 会把旧机器人审核中的逐行 `review` 和 `change` 线程标记为 resolved,dismiss 仍然生效的旧审核结论,并把旧审核正文压缩为 superseded 占位说明。如果 GitHub 无法通过 GraphQL 暴露某个旧线程,ghbot 才会删除这条无法映射的逐行评论作为降级处理。GitHub 不允许删除已经提交的 review 记录本身,因此最终只有最新审核保留完整正文和有效状态。
|
||||
每次 `synchronize` 都会先发布一条绑定当前 commit 的“开始审核”进度评论;审核完成、失败,或因为 PR 再次变化而过期时,会更新同一条评论。新审核成功发布后,ghbot 会把旧机器人审核中的逐行 `review` 和 `change` 线程标记为 resolved,并把这些已解决评论折叠隐藏,dismiss 仍然生效的旧审核结论,并把旧审核正文压缩为 superseded 占位说明。如果 GitHub 无法通过 GraphQL 暴露某个旧线程,ghbot 才会删除这条无法映射的逐行评论作为降级处理。GitHub 不允许删除已经提交的 review 记录本身,因此最终只有最新审核保留完整正文和有效状态。
|
||||
|
||||
PR 标题、描述或 base branch 变化触发 `edited` 时也会重新审核。对象按仓库 ID 和 PR 编号隔离;`latest.json` 用于加速下一次审核,`reviews/<head-sha>.json` 留存每个成功审核过的 head。关闭或合并 PR 不会主动删除这些对象。缓存不保存 API key、完整 diff 或 prompt。
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ When Cloudflare R2 is configured, each successful review stores this metadata in
|
||||
|
||||
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.
|
||||
|
||||
For every `synchronize` event, ghbot posts a commit-scoped progress comment when review starts and updates that same comment when the run completes, fails, or becomes stale because the PR changed again. After the new review is published successfully, ghbot marks inline `review` and `change` threads from earlier bot reviews as resolved, dismisses any earlier active bot decision, and reduces its old summary to a superseded marker. If GitHub cannot expose a legacy thread through GraphQL, ghbot deletes only that unmappable inline comment as a fallback. GitHub does not allow a submitted review record itself to be deleted, so the newest review is the only full and active automated result.
|
||||
For every `synchronize` event, ghbot posts a commit-scoped progress comment when review starts and updates that same comment when the run completes, fails, or becomes stale because the PR changed again. After the new review is published successfully, ghbot marks inline `review` and `change` threads from earlier bot reviews as resolved and minimizes those resolved comments, dismisses any earlier active bot decision, and reduces its old summary to a superseded marker. If GitHub cannot expose a legacy thread through GraphQL, ghbot deletes only that unmappable inline comment as a fallback. GitHub does not allow a submitted review record itself to be deleted, so the newest review is the only full and active automated result.
|
||||
|
||||
Objects are isolated by repository ID and PR number. `latest.json` accelerates the next review, while `reviews/<head-sha>.json` preserves each successful head result. Closing or merging a PR does not proactively delete these objects. Cache data contains no API keys, full diff, or prompt.
|
||||
|
||||
|
||||
+46
-11
@@ -1479,7 +1479,7 @@ export function formatSupersededReviewBody(params: {
|
||||
"",
|
||||
`The review for commit \`${shortSha(params.oldCommitId)}\` has been replaced by the automated review for commit \`${shortSha(params.currentCommitId)}\`.`,
|
||||
"",
|
||||
"Its previous inline `review` and `change` threads were marked as resolved. Refer to the latest commit review for the current result."
|
||||
"Its previous inline `review` and `change` threads were marked as resolved and hidden. Refer to the latest commit review for the current result."
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
@@ -1543,18 +1543,53 @@ async function resolveReviewThreadsForComments(
|
||||
if (matchingCommentNodeIds.length === 0) {
|
||||
continue;
|
||||
}
|
||||
let threadResolved = thread.isResolved;
|
||||
if (!threadResolved) {
|
||||
try {
|
||||
await withRetry("github.graphql.resolveReviewThread.superseded.item", async () => {
|
||||
return octokit.graphql(
|
||||
`mutation ResolveReviewThread($threadId: ID!) {
|
||||
resolveReviewThread(input: { threadId: $threadId }) {
|
||||
thread { isResolved }
|
||||
}
|
||||
}`,
|
||||
{ threadId: thread.id }
|
||||
);
|
||||
});
|
||||
threadResolved = true;
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
{ error, threadId: thread.id },
|
||||
"Could not resolve a superseded review thread."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!threadResolved) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const commentNodeId of matchingCommentNodeIds) {
|
||||
matchedCommentNodeIds.add(commentNodeId);
|
||||
}
|
||||
if (!thread.isResolved) {
|
||||
await octokit.graphql(
|
||||
`mutation ResolveReviewThread($threadId: ID!) {
|
||||
resolveReviewThread(input: { threadId: $threadId }) {
|
||||
thread { isResolved }
|
||||
}
|
||||
}`,
|
||||
{ threadId: thread.id }
|
||||
);
|
||||
try {
|
||||
await withRetry("github.graphql.minimizeResolvedReviewComment.superseded", async () => {
|
||||
return octokit.graphql(
|
||||
`mutation MinimizeSupersededInlineComment($subjectId: ID!) {
|
||||
minimizeComment(input: { subjectId: $subjectId, classifier: RESOLVED }) {
|
||||
minimizedComment { isMinimized }
|
||||
}
|
||||
}`,
|
||||
{ subjectId: commentNodeId }
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
// Resolution succeeded, so keep the comment rather than deleting it
|
||||
// merely because the optional visual minimization failed.
|
||||
logger.warn(
|
||||
{ error, commentNodeId },
|
||||
"Could not hide a resolved superseded review comment."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ test("superseded review body removes old findings and points to the current comm
|
||||
assert.match(body, /`aaaaaaaaaaaa`/);
|
||||
assert.match(body, /`bbbbbbbbbbbb`/);
|
||||
assert.doesNotMatch(body, /Required changes:/);
|
||||
assert.match(body, /inline `review` and `change` threads were marked as resolved/);
|
||||
assert.match(body, /inline `review` and `change` threads were marked as resolved and hidden/);
|
||||
});
|
||||
|
||||
test("old bot reviews are cleaned only while the current review is preserved", async () => {
|
||||
@@ -125,9 +125,10 @@ test("old bot reviews are cleaned only while the current review is preserved", a
|
||||
assert.ok(pulls.listReviews);
|
||||
});
|
||||
|
||||
test("superseded inline comments are marked resolved when GitHub exposes review threads", async () => {
|
||||
test("superseded inline comments are marked resolved and hidden when GitHub exposes review threads", async () => {
|
||||
const deletedComments: number[] = [];
|
||||
const resolvedThreads: string[] = [];
|
||||
const hiddenComments: string[] = [];
|
||||
const reviews = [
|
||||
{ id: 10, node_id: "PRR_10", user: { type: "Bot" }, body: marker, state: "CHANGES_REQUESTED", commit_id: "a".repeat(40) },
|
||||
{ id: 20, node_id: "PRR_20", user: { type: "Bot" }, body: marker, state: "COMMENTED", commit_id: "b".repeat(40) }
|
||||
@@ -154,7 +155,7 @@ test("superseded inline comments are marked resolved when GitHub exposes review
|
||||
dismissReview: async () => ({ data: {} })
|
||||
}
|
||||
},
|
||||
graphql: async (query: string, variables: { threadId?: string }) => {
|
||||
graphql: async (query: string, variables: { subjectId?: string; threadId?: string }) => {
|
||||
if (query.includes("query ReviewThreadsForSupersededReview")) {
|
||||
return {
|
||||
repository: {
|
||||
@@ -181,6 +182,10 @@ test("superseded inline comments are marked resolved when GitHub exposes review
|
||||
if (query.includes("mutation ResolveReviewThread")) {
|
||||
resolvedThreads.push(variables.threadId!);
|
||||
}
|
||||
if (query.includes("mutation MinimizeSupersededInlineComment")) {
|
||||
assert.match(query, /classifier: RESOLVED/);
|
||||
hiddenComments.push(variables.subjectId!);
|
||||
}
|
||||
return { resolveReviewThread: { thread: { isResolved: true } } };
|
||||
}
|
||||
} as unknown as Octokit;
|
||||
@@ -196,4 +201,5 @@ test("superseded inline comments are marked resolved when GitHub exposes review
|
||||
|
||||
assert.deepEqual(deletedComments, []);
|
||||
assert.deepEqual(resolvedThreads, ["THREAD_PRC_101", "THREAD_PRC_102"]);
|
||||
assert.deepEqual(hiddenComments, ["PRC_101", "PRC_102"]);
|
||||
});
|
||||
Reference in new issue
Block a user