diff --git a/.coderabbit.yaml b/.coderabbit.yaml index 3c33e423..f45b8947 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -1,6 +1,8 @@ # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json -# CodeRabbit reviews every pull request. It reads AGENTS.md on its own, as one of its default code -# guidelines; the path instructions point it at what reviews of StableBar keep catching. +# CodeRabbit reviews pull requests labeled deep-review, and cubic reviews every pull request +# (cubic.yaml). .github/workflows/deep-review.yml adds the label to big or risky changes, and anyone +# can add it by hand. CodeRabbit reads AGENTS.md on its own, as one of its default code guidelines; +# the path instructions point it at what reviews of StableBar keep catching. language: en-US reviews: # Only the most important findings go inline. Each one is a thread to resolve before merging. @@ -18,6 +20,8 @@ reviews: auto_review: enabled: true drafts: false + # Adding the label starts a review. + labels: ["deep-review"] # Every base branch, so pull requests stacked on another branch are reviewed too. base_branches: [".*"] # Keep reviewing every push: by default reviews pause after five reviewed commits, silently diff --git a/.github/deep-review-paths b/.github/deep-review-paths new file mode 100644 index 00000000..cf2d38fc --- /dev/null +++ b/.github/deep-review-paths @@ -0,0 +1,24 @@ +Sources/StableBar/PrivateAPI.swift +Sources/StableBar/AppUpdate.swift +Sources/StableBar/UpdateRelease.swift +Sources/StableBar/ICloudSync*.swift +Sources/StableBar/Uninstall*.swift +Sources/StableBar/ConfigurationLoader.swift +Sources/StableBar/PackageSecrets.swift +Sources/StableBar/PackageSourceFetching.swift +Resources/Info.plist +Resources/StableBar.entitlements +.github/workflows/** +.github/scripts/** +.github/deep-review-paths +.github/CODEOWNERS +.github/dependabot.yml +.coderabbit.yaml +cubic.yaml +.githooks/** +scripts/** +.releaserc.json +Package.swift +Package.resolved +package.json +package-lock.json diff --git a/.github/scripts/deep-review.mjs b/.github/scripts/deep-review.mjs new file mode 100644 index 00000000..c58b6c4a --- /dev/null +++ b/.github/scripts/deep-review.mjs @@ -0,0 +1,20 @@ +// Decides whether a pull request gets the deep-review label, which starts a CodeRabbit review. +// .github/workflows/deep-review.yml runs the default branch's copy of this module, so a pull request +// never runs its own. +import { readFileSync } from "node:fs"; +import { matchesGlob } from "node:path"; + +export const deepReviewPaths = readFileSync(new URL("../deep-review-paths", import.meta.url), "utf8").trim().split("\n"); + +export function needsDeepReview(files, changedLines) { + return changedLines > 400 || files.some((file) => deepReviewPaths.some((path) => matchesGlob(file, path))); +} + +// Whether to add the label anew, which asks CodeRabbit again: at least 30 minutes ago, its summary +// comment said it hit the review limit on the head commit. CodeRabbit doesn't retry by itself, and +// drops the notice once it reviews. +export function needsRetry({ headSha, comments, now }) { + return comments.some((comment) => comment.user.login === "coderabbitai[bot]" + && comment.body.includes("rate limited by coderabbit.ai") && comment.body.includes(headSha) + && now - Date.parse(comment.updated_at) >= 30 * 60 * 1000); +} diff --git a/.github/scripts/deep-review.test.mjs b/.github/scripts/deep-review.test.mjs new file mode 100644 index 00000000..fc1558cd --- /dev/null +++ b/.github/scripts/deep-review.test.mjs @@ -0,0 +1,39 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { matchesGlob } from "node:path"; +import { deepReviewPaths, needsDeepReview, needsRetry } from "./deep-review.mjs"; + +test("needsDeepReview asks for more than 400 changed lines", () => { + assert.equal(needsDeepReview(["docs/widgets.md"], 400), false); + assert.equal(needsDeepReview(["docs/widgets.md"], 401), true); +}); + +test("needsDeepReview matches the listed paths", () => { + for (const file of ["Sources/StableBar/PrivateAPI.swift", "Sources/StableBar/ICloudSyncSettings.swift", + ".github/workflows/ci.yml", ".github/scripts/fixtures/screens.json", "scripts/build.sh", "Package.resolved"]) + assert.equal(needsDeepReview(["docs/widgets.md", file], 10), true, file); + for (const file of ["Sources/StableBar/BarStore.swift", "Sources/StableBar/Settings/PrivateAPI.swift", + "docs/scripts.md", "Tests/StableBarTests/UninstallTests.swift"]) + assert.equal(needsDeepReview([file], 10), false, file); +}); + +test("every listed path matches a file", () => { + const files = execFileSync("git", ["ls-files"], + { cwd: new URL("../..", import.meta.url), encoding: "utf8", timeout: 60_000 }).split("\n"); + for (const path of deepReviewPaths) assert.ok(files.some((file) => matchesGlob(file, path)), path); +}); + +test("needsRetry asks CodeRabbit again 30 minutes after its review limit held back the head commit", () => { + const limited = (user, head) => ({ user: { login: user }, updated_at: "2026-11-17T09:00:00Z", + body: `\nbetween a1 and ${head}.` }); + const summary = { user: { login: "coderabbitai[bot]" }, updated_at: "2026-11-17T09:00:00Z", + body: "\nbetween a1 and b2." }; + const pr = { headSha: "b2", comments: [limited("coderabbitai[bot]", "b2")], now: Date.parse("2026-11-17T09:30:00Z") }; + assert.equal(needsRetry(pr), true); + assert.equal(needsRetry({ ...pr, now: Date.parse("2026-11-17T09:29:00Z") }), false); + assert.equal(needsRetry({ ...pr, headSha: "c3" }), false); + assert.equal(needsRetry({ ...pr, comments: [summary] }), false); + assert.equal(needsRetry({ ...pr, comments: [limited("cubic-dev-ai[bot]", "b2")] }), false); + assert.equal(needsRetry({ ...pr, comments: [] }), false); +}); diff --git a/.github/scripts/pull-request-checks.mjs b/.github/scripts/pull-request-checks.mjs index b5ebcbff..229f6789 100644 --- a/.github/scripts/pull-request-checks.mjs +++ b/.github/scripts/pull-request-checks.mjs @@ -5,13 +5,13 @@ const keywords = "close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved" const sectionNames = ["Problem", "Changes", "Testing"]; const attributionHint = 'End it with the model and harness that did the work, such as "Claude Opus 5.5 via Claude Code", or with "No agent".'; -// The text GitHub shows, following CommonMark: auto-generated summaries and comments are hidden, +// The text GitHub shows, following CommonMark: auto-generated blocks and comments are hidden, // code is shown as written, a comment that starts a line hides everything up to its "-->" (or the // rest of the description when it never closes), and an unclosed "/g, ""); + .replace(//gi, ""); const shown = []; let paragraph = []; let fence = null; diff --git a/.github/scripts/pull-request-checks.test.mjs b/.github/scripts/pull-request-checks.test.mjs index e0fdb527..f34efc44 100644 --- a/.github/scripts/pull-request-checks.test.mjs +++ b/.github/scripts/pull-request-checks.test.mjs @@ -11,6 +11,9 @@ const filled = ["## Problem", "The clock disappears on a notched display.", "", "## Merging", "Rebase merge.", "", attribution].join("\n"); const summary = "\n\n" + "## Summary by CodeRabbit\n* New stuff\n"; +const cubicButtons = "\n\n\n" + + 'View guided diff\n' + + "\n"; const everything = ["Problem", "Changes", "Testing", "attribution line"]; test("visibleText drops comments, auto-generated blocks and carriage returns", () => { @@ -18,6 +21,7 @@ test("visibleText drops comments, auto-generated blocks and carriage returns", ( assert.equal(visibleText("a\n")).missing, ["Testing"]); assert.deepEqual(checkDescription(filled.replace("## Testing", "## testing")).missing, []); assert.deepEqual(checkDescription(filled + summary).missing, []); + assert.deepEqual(checkDescription(filled + cubicButtons).missing, []); assert.deepEqual(checkDescription(filled.replace("Keep it left of the notch.", "Handle the literal `