Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab API to post inline comment to Merge Request

Tags:

gitlab

Using GitLab API it is possible to post a comment to a commit "on a particular line of a particular file" (see here).

On Merge Request in order to add comments it's required to use the notes resource (see here) but the note object does not seem to contain any parameter to comment on a particular line.

However from the GitLab UI I'm able to add inline comments to a Merge Request in the Changes tab but when I call the API and look at the corresponding note object created from my inline comment there is nothing about the inline, it is only a regular note object without any line or line_type parameter...

Anyone knows how to use the GitLab API to add inline comments to a Merge Request ?

like image 340
stour Avatar asked Jan 17 '17 14:01

stour


People also ask

How do I comment multiple lines in GitLab?

Users can now click at the beginning of a line and drag the comment marker across multiple lines to highlight and reference multiple lines when leaving feedback in an MR.


1 Answers

In order to add inline comments for merge requests, there is Discussions API: https://docs.gitlab.com/ce/api/discussions.html

Each discussion can contain a position in the code, like that:

    "position": {
      "base_sha": "b5d6e7b1613fca24d250fa8e5bc7bcc3dd6002ef",
      "start_sha": "7c9c2ead8a320fb7ba0b4e234bd9529a2614e306",
      "head_sha": "4803c71e6b1833ca72b8b26ef2ecd5adc8a38031",
      "old_path": "package.json",
      "new_path": "package.json",
      "position_type": "text",
      "old_line": 27,
      "new_line": 27
    },
like image 173
Dmitry Frank Avatar answered Oct 10 '22 17:10

Dmitry Frank