Add diff context to comments in merge request notes API
Description
I'm trying to create a list of MR discussions (similar to one GitLab shows) relying on GitLab API.
Some items contain discussions with attached piece of source code which is rendered nicely on Gitlab.com. However GitLab API doesn't provide the code chunk and the corresponding position for comment notes.
Proposal
I'd like to propose to add an information about the corresponding code context to the note API:
GET /projects/:id/issues/:issue_iid/notes
New fields:
-
file_name
- the name of the changed file -
diff_chunk
- the source of the chunk the comment refers to. The content can be trimmed below the target line. -
position
- the position in the chunk the comments refers to.
Example
Let's say we want to request notes for https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10741 (just an example). There's a discussion which refers to lib/gitlab/markup_helper.rb line 44.
The result for request to GET /projects/:id/issues/:issue_iid/notes
endpoint should look like following:
[
{
"id": 305,
"body": "Decided to disable `Performance/Casecmp` in...",
"file_name": "lib/gitlab/markup_helper.rb", // new
"diff_chunk" : "@@ -39,12 +41,17 @@ module Gitlab" // new
"position": 44, // new
"attachment": null,
"author": {
"id": 1,
"username": "pipin",
"email": "admin@example.com",
"name": "Pip",
"state": "active",
"created_at": "2013-09-30T13:46:01Z"
},
"created_at": "2013-10-02T09:56:03Z",
"updated_at": "2013-10-02T09:56:03Z",
"system": true,
"noteable_id": 121,
"noteable_type": "Issue"
}
...
]
There are more things to discuss, but I wanted to get the ball rolling to get an initial feedback.
Links / references
https://docs.gitlab.com/ce/api/notes.html#list-all-merge-request-notes
P.S. Not sure if mentioning another issue as an example is a good idea.