also looking at this
fix(review): read what publishing reported, honour reviewSuggestions, and un-strand two flags
#1435
5 files
+267
-10
| @@ -42,14 +42,22 @@ export interface PreparedReview { | ||
| 42 | 42 | * as prose only, since a half-right suggestion costs more to undo than to |
| 43 | 43 | * write by hand. |
| 44 | 44 | * |
| 45 | * On a platform whose `reviewSuggestions` capability is false the block | |
| 46 | * renders as a plain code fence instead: Bitbucket shows a literal | |
| 47 | * suggestion fence as noise, and the one-click apply it promises does not | |
| 48 | * exist there. | |
| 49 | * | |
| 45 | 50 | * @param finding - Finding to render |
| 51 | * @param options - Whether the platform renders suggestion blocks (default: it does) | |
| 46 | 52 | */ |
| 47 | export function renderFinding(finding: ReviewFinding): string { | |
| 53 | export function renderFinding(finding: ReviewFinding, options?: { suggestions?: boolean }): string { | |
| 48 | 54 | const source = finding.tool ? ` \`[${finding.tool}]\`` : '' |
| 49 | 55 | let body = `**${SEVERITY_BADGE[finding.severity]}** · \`${finding.category}\`${source}\n\n${finding.message}` |
| 50 | 56 | |
| 51 | 57 | if (finding.suggestion) { |
| 52 | body += `\n\n\`\`\`suggestion\n${finding.suggestion}\n\`\`\`` | |
| 58 | body += options?.suggestions === false | |
| 59 | ? `\n\nSuggested replacement:\n\n\`\`\`\n${finding.suggestion}\n\`\`\`` | |
| 60 | : `\n\n\`\`\`suggestion\n${finding.suggestion}\n\`\`\`` | |
| 53 | 61 | } |
| 54 | 62 | |
| 55 | 63 | return body |
| @@ -70,13 +78,15 @@ export function prepareReview( | ||
| 70 | 78 | requestChangesOn?: 'never' | 'critical' |
| 71 | 79 | /** Fingerprints already reported, carried forward into the new state */ |
| 72 | 80 | seenFingerprints?: string[] |
| 81 | /** Whether the platform renders suggestion blocks (default: it does) */ | |
| 82 | suggestions?: boolean | |
| 73 | 83 | }, |
| 74 | 84 | ): PreparedReview { |
| 75 | 85 | const comments: InlineComment[] = result.findings.map(finding => ({ |
| 76 | 86 | path: finding.path, |
| 77 | 87 | line: finding.line, |
| 78 | 88 | side: 'RIGHT' as const, |
| 79 | body: renderFinding(finding), | |
| 89 | body: renderFinding(finding, { suggestions: options.suggestions !== false }), | |
| 80 | 90 | })) |
| 81 | 91 | |
| 82 | 92 | const counts = countBySeverity(result.findings) |