Skip to content

Commit 279d3bd

Browse files
authored
fix(apply): restore PR review labels when the reviewed head matches the live head (#396)
Summary: - The PR updates apply-decision label freshness logic so complete same-head PR reviews can restore review labels after bot-updated timestamps, with regression tests for bot activity, human activity, and close proposals. - Reproducibility: yes. The linked issue gives a live timeline, and current-main source shows same-head comple ... omation bumps item.updatedAt while the durable review comment timestamp is older than the five-minute gate. Automerge notes: - PR branch already contained follow-up commit before automerge: fix(apply): keep fresh-head label restore out of close proposals Validation: - ClawSweeper review passed for head 4c41d09. - Required merge gates passed before the squash merge. Prepared head SHA: 4c41d09 Review: #396 (comment) Co-authored-by: yetval <[email protected]> Approved-by: momothemage
1 parent ead7d64 commit 279d3bd

2 files changed

Lines changed: 555 additions & 5 deletions

File tree

‎src/clawsweeper.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15205,6 +15205,13 @@ function stalePullRequestReviewHead(
1520515205
};
1520615206
}
1520715207

15208+
function freshPullRequestReviewHead(markdown: string, context: ItemContext): boolean {
15209+
if (frontMatterValue(markdown, "type") !== "pull_request") return false;
15210+
const reportHeadSha = pullHeadShaFromReport(markdown);
15211+
const liveHeadSha = pullHeadShaFromContext(context);
15212+
return Boolean(reportHeadSha && liveHeadSha && reportHeadSha === liveHeadSha);
15213+
}
15214+
1520815215
function isStalePullRequestReviewLabel(label: string): boolean {
1520915216
return (
1521015217
isClawSweeperOwnedLabel(label) &&
@@ -17574,11 +17581,20 @@ async function applyDecisionsCommand(args: Args): Promise<void> {
1757417581
const labelSyncFreshEnough = (): boolean => {
1757517582
if (!storedUpdatedAt) return false;
1757617583
if (!updatedSinceReview || reviewCommentOnlyUpdate) return true;
17577-
const existingReviewCommentUpdatedAtMs = timestampMs(commentUpdatedAt(existingReviewComment));
17578-
const itemUpdatedAtMs = timestampMs(item.updatedAt);
17579-
if (existingReviewCommentUpdatedAtMs === null || itemUpdatedAtMs === null) return false;
17580-
if (Math.abs(itemUpdatedAtMs - existingReviewCommentUpdatedAtMs) > 5 * 60 * 1000) {
17581-
return false;
17584+
const completeFreshHeadReview =
17585+
!isCloseProposal &&
17586+
item.kind === "pull_request" &&
17587+
frontMatterValue(markdown, "review_status") === "complete" &&
17588+
freshPullRequestReviewHead(markdown, currentItemContext());
17589+
if (!completeFreshHeadReview) {
17590+
const existingReviewCommentUpdatedAtMs = timestampMs(
17591+
commentUpdatedAt(existingReviewComment),
17592+
);
17593+
const itemUpdatedAtMs = timestampMs(item.updatedAt);
17594+
if (existingReviewCommentUpdatedAtMs === null || itemUpdatedAtMs === null) return false;
17595+
if (Math.abs(itemUpdatedAtMs - existingReviewCommentUpdatedAtMs) > 5 * 60 * 1000) {
17596+
return false;
17597+
}
1758217598
}
1758317599
const storedUpdatedAtMs = timestampMs(storedUpdatedAt);
1758417600
if (storedUpdatedAtMs === null) return false;

0 commit comments

Comments
 (0)