Discussions API - Missing fields for MR Multiline comments

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

  • Close this issue

Summary

When comparing multiline comments created by the UI vs. the API, the following fields are missing from an API created discussion:

  • old_line
  • new_line

Steps to reproduce

  1. Create a multiline comment via the UI
  2. Create a multiline comment via the API
Example payload
{
    "position": {
        "position_type": "text",
        "base_sha": "484301b317d46853efe93175a062a9c0ff12ff51",
        "start_sha": "484301b317d46853efe93175a062a9c0ff12ff51",
        "head_sha": "0ce15e42c906d9d39956485098f309e60fc6776a",
        "old_path": "main.rs",
        "new_path": "main.rs",
        "new_line":"20",
        "line_range": {
            "start": {
                "line_code": "d28144c4832d52a64a74ddd6d29c1c182d228e1f_3_16",
                "type": "new"
            },
            "end": {
                "line_code": "d28144c4832d52a64a74ddd6d29c1c182d228e1f_3_20",
                "type": "new"
            }
        }
    },
    "body": "Multi-line API"
}
3. Observe the differences visually and using the List project merge request discussion items endpoint

Example Project

https://gitlab.com/gitlab-gold/jiocastillo/rust-test/-/merge_requests/2

What is the current bug behavior?

The missing fields cause the Comment on lines x to y UI component to not render.
Sources:

  • showMultiLineComment
  • getLineNumber

What is the expected correct behavior?

The Comment on lines x to y UI component to be rendered.

Relevant logs and/or screenshots

UI API
Screenshot_2023-02-21_at_12.29.55_PM Screenshot_2023-02-21_at_12.35.02_PM

JSON objects obtained from the List project merge request discussion items endpoint:

UI Notes Object
        "notes": [
            {
                "id": 1271401407,
                "type": "DiffNote",
                "body": "Multi-line UI",
                "attachment": null,
                "author": {
                    "id": 11346989,
                    "username": "j.castillo",
                    "name": "Jiovanni Castillo",
                    "state": "active",
                    "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/11346989/avatar.png",
                    "web_url": "https://gitlab.com/j.castillo"
                },
                "created_at": "2023-02-09T01:18:59.762Z",
                "updated_at": "2023-02-09T01:18:59.762Z",
                "system": false,
                "noteable_id": 204410955,
                "noteable_type": "MergeRequest",
                "commit_id": null,
                "position": {
                    "base_sha": "484301b317d46853efe93175a062a9c0ff12ff51",
                    "start_sha": "484301b317d46853efe93175a062a9c0ff12ff51",
                    "head_sha": "0ce15e42c906d9d39956485098f309e60fc6776a",
                    "old_path": "main.rs",
                    "new_path": "main.rs",
                    "position_type": "text",
                    "old_line": null,
                    "new_line": 20,
                    "line_range": {
                        "start": {
                            "line_code": "d28144c4832d52a64a74ddd6d29c1c182d228e1f_3_16",
                            "type": "new",
                            "old_line": null,
                            "new_line": 16
                        },
                        "end": {
                            "line_code": "d28144c4832d52a64a74ddd6d29c1c182d228e1f_3_20",
                            "type": "new",
                            "old_line": null,
                            "new_line": 20
                        }
                    }
                },
                "resolvable": true,
                "resolved": false,
                "resolved_by": null,
                "resolved_at": null,
                "confidential": false,
                "internal": false,
                "noteable_iid": 2,
                "commands_changes": {}
            }
        ]
API Notes Object
"notes": [
            {
                "id": 1287288045,
                "type": "DiffNote",
                "body": "Multi-line API",
                "attachment": null,
                "author": {
                    "id": 11346989,
                    "username": "j.castillo",
                    "name": "Jiovanni Castillo",
                    "state": "active",
                    "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/11346989/avatar.png",
                    "web_url": "https://gitlab.com/j.castillo"
                },
                "created_at": "2023-02-21T19:57:15.423Z",
                "updated_at": "2023-02-21T19:57:15.423Z",
                "system": false,
                "noteable_id": 204410955,
                "noteable_type": "MergeRequest",
                "commit_id": null,
                "position": {
                    "base_sha": "484301b317d46853efe93175a062a9c0ff12ff51",
                    "start_sha": "484301b317d46853efe93175a062a9c0ff12ff51",
                    "head_sha": "0ce15e42c906d9d39956485098f309e60fc6776a",
                    "old_path": "main.rs",
                    "new_path": "main.rs",
                    "position_type": "text",
                    "old_line": null,
                    "new_line": 20,
                    "line_range": {
                        "start": {
                            "line_code": "d28144c4832d52a64a74ddd6d29c1c182d228e1f_3_16",
                            "type": "new"
                        },
                        "end": {
                            "line_code": "d28144c4832d52a64a74ddd6d29c1c182d228e1f_3_20",
                            "type": "new"
                        }
                    }
                },
                "resolvable": true,
                "resolved": false,
                "resolved_by": null,
                "resolved_at": null,
                "confidential": false,
                "internal": false,
                "noteable_iid": 2,
                "commands_changes": {}
            }
        ]

Possible fixes

  • Populate the fields when creating a discussion via API.
  • Modify the getLineNumber function to use the line code old or new values if the fields are not present
  let lineNumber = !oldLine ? lineRange[key].line_code.split('_')[1] : oldLine;
  if (lineType === 'new' || otherLineType === 'new') lineNumber = !newLine ? lineRange[key].line_code.split('_')[2] : newLine;

Reported by customer in Zendesk ticket(internal)

Edited Aug 28, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading