2

i looked at the documentation but its hard to understand how it works.

This is my current restcall:

{
    "body": "Via Rest",
    "position": {
        "base_sha": "bcdfbfd57c8f3cd6cd65998464bb71a562d49948",
        "start_sha": "bcdfbfd57c8f3cd6cd65998464bb71a562d49948",
        "head_sha": "5828c8f62744f8c63d2e35cfb17988380a3a63d6",
        "new_path": "README.md",
        "position_type": "text",
        "line_range": {
            "start": {
                "line_code": "8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_0_6",
                "type": "new"
            },
            "end": {
                "line_code": "8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_0_11",
                "type": "new"
            }
        }
    }
}

The response is:

"message": "400 Bad request - Note {:line_code=>[\"can't be blank\", \"must be a valid line code\"], :position=>[\"is incomplete\"]}"

But what i dont understand is that line_code is not blank...

I also dont understand how the linecode itself works. I am adding a new comment, so SHA1HASH_OLDLINE_NEWLINE doesnt work as a format, since iam not referencing any old line. I looked at existing muliti line comments, but when i copy them (HASH_12_6 and HASH_12_11), it still returns the same error.

EDIT: Here is the api i have problems with.

https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread

After some testing i found out that the problem is probably NOT what the errors says.

If i create a normal merge request thread over a single line via this json:

{
    "body": "Via Postman",
    "position": {
        "position_type": "text",
        "base_sha": "bcdfbfd57c8f3cd6cd65998464bb71a562d49948",
        "head_sha": "5828c8f62744f8c63d2e35cfb17988380a3a63d6",
        "start_sha": "bcdfbfd57c8f3cd6cd65998464bb71a562d49948",
        "new_path": "src/main/java/com/example/demo/DemoApplication.java",
        "old_path": "src/main/java/com/example/demo/DemoApplication.java",
        "new_line": 1
    }
}

it also returns the same error, but if i switch the old_path & new_path to "README.md" it works.

Both files exist, but somehow the longer file is making problems.

EDIT: i figured out the issue. The problem is that new_line really needs to point to a new line (green line in PR view). If its not green i have to supply both new_line and old_line. If its a red line i have to supply old_line

Loading
  • 1,098
  • 1
  • 12
  • 25
  • Which endpoint are you referring to? Also please provide a link to the documentation that you have a hard time to understand. – cyberbrain Jan 22 '23 at 20:52
  • I can see in the documentation `base_sha` refer to source branch and `start_sha` refers to target branch. But in your request both are same – deadshot Jan 23 '23 at 19:30
  • it was an issue with the provided parameters. I updated the post – Loading Jan 25 '23 at 18:24

0 Answers0