diff --git a/cmd/review-bot/main.go b/cmd/review-bot/main.go index 021ccc3..82e4575 100644 --- a/cmd/review-bot/main.go +++ b/cmd/review-bot/main.go @@ -315,6 +315,23 @@ func main() { sentinel := fmt.Sprintf("", *reviewerName) + // Stale check: verify HEAD hasn't moved since we started + // Re-fetch PR metadata to get the current HEAD SHA + evaluatedSHA := pr.Head.Sha + currentPR, err := giteaClient.GetPullRequest(ctx, owner, repoName, prNumber) + if err != nil { + slog.Warn("could not re-fetch PR for stale check", "pr", prNumber, "error", err) + // Continue anyway — better to post a potentially stale review than fail + } else if currentPR.Head.Sha != evaluatedSHA { + slog.Warn("HEAD moved during review — skipping stale review", + "evaluated", evaluatedSHA, + "current", currentPR.Head.Sha, + "pr", prNumber) + // Exit successfully — this isn't an error, just outdated work + // A new workflow run should already be in progress for the new HEAD + return + } + // Map findings to inline comments for lines present in the diff diffRanges := gitea.ParseDiffNewLines(diff) var inlineComments []gitea.ReviewComment