API to post suggestions on Merge Request

Hi there!

I want to create comments on the merge request view on a specific line. More specifically, I want to create a suggestion (a merge request comment inside the ```suggestion tag like the one at https://gitlab.com/axeit/eslint-example/-/merge_requests/1#note_487689068).

I am only able to create those manually, I was expecting to be able create a comment via API where the text of that body would be wrapped on the ```suggestion tag.

It seems that the way to create comments on Merge Requests don’t accept line as field:
https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note
So any comment made with that API just exists as a comment not part of the code.

Also tried to use https://docs.gitlab.com/ee/api/commits.html#post-comment-to-commit to comment on the latest commit of a Merge Request, which would be fine, except for the fact that the ```suggestion tag does not work on commit comments.

Anyone has any suggestion on how can I have suggestions on a Merge Request via API?

Thx!

9 Likes

Hello,

Here is what you are searching for.
The problem I can’t figure out is that I can’t retrieve environment variables for base_sha, start_sha and head_sha, (CI_MERGE_REQUEST_DIFF_BASE_SHA, CI_MERGE_REQUEST_SOURCE_BRANCH_SHA, CI_MERGE_REQUEST_TARGET_BRANCH_SHA) which are required to use position, within my runner. I can only make this work by calling this endpoint from my computer for now.

Interesting! I missed your reply, thx!

We changed to GitHub when we questioned here, as we didn’t managed to make it work. But eventually we want to try it again on GitLab, with your suggestion. I think we already have some of that information from the API, so maybe it won’t be a blocker.

Sounds very promising, so once again, thank you very much!