Skip to content

Commit 7e13629

Browse files
committed
fix: remove invalid inReplyTo parameter in review comments
- Remove hardcoded inReplyTo parameter that caused GitHub API validation error - Only include line-specific parameters when needed - Add type safety with CreateReviewCommentParams interface
1 parent 86cdc64 commit 7e13629

File tree

1 file changed

+74
-14
lines changed

1 file changed

+74
-14
lines changed

src/cli/commands/helpers.ts

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '../../services/services.types';
99
import { VcsProvider } from '../../utils/git-service.interface';
1010
import { CodeReviewResult } from '../../providers/provider.types';
11+
import { CreateReviewCommentParams } from '../../services/services.types';
1112

1213
export interface ReviewResults {
1314
branchName?: CodeReviewResult[];
@@ -147,21 +148,80 @@ export async function outputToCIPlatform(
147148
return;
148149
}
149150

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+
);
151157

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+
}
165225
}
166226
}
167227

0 commit comments

Comments
 (0)