Discussions API - Missing fields for MR Multiline comments
<!--IssueSummary start--> <details> <summary> Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards. </summary> - [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=392800) </details> <!--IssueSummary end--> <!--- Please read this! Before opening a new issue, make sure to search for keywords in the issues filtered by the "regression" or "type::bug" label: - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug and verify the issue you're about to submit isn't a duplicate. ---> ### Summary <!-- Summarize the bug encountered concisely. --> When comparing multiline comments created by [the UI](https://docs.gitlab.com/ee/user/discussions/#add-a-comment-to-a-merge-request-diff) vs. [the API](https://docs.gitlab.com/ee/api/discussions.html#parameters-for-multiline-comments), the following fields are missing from an API created discussion: * `old_line` * `new_line` ### Steps to reproduce <!-- Describe how one can reproduce the issue - this is very important. Please use an ordered list. --> 1. [Create a multiline comment via the UI](https://docs.gitlab.com/ee/user/discussions/#add-a-comment-to-a-merge-request-diff) 2. [Create a multiline comment via the API](https://docs.gitlab.com/ee/api/discussions.html#parameters-for-multiline-comments) <details><summary>Example payload</summary> ```json { "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" } ``` </details> 3. Observe the differences visually and using the [List project merge request discussion items](https://docs.gitlab.com/ee/api/discussions.html#list-project-merge-request-discussion-items) endpoint ### Example Project <!-- If possible, please create an example project here on GitLab.com that exhibits the problematic behavior, and link to it here in the bug report. If you are using an older version of GitLab, this will also determine whether the bug is fixed in a more recent version. --> https://gitlab.com/gitlab-gold/jiocastillo/rust-test/-/merge_requests/2 ### What is the current *bug* behavior? <!-- Describe what actually happens. --> The missing fields cause the `Comment on lines x to y` UI component to not render. \ Sources: * [showMultiLineComment](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/assets/javascripts/notes/components/noteable_note.vue#L183-192) * [getLineNumber](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/assets/javascripts/notes/components/multiline_comment_utils.js#L11) ### What is the expected *correct* behavior? <!-- Describe what you should see instead. --> The `Comment on lines x to y` UI component to be rendered. ### Relevant logs and/or screenshots <!-- Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's tough to read otherwise. --> | UI | API | | ------ | ------ | | ![Screenshot_2023-02-21_at_12.29.55_PM](/uploads/744cab7d16dbf0ac99ad15195fac9967/Screenshot_2023-02-21_at_12.29.55_PM.png) | ![Screenshot_2023-02-21_at_12.35.02_PM](/uploads/09771926a714bf43f67c86b2ba5e1beb/Screenshot_2023-02-21_at_12.35.02_PM.png) | JSON objects obtained from the [List project merge request discussion items](https://docs.gitlab.com/ee/api/discussions.html#list-project-merge-request-discussion-items) endpoint: <details><summary>UI Notes Object</summary> ```json "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": {} } ] ``` </details> <details><summary>API Notes Object</summary> ```json "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": {} } ] ``` </details> ### Possible fixes <!-- If you can, link to the line of code that might be responsible for the problem. --> - Populate the fields when creating a discussion via API. - Modify the [`getLineNumber`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/assets/javascripts/notes/components/multiline_comment_utils.js#L22) function to use the line code `old` or `new` values if the fields are not present ```js let lineNumber = !oldLine ? lineRange[key].line_code.split('_')[1] : oldLine; if (lineType === 'new' || otherLineType === 'new') lineNumber = !newLine ? lineRange[key].line_code.split('_')[2] : newLine; ``` </details> Reported by ~customer in [Zendesk ticket](https://gitlab.zendesk.com/agent/tickets/361246)(internal)
issue