Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a GitLab line_code as referenced when creating a new merge request thread

I'm trying to create a discussion note on a merge request on a certain line of a file with the GitLab api using this endpoint: https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread

Part of the payload asks for a line_code

Attribute Type Required Description
position[line_range][start][line_code] string yes Line code for the start line

When I issue a POST I get a response with:

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

What is this line_code? Is it some kind of calculated value? The documentation is rather vague here.

When I issue a GET for all the current notes on a merge_request I can see some notes have this line_code (see below). I'm trying to figure out how to create that value for new notes.

 {
        "id": 89,
        "type": "DiffNote",
        "body": "4",
        "attachment": null,
        "author": {
            "id": 6,
            "name": "brian c",
            "username": "bc",
            "state": "active",
            "avatar_url": "https://www.gravatar.com/avatar/f590a9cf57136732dd0cb5z9b1563390?s=80&d=identicon",
            "web_url": "http://gitlab.mycompany.us/thisIsMe"
        },
        "created_at": "2021-01-11T21:46:23.861Z",
        "updated_at": "2021-01-11T21:46:23.861Z",
        "system": false,
        "noteable_id": 21,
        "noteable_type": "MergeRequest",
        "position": {
            "base_sha": "3bf8094f0d54fc70a66698bd582f25c77243de3b",
            "start_sha": "3bf8094f0d54fc70a66698bd582f25c77243de3b",
            "head_sha": "a10e73cf84eae38286df56f4b58fa221d7eefc44",
            "old_path": "b.txt",
            "new_path": "b.txt",
            "position_type": "text",
            "old_line": null,
            "new_line": 4,
            "line_range": {
                "start": {
                    "line_code": "aceba96ffdf13ce4cd4171c0248420cc03108ef0_0_4",
                    "type": "new",
                    "old_line": null,
                    "new_line": 4
                },
                "end": {
                    "line_code": "aceba96ffdf13ce4cd4171c0248420cc03108ef0_0_4",
                    "type": "new",
                    "old_line": null,
                    "new_line": 4
                }
            }
        },
        "resolvable": true,
        "resolved": false,
        "resolved_by": null,
        "confidential": false,
        "noteable_iid": 3,
        "commands_changes": {}
    },
like image 292
brianc Avatar asked Jan 27 '21 19:01

brianc


People also ask

How do you create merge request for specific commit in GitLab?

You can, however, create a new branch from your master branch, cherry-pick the single commit, and create a merge request for that branch, containing only the one commit. If you do not need the other commits any more, you can also consider an interactive rebase, to remove the unwanted commits from the branch.

How do I start a thread in GitLab?

On the top bar, select Menu > Projects and find your project. On the left sidebar, select Repository > Commits. Below the commits, in the Comment field, enter a comment. Select Comment or select the down arrow ( ) to select Start thread.

How do I update a merge request?

Revise a merge request If you need to update a merge request (for example in response to a request from the review shifter), simply push to the same branch again after editing (and testing) the files.


Video Answer


1 Answers

Line code is hash of the file name + underscore + old line number + underscore + new line number

The documentation is wrong. line_code is required only if you are using position.line_range which is only required for adding diff note spanning multiple lines of diff. You don't need to deal with line_code for single-line diff notes. So it is not a required parameter. You can just use position.old_line or position.new_line.

like image 193
Shashank V Avatar answered Sep 25 '22 19:09

Shashank V