Commit 17fd0e5c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #6569 from criteo/api_merge_request_comments

Add method to get the comments on a merge request
parents af0b59d4 9886998f
...@@ -150,6 +150,7 @@ Parameters: ...@@ -150,6 +150,7 @@ Parameters:
+ `target_branch` - The target branch + `target_branch` - The target branch
+ `assignee_id` - Assignee user ID + `assignee_id` - Assignee user ID
+ `title` - Title of MR + `title` - Title of MR
+ `state_event` - New state (close|reopen|merge)
```json ```json
...@@ -210,3 +211,44 @@ Parameters: ...@@ -210,3 +211,44 @@ Parameters:
"note":"text1" "note":"text1"
} }
``` ```
## Get the comments on a MR
Gets all the comments associated with a merge request.
```
GET /projects/:id/merge_request/:merge_request_id/comments
```
Parameters:
+ `id` (required) - The ID of a project
+ `merge_request_id` (required) - ID of merge request
```json
[
{
"note":"this is the 1st comment on the 2merge merge request",
"author":{
"id":11,
"username":"admin",
"email":"admin@local.host",
"name":"Administrator",
"state":"active",
"created_at":"2014-03-06T08:17:35.000Z"
}
},
{
"note":"_Status changed to closed_",
"author":{
"id":11,
"username":"admin",
"email":"admin@local.host",
"name":"Administrator",
"state":"active",
"created_at":"2014-03-06T08:17:35.000Z"
}
}
]
```
...@@ -125,6 +125,22 @@ module API ...@@ -125,6 +125,22 @@ module API
end end
end end
# Get a merge request's comments
#
# Parameters:
# id (required) - The ID of a project
# merge_request_id (required) - ID of MR
# Examples:
# GET /projects/:id/merge_request/:merge_request_id/comments
#
get ":id/merge_request/:merge_request_id/comments" do
merge_request = user_project.merge_requests.find(params[:merge_request_id])
authorize! :read_merge_request, merge_request
present paginate(merge_request.notes), with: Entities::MRNote
end
# Post comment to merge request # Post comment to merge request
# #
# Parameters: # Parameters:
......
...@@ -7,6 +7,7 @@ describe API::API do ...@@ -7,6 +7,7 @@ describe API::API do
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project) {create(:project, creator_id: user.id, namespace: user.namespace) } let!(:project) {create(:project, creator_id: user.id, namespace: user.namespace) }
let!(:merge_request) { create(:merge_request, author: user, assignee: user, source_project: project, target_project: project, title: "Test") } let!(:merge_request) { create(:merge_request, author: user, assignee: user, source_project: project, target_project: project, title: "Test") }
let!(:note) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "a comment on a MR") }
before { before {
project.team << [user, :reporters] project.team << [user, :reporters]
} }
...@@ -205,4 +206,20 @@ describe API::API do ...@@ -205,4 +206,20 @@ describe API::API do
response.status.should == 404 response.status.should == 404
end end
end end
describe "GET :id/merge_request/:merge_request_id/comments" do
it "should return merge_request comments" do
get api("/projects/#{project.id}/merge_request/#{merge_request.id}/comments", user)
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 1
json_response.first['note'].should == "a comment on a MR"
json_response.first['author']['id'].should == user.id
end
it "should return a 404 error if merge_request_id not found" do
get api("/projects/#{project.id}/merge_request/999/comments", user)
response.status.should == 404
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment