Repository navigation
feat(review): --all-projects reviews every dbt project a PR touches in one run
#1773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/review-ai-focused-batches
Are you sure you want to change the base?
Changes from all commits
2522e5a
3376fec
5b9d1d4
218f445
45795f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -75,6 +75,8 @@ export function renderSummary(env: VerdictEnvelope, opts: RenderOptions = {}): s | |||||
| return "" | ||||||
|
|
||||||
| const lines: string[] = [REVIEW_MARKER, "", `## ${verdictHeadline(env)}`, ""] | ||||||
| const projects = env.scope?.projects ?? [] | ||||||
| if (projects.length > 1) lines.push(`Reviewed ${projects.length} dbt projects: ${projects.map((p) => p.root || ".").join(", ")}`, "") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Project roots are repository-controlled strings, but this line inserts them raw into Markdown. A project directory containing a backtick or newline can break the summary's formatting or inject content; render each root with Prompt for AI agents
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow-up: low priority, tracked ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: The project list is unbounded, unlike the other multi-entry renders ( On a monorepo with many (or long-named) projects this single fixed line can consume most of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as r4626966319; tracked. |
||||||
|
|
||||||
| if (env.summary.degraded) { | ||||||
| lines.push( | ||||||
|
|
||||||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import path from "node:path" | |
| import { readFile, realpath, stat, access, readdir } from "node:fs/promises" | ||
| import YAML from "yaml" | ||
| import { Installation } from "../../installation" | ||
| import { loadReviewPolicy, policyHash, resolveRubric } from "./config" | ||
| import { headPolicyChanges, loadReviewPolicy, policyHash, resolveRubric } from "./config" | ||
| import { SEVERITY_ORDER, type Severity } from "./finding" | ||
| import { | ||
| collectChangedFiles, | ||
|
|
@@ -47,6 +47,9 @@ export interface ReviewPullRequestOptions { | |
| head?: string | ||
| /** Override the manifest path from config. */ | ||
| manifestPath?: string | ||
| /** Directories whose `.altimate/review` policy applies, in order, when `cwd` has none | ||
| * (`--all-projects`: the ancestors of `cwd` up to the repository root, nearest first). */ | ||
| policyFallbackDirs?: string[] | ||
| /** Override the review mode from config. */ | ||
| mode?: ReviewMode | ||
| /** Override the minimum severity to surface. */ | ||
|
|
@@ -72,6 +75,10 @@ export interface ReviewPullRequestOptions { | |
| /** G2 — [EXPERIMENTAL] bypass the tier classifier with the supplied tier. | ||
| * Envelope carries `tierForced: true` when used. Debug / bench only. */ | ||
| forceTier?: "trivial" | "lite" | "full" | ||
| /** Every file the PR changes, when `changedFiles` is a subset of it (multi-project review). */ | ||
| prFiles?: string[] | ||
| /** Every rename the PR makes (new → old path), when `changedFiles` is a subset of it. */ | ||
| prRenames?: Array<[string, string]> | ||
| } | ||
|
|
||
| /** dbt adapter_type → core SQL dialect. Mostly identity; a few aliases. */ | ||
|
|
@@ -256,14 +263,29 @@ export async function reviewPullRequest(opts: ReviewPullRequestOptions): Promise | |
|
|
||
| // The policy (.altimate/review.yml) comes from the BASE commit, so the PR | ||
| // under review cannot relax its own rules; what it would change is listed. | ||
| const cwdRel = await repoRelative(gitRoot, opts.cwd, true) | ||
| const policy = await loadReviewPolicy({ | ||
| cwd: opts.cwd, | ||
| readBase: | ||
| resolved && cwdRel !== undefined | ||
| ? (rel) => showAtRef(opts.cwd, resolved.sha, path.posix.join(cwdRel, rel)) | ||
| : undefined, | ||
| }) | ||
| // The first of cwd and `policyFallbackDirs` that has a policy file wins. | ||
| const policyAt = async (dir: string) => { | ||
| const dirRel = await repoRelative(gitRoot, dir, true) | ||
| return loadReviewPolicy({ | ||
| cwd: dir, | ||
| readBase: | ||
| resolved && dirRel !== undefined ? (rel) => showAtRef(opts.cwd, resolved.sha, path.posix.join(dirRel, rel)) : undefined, | ||
| }) | ||
| } | ||
| const policyHere = await policyAt(opts.cwd) | ||
| let policy = policyHere | ||
| for (const dir of opts.policyFallbackDirs ?? []) { | ||
| if (policy.source !== "default") break | ||
| policy = await policyAt(dir) | ||
| } | ||
| if (policy !== policyHere) { | ||
| // A policy file the PR adds in cwd replaces the inherited one once merged: list | ||
| // what it changes relative to the policy applied (relative to the defaults when | ||
| // no directory has one on the base branch). | ||
| const addedHere = | ||
| policy.source === "base" ? await headPolicyChanges(opts.cwd, policy.config) : policyHere.changedInPr | ||
| policy.changedInPr = [...new Set([...policy.changedInPr, ...addedHere])] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: A PR-added policy file in a non-project ancestor directory is never reported in The fallback walk visits every ancestor between the reviewed project and the repo root, but each Diff the nearest visited directory that has a head-side policy file against the applied policy (not only
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MINOR] A policy file the PR adds in a directory between the project and the applied ancestor is not reported in const addedHere =
policy.source === "base" ? await headPolicyChanges(opts.cwd, policy.config) : policyHere.changedInPr
policy.changedInPr = [...new Set([...policy.changedInPr, ...addedHere])]While the fallback loop walks up, Fix: for every directory skipped on the way up ( |
||
| } | ||
| const config = policy.config | ||
| if (policy.changedInPr.length) { | ||
| process.stderr.write( | ||
|
|
@@ -349,10 +371,12 @@ export async function reviewPullRequest(opts: ReviewPullRequestOptions): Promise | |
| } | ||
| // Map renamed files → their old path so getContent resolves the "old" side | ||
| // from where the file lived at `base`: in-scope files as scoped (a rename into | ||
| // the project is scoped as added), files outside the project as collected. | ||
| const prRenames = new Map( | ||
| collected.filter((f) => f.status === "renamed" && f.oldPath).map((f) => [f.path, f.oldPath as string]), | ||
| ) | ||
| // the project is scoped as added), files outside the project as collected or, | ||
| // when `changedFiles` is a subset, as the whole PR renamed them. | ||
| const prRenames = new Map([ | ||
| ...(opts.prRenames ?? []), | ||
| ...collected.filter((f) => f.status === "renamed" && f.oldPath).map((f) => [f.path, f.oldPath as string] as const), | ||
| ]) | ||
| const inScopePaths = new Set(changedFiles.map((f) => f.path)) | ||
| const renames = new Map([...prRenames].filter(([p]) => !inScopePaths.has(p))) | ||
| for (const f of changedFiles) if (f.status === "renamed" && f.oldPath) renames.set(f.path, f.oldPath) | ||
|
|
@@ -470,7 +494,7 @@ export async function reviewPullRequest(opts: ReviewPullRequestOptions): Promise | |
| const specs = projectGrepSpecs(projectRootRel, dirs, glob) | ||
| return specs ? grepFixedAt(gitRoot, opts.head, pattern, specs) : Promise.resolve(undefined) | ||
| }, | ||
| prFiles: collected.map((f) => f.path), | ||
| prFiles: opts.prFiles ?? collected.map((f) => f.path), | ||
| prRenames, | ||
| prTitle: opts.prTitle, | ||
| prBody: opts.prBody, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { cmd } from "./cmd" | |
| import { bootstrap } from "../bootstrap" | ||
| import { Installation } from "../../installation" | ||
| import { prContextFromEnv, reviewPullRequest } from "../../altimate/review/run" | ||
| import { reviewAllProjects } from "../../altimate/review/multi-project" | ||
| import { renderSummary } from "../../altimate/review/format" | ||
| import { postGitHubReview, resolveGitHubTarget } from "../../altimate/review/post-github" | ||
| // altimate_change — review feature telemetry | ||
|
|
@@ -70,6 +71,13 @@ export const ReviewCommand = cmd({ | |
| type: "string", | ||
| describe: "provider/model for the advisory AI lane (default: the configured default model)", | ||
| }) | ||
| .option("all-projects", { | ||
| type: "boolean", | ||
| default: false, | ||
| describe: | ||
| "review every dbt project the PR changes (mono-repo) and emit one merged verdict / one comment; " + | ||
| "--manifest then applies only to the project that contains it", | ||
| }) | ||
| .option("cwd", { type: "string", describe: "project directory (default: current dir)" }), | ||
| async handler(args) { | ||
| const cwd = (args.cwd as string) || process.cwd() | ||
|
|
@@ -100,7 +108,8 @@ export const ReviewCommand = cmd({ | |
| const prContext = await prContextFromEnv() | ||
| let env | ||
| try { | ||
| env = await reviewPullRequest({ | ||
| const review = args.allProjects === true ? reviewAllProjects : reviewPullRequest | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow-up: low priority, tracked. Discovering roots at the merge-base as well would cover it. |
||
| env = await review({ | ||
| ...prContext, | ||
| aiModel: args.aiModel as string | undefined, | ||
| cwd, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The project list is unbounded even though this renderer promises a character budget for the posted comment. With enough touched projects, this line alone can exceed 5,000 characters and the later finding-budget loop cannot trim it; cap the displayed roots and retain the full list in
scope.projects.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up: low priority, tracked. We'll cap it at
RENDER_CAPwith "+N more".