Create new merge request thread API not working for multiline comments

Summary

Issue: Multiline comment can't be created using Create new merge request thread endpoint.

Steps to reproduce

Call the endpoint to create a multiline comment for your MR:

curl --request POST --header "PRIVATE-TOKEN: <token>" \
     --header "Content-Type: application/json" \
     --data '{
       "body": "Comment",
       "position": {
         "base_sha": "f15b32277d2c55c6c595845a87109b09c913c556",
         "start_sha": "f15b32277d2c55c6c595845a87109b09c913c556",
         "head_sha": "aca6050ec8555d661c6818813047cbd6e1e7ca69",
         "new_path": "README.md",
         "old_path": "README.md",
         "position_type": "text",
         "new_line":"14",
         "line_range": {
           "start": { "type": "new","old_line":null,"new_line":"6", "line_code": "8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_6_6" },
           "end": { "type": "new","old_line":null,"new_line":"14", "line_code": "8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_6_14" }
         }
       }
     }' \
     "http://localhost:3000/api/v4/projects/7/merge_requests/11/discussions"

What is the current bug behavior?

The above endpoint will return and error {"message":"400 Bad request - Note {:position=>[\"must be a valid json schema\"]}"}

What is the expected correct behavior?

It should create a comment on lines 6-14 for the README.md file

Possible fixes

The problem is in the endpoint the type is String for old_line and new_line but it should be an Integer for the DiffNote to be valid.

optional :old_line, **type: String**, desc: 'Start old_line line number'
optional :new_line, **type: String**, desc: 'Start new_line line number'

The same service app/services/notes/create_service.rb is being called for when

  • we use the above endpoint
  • or when we add a multiline comment from UI (which works as expected)

The only difference is from the UI the old_line and new_line are Integers and not Strings.

Fixing the types in the endpoint it fixes the issue and the comment can be created.

Edited by 🤖 GitLab Bot 🤖