Cannot create new merge request thread via API v4
Problem to solve
Hello everyone. I have to let user know that his MR is not supposed to be merged for some specific reason, and do that automatically via a cron job in k8s - so i have to use gitlab API. Since there are no way to lock MRs via API (there is another request from 2017 for that feature) i am trying to create new unresolved MR thread via API v4 using cUrl, but getting errors: "{"error":"position[line_range][start_line_code] is invalid, position[line_range][end_line_code] is invalid"}"
My API call looks like this :
curl -X POST --header "PRIVATE-TOKEN: private_token" -d 'body=comment
&position[base_sha]=4bc32d229d226054a6004b7f1e201fd1f4fa9672
&position[start_sha]=4bc32d229d226054a6004b7f1e201fd1f4fa9672
&position[head_sha]=4bc32d229d226054a6004b7f1e201fd1f4fa9672
&position[position_type]=text
&position[line_range][start_line_code][]=588440f66559714280628a4f9799f0c4eb880a4a_86_86
&position[line_range][end_line_code][]=588440f66559714280628a4f9799f0c4eb880a4a_87_87'
https://my_gitlab_server/api/v4/projects/project_id/merge_requests/mr_id/discussions
From the documentation i cannot understand what do i have to put in these 2 parameters: position[line_range][start_line_code] position[line_range][end_line_code] but they are necessary.
from the example in said documentation it looks like some SHA followed by code lines: "start_line_code": "588440f66559714280628a4f9799f0c4eb880a4a_10_10", "end_line_code": "588440f66559714280628a4f9799f0c4eb880a4a_11_11"
Could you clarify 2 things for me:
- What are those values?
- Can i create new MR thread without specifying the code lines just how i can do that via the UI?
In my API call i tried using commit SHA as values for position[line_range][start_line_code] and [position[line_range][end_line_code], but it didn't work.
Proposal
I have several things in mind that will improve API user experience:
- Update documentation on discussions API and add usage examples to eliminate all possible questions.
- Add more ways to create merge request threads via API, that do not require line codes, just like we can do from the UI.