also looking at this
fix(review): read what publishing reported, honour reviewSuggestions, and un-strand two flags
#1435
5 files
+267
-10
| @@ -141,7 +141,11 @@ export async function reviewPullRequest(options: RunReviewOptions): Promise<Revi | ||
| 141 | 141 | effort: 1, |
| 142 | 142 | omittedFiles: [], |
| 143 | 143 | }, |
| 144 | { headSha, requestChangesOn: config.ai?.review?.requestChangesOn }, | |
| 144 | { | |
| 145 | headSha, | |
| 146 | requestChangesOn: config.ai?.review?.requestChangesOn, | |
| 147 | suggestions: provider.capabilities().reviewSuggestions, | |
| 148 | }, | |
| 145 | 149 | ) |
| 146 | 150 | |
| 147 | 151 | const staticResult: ReviewResult = { |
| @@ -158,9 +162,15 @@ export async function reviewPullRequest(options: RunReviewOptions): Promise<Revi | ||
| 158 | 162 | } |
| 159 | 163 | |
| 160 | 164 | 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 | ||
| 162 | 169 | 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 | } | |
| 164 | 174 | } |
| 165 | 175 | |
| 166 | 176 | // Guidelines and learnings are read from the base branch: both are inlined |
| @@ -196,6 +206,7 @@ export async function reviewPullRequest(options: RunReviewOptions): Promise<Revi | ||
| 196 | 206 | headSha, |
| 197 | 207 | requestChangesOn: config.ai?.review?.requestChangesOn, |
| 198 | 208 | seenFingerprints: options.full ? [] : state?.fingerprints ?? [], |
| 209 | suggestions: provider.capabilities().reviewSuggestions, | |
| 199 | 210 | }) |
| 200 | 211 | |
| 201 | 212 | if (options.dryRun) { |
| @@ -204,17 +215,50 @@ export async function reviewPullRequest(options: RunReviewOptions): Promise<Revi | ||
| 204 | 215 | } |
| 205 | 216 | |
| 206 | 217 | 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 | ||
| 208 | 226 | await persistReviewState(provider, prNumber, pr.body, prepared.state, state?.paused, logger) |
| 209 | 227 | |
| 210 | 228 | return { |
| 211 | 229 | status: result.findings.length === 0 |
| 212 | 230 | ? 'Reviewed — nothing to report.' |
| 213 | : `Reviewed — ${result.findings.length} finding(s) posted.`, | |
| 231 | : `Reviewed — ${result.findings.length} finding(s) posted.${placementNote(submission, prepared, logger)}`, | |
| 214 | 232 | result, |
| 215 | 233 | } |
| 216 | 234 | } |
| 217 | 235 | |
| 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 | */ | |
| 249 | function 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 | ||
| 218 | 262 | /** |
| 219 | 263 | * Review a pull request end to end and post the result. |
| 220 | 264 | * |