fix(gitlab): submit review comments on context lines #6348
Mergedtarik02(GitHub profile, opens in a new tab)merged 9 commits into
main fromrefs/pull/6348/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- packages/contracts/src/pullRequest.ts line 888Resolvedby tarik02(GitHub profile, opens in a new tab)@@ -619,5 +639,4 @@619639 * the hosts that address a comment by one path ignore this.620640 */621641 oldPath: Schema.optional(TrimmedNonEmptyString),622- line: PositiveInt,623- side: PullRequestDiffSide,642+ position: PullRequestReviewPosition,apps/web/src/components/pullRequest/PullRequestCodeTab.tsx lines 618 to 619Resolvedby tarik02(GitHub profile, opens in a new tab)@@ -552,3 +573,5 @@552573 // that silently lost its first line on the other hosts would be worse than one line.553574 const path = resolveFileDiffPath(file);554575 const previousPath = resolveFileDiffPreviousPath(file);576+ const position = resolveDiffReviewPosition(file, range.end, range.endSide ?? range.side);577+ if (position === null) return;
- apps/web/src/reviewCommentContext.ts line 430OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -372,0 +410,21 @@410+411+ if (hunk === undefined) return null;412+ oldContextStart = oldContextEnd + hunk.deletionCount;413+ newContextStart = newContextEnd + hunk.additionCount;414+ }415+416+ return null;417+}418+419+/** Resolve the host-facing coordinates of a line selected in the diff viewer. */420+export function resolveDiffReviewPosition(421+ fileDiff: FileDiffMetadata,422+ lineNumber: number,423+ side: SelectionSide | undefined,424+): PullRequestReviewPosition | null {425+ const lines = buildDiffReviewLines(fileDiff);426+ const preferredKey = side === "deletions" ? "oldLineNumber" : "newLineNumber";427+ const preferredIndex = lines.findIndex((line) => line[preferredKey] === lineNumber);428+ if (preferredIndex < 0) {429+ const expandedPosition = resolveExpandedContextPosition(fileDiff, lineNumber, side);430+ if (expandedPosition !== null) return expandedPosition;
- apps/web/src/reviewCommentContext.ts line 360OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -321 +340,21 @@321340 }341+342+ oldContextStart = hunk.deletionStart + hunk.deletionCount;343+ newContextStart = hunk.additionStart + hunk.additionCount;344+ if (hunk.deletionCount === 0) oldContextStart += 1;345+ if (hunk.additionCount === 0) newContextStart += 1;346+ }347+348+ if (!fileDiff.isPartial) {349+ const trailingLines = Math.min(350+ fileDiff.deletionLines.length - oldContextStart + 1,351+ fileDiff.additionLines.length - newContextStart + 1,352+ );353+ for (let offset = 0; offset < trailingLines; offset += 1) {354+ rows.push({355+ change: "context",356+ oldLineNumber: oldContextStart + offset,357+ newLineNumber: newContextStart + offset,358+ content: stripTrailingNewline(fileDiff.additionLines[newContextStart + offset - 1] ?? ""),359+ });360+ }
- apps/web/src/reviewCommentContext.ts line 430OutdatedResolvedby tarik02(GitHub profile, opens in a new tab)@@ -370,3 +421,10 @@370421 return lines.findIndex((line) => line[fallbackKey] === lineNumber);371422 }372423424+/** Resolve the host-facing coordinates of a line selected in the diff viewer. */425+export function resolveDiffReviewPosition(426+ fileDiff: FileDiffMetadata,427+ lineNumber: number,428+ side: SelectionSide | undefined,429+): PullRequestReviewPosition | null {430+ const lines = buildDiffReviewLines(fileDiff);
- apps/web/src/reviewCommentContext.ts lines 293 to 294OutdatedResolvedby tarik02(GitHub profile, opens in a new tab)@@ -267,7 +278,17 @@267278 return value.endsWith("\n") ? value.slice(0, -1) : value;268279 }269280270-function buildDiffReviewLines(fileDiff: FileDiffMetadata): ReadonlyArray<DiffReviewLine> {281+function buildDiffReviewLines(282+ fileDiff: FileDiffMetadata,283+ includeExpandedContext = !fileDiff.isPartial,284+): ReadonlyArray<DiffReviewLine> {271285 const rows: DiffReviewLine[] = [];286+ let oldContextStart = 1;287+ let newContextStart = 1;272288273289 for (const hunk of fileDiff.hunks) {290+ if (includeExpandedContext) {291+ const oldHunkStart = hunk.deletionStart + (hunk.deletionCount === 0 ? 1 : 0);292+ const newHunkStart = hunk.additionStart + (hunk.additionCount === 0 ? 1 : 0);293+ const contextLines = Math.min(oldHunkStart - oldContextStart, newHunkStart - newContextStart);294+ for (let offset = 0; offset < contextLines; offset += 1) {
- apps/web/src/reviewCommentContext.ts line 542Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -370,0 +522,21 @@522+ const line = buildDiffReviewLines(fileDiff, !fileDiff.isPartial, {523+ startIndex: lineIndex,524+ endIndex: lineIndex,525+ })[0];526+ if (line === undefined) return null;527+528+ switch (line.change) {529+ case "add":530+ return line.newLineNumber === null ? null : { kind: "added", newLine: line.newLineNumber };531+ case "delete":532+ return line.oldLineNumber === null ? null : { kind: "deleted", oldLine: line.oldLineNumber };533+ case "context":534+ return line.oldLineNumber === null || line.newLineNumber === null535+ ? null536+ : {537+ kind: "context",538+ oldLine: line.oldLineNumber,539+ newLine: line.newLineNumber,540+ side: side === "deletions" ? "left" : "right",541+ };542+ }
- @@ -370,0 +522,21 @@522+ const line = buildDiffReviewLines(fileDiff, !fileDiff.isPartial, {523+ startIndex: lineIndex,524+ endIndex: lineIndex,525+ })[0];526+ if (line === undefined) return null;527+528+ switch (line.change) {529+ case "add":530+ return line.newLineNumber === null ? null : { kind: "added", newLine: line.newLineNumber };531+ case "delete":532+ return line.oldLineNumber === null ? null : { kind: "deleted", oldLine: line.oldLineNumber };533+ case "context":534+ return line.oldLineNumber === null || line.newLineNumber === null535+ ? null536+ : {537+ kind: "context",538+ oldLine: line.oldLineNumber,539+ newLine: line.newLineNumber,540+ side: side === "deletions" ? "left" : "right",541+ };542+ }
juliusmarminge merged thisd94fbda
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
ff4afb83-1e53-4bc5-be47-9a503a5e4d98You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share