Skip to content

MR Review: track changed lines on the diff

Problem to solve

This issue is a follow up for #340 (closed) that might be not necessary to implement if the gitlab#325161 (closed) gets fixed.

This issue implements logic related to tracking which lines in the diff have been added/removed/unchanged. This feature needs to be behind a feature flag because we'll implement submitting new comments in a subsequent issue.

Commenting ranges

To be able to create new comments (not replies to a thread) we need to create a CommentingRangeProvider. We implement a function that receives a file URI and returns all the lines that the user can comment on.

Without these ranges, the user can only respond to existing comments (#339 (closed)).

Track changed lines on the diff

To be able to submit comments on unchanged lines, we also need to be able to track position of unchanged lines across both old and new diff version. The createDiffNote GraphQL mutation requires both oldLine and newLine for unchanged lines (this is an issue tracked in gitlab#325161 (closed)). The following image explains the information we must compute:

Extension_Development_Host_-_gitlab_comment_thread_test_ts___197____gitlab-vscode-extension-TEST

To be able to submit a comment for the it('deletes a comment', async () => { line, we need to compute that the line has the number 133 on the old version but 149 on the new.

Proposal

We'll need to use the textual diff that we retrieve from the MR Diff version API endpoint.

{
  "old_path": "new_file.ts",
  "new_path": "new_file.ts",
  "a_mode": "0",
  "b_mode": "100644",
  "new_file": true,
  "renamed_file": false,
  "deleted_file": false,
  "diff": "@@ -0,0 +1,3 @@\n+export class NewFile{\n+    private property: string;\n+}\n"
}

We'll have to praise the diff property to find all changed lines.

Further details

Example:

no ranges with ranges
gitlab_comment_thread_test_ts___197____gitlab-vscode-extension Extension_Development_Host_-_gitlab_comment_thread_test_ts___197____gitlab-vscode-extension-TEST

Links / references