Commit 8dd2188b authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '2954-api-expose-issue-user_notes_count' into 'master'

API: Expose Issue#user_notes_count and MergeRequest#user_notes_count

_Originally opened at !2954 by @cnam812._

- - -

Expose `Issue#user_notes_count` and `MergeRequest#user_notes_count` through the API.

See merge request !3126
parents d4d34b16 f5240f97
...@@ -25,6 +25,7 @@ v 8.8.0 (unreleased) ...@@ -25,6 +25,7 @@ v 8.8.0 (unreleased)
- Added button to toggle whitespaces changes on diff view - Added button to toggle whitespaces changes on diff view
- Backport GitHub Enterprise import support from EE - Backport GitHub Enterprise import support from EE
- Create tags using Rugged for performance reasons. !3745 - Create tags using Rugged for performance reasons. !3745
- API: Expose Issue#user_notes_count. !3126 (Anton Popov)
- Files over 5MB can only be viewed in their raw form, files over 1MB without highlighting !3718 - Files over 5MB can only be viewed in their raw form, files over 1MB without highlighting !3718
- Add support for supressing text diffs using .gitattributes on the default branch (Matt Oakes) - Add support for supressing text diffs using .gitattributes on the default branch (Matt Oakes)
- Added multiple colors for labels in dropdowns when dups happen. - Added multiple colors for labels in dropdowns when dups happen.
......
...@@ -160,6 +160,10 @@ module Issuable ...@@ -160,6 +160,10 @@ module Issuable
notes.awards.where(note: "thumbsup").count notes.awards.where(note: "thumbsup").count
end end
def user_notes_count
notes.user.count
end
def subscribed_without_subscriptions?(user) def subscribed_without_subscriptions?(user)
participants(user).include?(user) participants(user).include?(user)
end end
......
...@@ -28,14 +28,8 @@ ...@@ -28,14 +28,8 @@
= downvotes = downvotes
- note_count = issue.notes.user.nonawards.count - note_count = issue.notes.user.nonawards.count
- if note_count > 0
%li %li
= link_to issue_path(issue) + "#notes" do = link_to issue_path(issue, anchor: 'notes'), class: ('issue-no-comments' if note_count.zero?) do
= icon('comments')
= note_count
- else
%li
= link_to issue_path(issue) + "#notes", class: "issue-no-comments" do
= icon('comments') = icon('comments')
= note_count = note_count
......
...@@ -36,14 +36,8 @@ ...@@ -36,14 +36,8 @@
= downvotes = downvotes
- note_count = merge_request.mr_and_commit_notes.user.nonawards.count - note_count = merge_request.mr_and_commit_notes.user.nonawards.count
- if note_count > 0
%li %li
= link_to merge_request_path(merge_request) + "#notes" do = link_to merge_request_path(merge_request, anchor: 'notes'), class: ('merge-request-no-comments' if note_count.zero?) do
= icon('comments')
= note_count
- else
%li
= link_to merge_request_path(merge_request) + "#notes", class: "merge-request-no-comments" do
= icon('comments') = icon('comments')
= note_count = note_count
......
...@@ -77,7 +77,8 @@ Example response: ...@@ -77,7 +77,8 @@ Example response:
"created_at" : "2016-01-04T15:31:51.081Z", "created_at" : "2016-01-04T15:31:51.081Z",
"iid" : 6, "iid" : 6,
"labels" : [], "labels" : [],
"subscribed" : false "subscribed" : false,
"user_notes_count": 1
} }
] ]
``` ```
...@@ -154,7 +155,8 @@ Example response: ...@@ -154,7 +155,8 @@ Example response:
"title" : "Ut commodi ullam eos dolores perferendis nihil sunt.", "title" : "Ut commodi ullam eos dolores perferendis nihil sunt.",
"updated_at" : "2016-01-04T15:31:46.176Z", "updated_at" : "2016-01-04T15:31:46.176Z",
"created_at" : "2016-01-04T15:31:46.176Z", "created_at" : "2016-01-04T15:31:46.176Z",
"subscribed" : false "subscribed" : false,
"user_notes_count": 1
} }
] ]
``` ```
...@@ -216,7 +218,8 @@ Example response: ...@@ -216,7 +218,8 @@ Example response:
"title" : "Ut commodi ullam eos dolores perferendis nihil sunt.", "title" : "Ut commodi ullam eos dolores perferendis nihil sunt.",
"updated_at" : "2016-01-04T15:31:46.176Z", "updated_at" : "2016-01-04T15:31:46.176Z",
"created_at" : "2016-01-04T15:31:46.176Z", "created_at" : "2016-01-04T15:31:46.176Z",
"subscribed": false "subscribed": false,
"user_notes_count": 1
} }
``` ```
...@@ -271,7 +274,8 @@ Example response: ...@@ -271,7 +274,8 @@ Example response:
"description" : null, "description" : null,
"updated_at" : "2016-01-07T12:44:33.959Z", "updated_at" : "2016-01-07T12:44:33.959Z",
"milestone" : null, "milestone" : null,
"subscribed" : true "subscribed" : true,
"user_notes_count": 0
} }
``` ```
...@@ -329,7 +333,8 @@ Example response: ...@@ -329,7 +333,8 @@ Example response:
"id" : 85, "id" : 85,
"assignee" : null, "assignee" : null,
"milestone" : null, "milestone" : null,
"subscribed" : true "subscribed" : true,
"user_notes_count": 0
} }
``` ```
......
...@@ -67,7 +67,8 @@ Parameters: ...@@ -67,7 +67,8 @@ Parameters:
}, },
"merge_when_build_succeeds": true, "merge_when_build_succeeds": true,
"merge_status": "can_be_merged", "merge_status": "can_be_merged",
"subscribed" : false "subscribed" : false,
"user_notes_count": 1
} }
] ]
``` ```
...@@ -130,7 +131,8 @@ Parameters: ...@@ -130,7 +131,8 @@ Parameters:
}, },
"merge_when_build_succeeds": true, "merge_when_build_succeeds": true,
"merge_status": "can_be_merged", "merge_status": "can_be_merged",
"subscribed" : true "subscribed" : true,
"user_notes_count": 1
} }
``` ```
...@@ -230,6 +232,7 @@ Parameters: ...@@ -230,6 +232,7 @@ Parameters:
"merge_when_build_succeeds": true, "merge_when_build_succeeds": true,
"merge_status": "can_be_merged", "merge_status": "can_be_merged",
"subscribed" : true, "subscribed" : true,
"user_notes_count": 1,
"changes": [ "changes": [
{ {
"old_path": "VERSION", "old_path": "VERSION",
...@@ -308,7 +311,8 @@ Parameters: ...@@ -308,7 +311,8 @@ Parameters:
}, },
"merge_when_build_succeeds": true, "merge_when_build_succeeds": true,
"merge_status": "can_be_merged", "merge_status": "can_be_merged",
"subscribed" : true "subscribed" : true,
"user_notes_count": 0
} }
``` ```
...@@ -378,7 +382,8 @@ Parameters: ...@@ -378,7 +382,8 @@ Parameters:
}, },
"merge_when_build_succeeds": true, "merge_when_build_succeeds": true,
"merge_status": "can_be_merged", "merge_status": "can_be_merged",
"subscribed" : true "subscribed" : true,
"user_notes_count": 1
} }
``` ```
...@@ -472,7 +477,8 @@ Parameters: ...@@ -472,7 +477,8 @@ Parameters:
}, },
"merge_when_build_succeeds": true, "merge_when_build_succeeds": true,
"merge_status": "can_be_merged", "merge_status": "can_be_merged",
"subscribed" : true "subscribed" : true,
"user_notes_count": 1
} }
``` ```
...@@ -537,7 +543,8 @@ Parameters: ...@@ -537,7 +543,8 @@ Parameters:
}, },
"merge_when_build_succeeds": true, "merge_when_build_succeeds": true,
"merge_status": "can_be_merged", "merge_status": "can_be_merged",
"subscribed" : true "subscribed" : true,
"user_notes_count": 1
} }
``` ```
...@@ -602,7 +609,8 @@ Example response: ...@@ -602,7 +609,8 @@ Example response:
"title" : "Consequatur vero maxime deserunt laboriosam est voluptas dolorem.", "title" : "Consequatur vero maxime deserunt laboriosam est voluptas dolorem.",
"created_at" : "2016-01-04T15:31:51.081Z", "created_at" : "2016-01-04T15:31:51.081Z",
"iid" : 6, "iid" : 6,
"labels" : [] "labels" : [],
"user_notes_count": 1
}, },
] ]
``` ```
......
...@@ -170,10 +170,10 @@ module API ...@@ -170,10 +170,10 @@ module API
expose :label_names, as: :labels expose :label_names, as: :labels
expose :milestone, using: Entities::Milestone expose :milestone, using: Entities::Milestone
expose :assignee, :author, using: Entities::UserBasic expose :assignee, :author, using: Entities::UserBasic
expose :subscribed do |issue, options| expose :subscribed do |issue, options|
issue.subscribed?(options[:current_user]) issue.subscribed?(options[:current_user])
end end
expose :user_notes_count
end end
class MergeRequest < ProjectEntity class MergeRequest < ProjectEntity
...@@ -187,10 +187,10 @@ module API ...@@ -187,10 +187,10 @@ module API
expose :milestone, using: Entities::Milestone expose :milestone, using: Entities::Milestone
expose :merge_when_build_succeeds expose :merge_when_build_succeeds
expose :merge_status expose :merge_status
expose :subscribed do |merge_request, options| expose :subscribed do |merge_request, options|
merge_request.subscribed?(options[:current_user]) merge_request.subscribed?(options[:current_user])
end end
expose :user_notes_count
end end
class MergeRequestChanges < MergeRequest class MergeRequestChanges < MergeRequest
......
...@@ -39,6 +39,7 @@ describe API::API, api: true do ...@@ -39,6 +39,7 @@ describe API::API, api: true do
let!(:empty_milestone) do let!(:empty_milestone) do
create(:milestone, title: '2.0.0', project: project) create(:milestone, title: '2.0.0', project: project)
end end
let!(:note) { create(:note_on_issue, author: user, project: project, noteable: issue) }
before { project.team << [user, :reporter] } before { project.team << [user, :reporter] }
...@@ -232,8 +233,28 @@ describe API::API, api: true do ...@@ -232,8 +233,28 @@ describe API::API, api: true do
end end
describe "GET /projects/:id/issues/:issue_id" do describe "GET /projects/:id/issues/:issue_id" do
it 'exposes known attributes' do
get api("/projects/#{project.id}/issues/#{issue.id}", user)
expect(response.status).to eq(200)
expect(json_response['id']).to eq(issue.id)
expect(json_response['iid']).to eq(issue.iid)
expect(json_response['project_id']).to eq(issue.project.id)
expect(json_response['title']).to eq(issue.title)
expect(json_response['description']).to eq(issue.description)
expect(json_response['state']).to eq(issue.state)
expect(json_response['created_at']).to be_present
expect(json_response['updated_at']).to be_present
expect(json_response['labels']).to eq(issue.label_names)
expect(json_response['milestone']).to be_a Hash
expect(json_response['assignee']).to be_a Hash
expect(json_response['author']).to be_a Hash
expect(json_response['user_notes_count']).to be(1)
end
it "should return a project issue by id" do it "should return a project issue by id" do
get api("/projects/#{project.id}/issues/#{issue.id}", user) get api("/projects/#{project.id}/issues/#{issue.id}", user)
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(json_response['title']).to eq(issue.title) expect(json_response['title']).to eq(issue.title)
expect(json_response['iid']).to eq(issue.iid) expect(json_response['iid']).to eq(issue.iid)
......
...@@ -113,6 +113,34 @@ describe API::API, api: true do ...@@ -113,6 +113,34 @@ describe API::API, api: true do
end end
describe "GET /projects/:id/merge_requests/:merge_request_id" do describe "GET /projects/:id/merge_requests/:merge_request_id" do
it 'exposes known attributes' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user)
expect(response.status).to eq(200)
expect(json_response['id']).to eq(merge_request.id)
expect(json_response['iid']).to eq(merge_request.iid)
expect(json_response['project_id']).to eq(merge_request.project.id)
expect(json_response['title']).to eq(merge_request.title)
expect(json_response['description']).to eq(merge_request.description)
expect(json_response['state']).to eq(merge_request.state)
expect(json_response['created_at']).to be_present
expect(json_response['updated_at']).to be_present
expect(json_response['labels']).to eq(merge_request.label_names)
expect(json_response['milestone']).to be_nil
expect(json_response['assignee']).to be_a Hash
expect(json_response['author']).to be_a Hash
expect(json_response['target_branch']).to eq(merge_request.target_branch)
expect(json_response['source_branch']).to eq(merge_request.source_branch)
expect(json_response['upvotes']).to eq(0)
expect(json_response['downvotes']).to eq(0)
expect(json_response['source_project_id']).to eq(merge_request.source_project.id)
expect(json_response['target_project_id']).to eq(merge_request.target_project.id)
expect(json_response['work_in_progress']).to be_falsy
expect(json_response['merge_when_build_succeeds']).to be_falsy
expect(json_response['merge_status']).to eq('can_be_merged')
expect(json_response['user_notes_count']).to be(2)
end
it "should return merge_request" do it "should return merge_request" do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user)
expect(response.status).to eq(200) expect(response.status).to eq(200)
......
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