MR Review: create a new comment on the diff
Problem to solve
The extension only allows creating new comments on the "Details" webview
which means they are not related to any particular position. To replicate the GitLab web experience, this ~feature implements creating new comments in the MR diff view.
Proposal
Implement a command that will be triggered when the user clicks "Add comment now" button:
This command will create a new comment. It will support unchanged, removed, and added lines.
Further details
Creating comments
GraphQL mutation
mutation CreateDiffNote5 {
createDiffNote(
input: {
noteableId: "gid://gitlab/MergeRequest/87196674"
body: "new note"
position: {
baseSha: "5e6dffa282c5129aa67cd227a0429be21bfdaf80"
headSha: "a2616e0fea06c8b5188e4064a76d623afbf97b0c"
startSha: "5e6dffa282c5129aa67cd227a0429be21bfdaf80"
paths: { oldPath: "/test.js", newPath: "/test.ts" }
newLine: 15
}
}
) {
errors
}
}
All attributes are mandatory, except for the following exception regarding newLine
and oldLine
:
type of line we comment on | newLine, oldLine explained |
---|---|
added line (right-hand-side of the diff) | We only submit newLine
|
removed line (left-hand-side of the diff) | We only submit oldLine
|
unchanged line | Both newLine and oldLine are required. If the unchanged line has a different index on each side of the diff, these attributes need to reflect that different index. |
Representing the new comment in VS Code
The createDiffNote
mutation gives us only the new note as a response. But we need the full discussion
response because only the discussion contains replyId
attribute that allows us to submit replies.
In other words, without knowing the replyId
, we can create a new thread, but the user can't reply to that thread.
The only way how we can get it now is to ask for all discussions on MR and filter out the one that contains our new note.