|
8 | 8 | } from '../../services/services.types'; |
9 | 9 | import { VcsProvider } from '../../utils/git-service.interface'; |
10 | 10 | import { CodeReviewResult } from '../../providers/provider.types'; |
| 11 | +import { CreateReviewCommentParams } from '../../services/services.types'; |
11 | 12 |
|
12 | 13 | export interface ReviewResults { |
13 | 14 | branchName?: CodeReviewResult[]; |
@@ -147,21 +148,80 @@ export async function outputToCIPlatform( |
147 | 148 | return; |
148 | 149 | } |
149 | 150 |
|
150 | | - const body = formatReviewResultsAsMarkdown(results.codeChanges); |
| 151 | + // Separate general and line-specific suggestions |
| 152 | + const generalSuggestions = results.codeChanges.filter((result) => |
| 153 | + result.suggestions.some( |
| 154 | + (suggestion) => suggestion.reviewType !== 'line-specific', |
| 155 | + ), |
| 156 | + ); |
151 | 157 |
|
152 | | - await context.gitService.createReviewComment({ |
153 | | - owner: context.prDetails.owner, |
154 | | - repo: context.prDetails.repo, |
155 | | - pullNumber: context.prDetails.pullNumber, |
156 | | - body, |
157 | | - commitId: context.prDetails.commitId, |
158 | | - path: context.prDetails.path, |
159 | | - line: 1, |
160 | | - side: 'RIGHT', |
161 | | - startLine: 1, |
162 | | - startSide: 'RIGHT', |
163 | | - inReplyTo: 1, |
164 | | - }); |
| 158 | + const lineSpecificSuggestions = results.codeChanges.filter((result) => |
| 159 | + result.suggestions.some( |
| 160 | + (suggestion) => suggestion.reviewType === 'line-specific', |
| 161 | + ), |
| 162 | + ); |
| 163 | + |
| 164 | + // Create general review comment if there are general suggestions |
| 165 | + if (generalSuggestions.length > 0) { |
| 166 | + const body = formatReviewResultsAsMarkdown(generalSuggestions); |
| 167 | + const reviewCommentParams: CreateReviewCommentParams = { |
| 168 | + owner: context.prDetails.owner, |
| 169 | + repo: context.prDetails.repo, |
| 170 | + pullNumber: context.prDetails.pullNumber, |
| 171 | + body, |
| 172 | + commitId: context.prDetails.commitId, |
| 173 | + path: context.prDetails.path, |
| 174 | + }; |
| 175 | + await context.gitService.createReviewComment(reviewCommentParams); |
| 176 | + } |
| 177 | + |
| 178 | + // Create line-specific review comments |
| 179 | + for (const result of lineSpecificSuggestions) { |
| 180 | + for (const suggestion of result.suggestions) { |
| 181 | + if ( |
| 182 | + suggestion.reviewType === 'line-specific' && |
| 183 | + suggestion.line && |
| 184 | + suggestion.filename |
| 185 | + ) { |
| 186 | + const body = formatReviewResultsAsMarkdown([ |
| 187 | + { |
| 188 | + ...result, |
| 189 | + suggestions: [suggestion], |
| 190 | + }, |
| 191 | + ]); |
| 192 | + |
| 193 | + // Base parameters for all review comments |
| 194 | + const reviewCommentParams: CreateReviewCommentParams = { |
| 195 | + owner: context.prDetails.owner, |
| 196 | + repo: context.prDetails.repo, |
| 197 | + pullNumber: context.prDetails.pullNumber, |
| 198 | + body, |
| 199 | + commitId: context.prDetails.commitId, |
| 200 | + path: suggestion.filename, |
| 201 | + line: suggestion.line, |
| 202 | + side: 'RIGHT', |
| 203 | + }; |
| 204 | + |
| 205 | + // Add multi-line parameters if startLine is provided and different from line |
| 206 | + if ( |
| 207 | + suggestion.startLine && |
| 208 | + suggestion.startLine !== suggestion.line |
| 209 | + ) { |
| 210 | + // Ensure startLine is less than line for multi-line comments |
| 211 | + const startLine = Math.min(suggestion.startLine, suggestion.line); |
| 212 | + const endLine = Math.max(suggestion.startLine, suggestion.line); |
| 213 | + |
| 214 | + Object.assign(reviewCommentParams, { |
| 215 | + startLine, |
| 216 | + startSide: 'RIGHT', |
| 217 | + line: endLine, |
| 218 | + }); |
| 219 | + } |
| 220 | + |
| 221 | + await context.gitService.createReviewComment(reviewCommentParams); |
| 222 | + } |
| 223 | + } |
| 224 | + } |
165 | 225 | } |
166 | 226 | } |
167 | 227 |
|
|
0 commit comments