ReviewOS

also looking at this

stacks/buddy

fix(review): read what publishing reported, honour reviewSuggestions, and un-strand two flags

#1435
Merged glennmichael123 wants to merge fix/review-low-tier into main
5 files +267 -10
src/review/run.tsmodified+49-5
Changes to src/review/run.ts
@@ -141,7 +141,11 @@ export async function reviewPullRequest(options: RunReviewOptions): Promise<Revi
141141 effort: 1,
142142 omittedFiles: [],
143143 },
144 { headSha, requestChangesOn: config.ai?.review?.requestChangesOn },
144 {
145 headSha,
146 requestChangesOn: config.ai?.review?.requestChangesOn,
147 suggestions: provider.capabilities().reviewSuggestions,
148 },
145149 )
146150
147151 const staticResult: ReviewResult = {
@@ -158,9 +162,15 @@ export async function reviewPullRequest(options: RunReviewOptions): Promise<Revi
158162 }
159163
160164 assertSupports(provider, 'inlineReviewComments', 'createReview', 'posting a review')
161 await provider.createReview(prNumber, prepared)
165 const submission = await provider.createReview(prNumber, prepared)
166 if (!submission.posted)
167 return { status: 'The review could not be posted.', result: staticResult }
168
162169 await persistReviewState(provider, prNumber, pr.body, prepared.state, state?.paused, logger)
163 return { status: `Posted ${analysis.findings.length} static-analysis finding(s).`, result: staticResult }
170 return {
171 status: `Posted ${analysis.findings.length} static-analysis finding(s).${placementNote(submission, prepared, logger)}`,
172 result: staticResult,
173 }
164174 }
165175
166176 // Guidelines and learnings are read from the base branch: both are inlined
@@ -196,6 +206,7 @@ export async function reviewPullRequest(options: RunReviewOptions): Promise<Revi
196206 headSha,
197207 requestChangesOn: config.ai?.review?.requestChangesOn,
198208 seenFingerprints: options.full ? [] : state?.fingerprints ?? [],
209 suggestions: provider.capabilities().reviewSuggestions,
199210 })
200211
201212 if (options.dryRun) {
@@ -204,17 +215,50 @@ export async function reviewPullRequest(options: RunReviewOptions): Promise<Revi
204215 }
205216
206217 assertSupports(provider, 'inlineReviewComments', 'createReview', 'posting a review')
207 await provider.createReview(prNumber, prepared)
218 const submission = await provider.createReview(prNumber, prepared)
219
220 // A review that never landed must not be recorded as this commit's review:
221 // persisting the state anyway would make every later run skip a review
222 // nobody can see.
223 if (!submission.posted)
224 return { status: 'The review could not be posted.', result }
225
208226 await persistReviewState(provider, prNumber, pr.body, prepared.state, state?.paused, logger)
209227
210228 return {
211229 status: result.findings.length === 0
212230 ? 'Reviewed — nothing to report.'
213 : `Reviewed — ${result.findings.length} finding(s) posted.`,
231 : `Reviewed — ${result.findings.length} finding(s) posted.${placementNote(submission, prepared, logger)}`,
214232 result,
215233 }
216234}
217235
236/**
237 * Describe inline comments the platform dropped, or nothing.
238 *
239 * `createReview` reports how many line-anchored comments were actually
240 * placed. A comment anchored to a line outside the diff is dropped by the
241 * platform, and a review that silently loses findings reads as cleaner than
242 * it is.
243 *
244 * @param submission - What the provider reports it published
245 * @param prepared - What was asked for
246 * @param logger - Logger for the warning
247 * @returns A sentence to append to the status, or an empty string
248 */
249function placementNote(
250 submission: { inlineComments: number },
251 prepared: PreparedReview,
252 logger: Logger,
253): string {
254 const dropped = prepared.comments.length - submission.inlineComments
255 if (dropped <= 0)
256 return ''
257
258 logger.warn(`⚠️ ${dropped} of ${prepared.comments.length} inline comment(s) could not be placed on the diff`)
259 return ` ${dropped} of ${prepared.comments.length} inline comment(s) could not be placed on the diff.`
260}
261
218262/**
219263 * Review a pull request end to end and post the result.
220264 *