Commit c19fddba authored by Luke Duncalfe's avatar Luke Duncalfe

Merge branch 'weimeng-user-counts-api' into 'master'

Add assigned issues and pending todos count to /user_counts API endpoint

See merge request gitlab-org/gitlab!66909
parents 6c3d2d1f eb340792
......@@ -859,9 +859,13 @@ Example response:
Get the counts (same as in top right menu) of the currently signed in user.
| Attribute | Type | Description |
| ---------------- | ------ | ------------------------------------------------------------ |
| `merge_requests` | number | Merge requests that are active and assigned to current user. |
| Attribute | Type | Description |
| --------------------------------- | ------ | ---------------------------------------------------------------------------- |
| `assigned_issues` | number | Number of issues that are open and assigned to the current user. [Added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66909) in GitLab 14.2. |
| `assigned_merge_requests` | number | Number of merge requests that are active and assigned to the current user. [Added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50026) in GitLab 13.8. |
| `merge_requests` | number | [Deprecated](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50026) in GitLab 13.8. Equivalent to and replaced by `assigned_merge_requests`. |
| `review_requested_merge_requests` | number | Number of merge requests that the current user has been requested to review. [Added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50026) in GitLab 13.8. |
| `todos` | number | Number of pending to-do items for current user. [Added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66909) in GitLab 14.2. |
```plaintext
GET /user_counts
......@@ -875,7 +879,11 @@ Example response:
```json
{
"merge_requests": 4
"merge_requests": 4,
"assigned_issues": 15,
"assigned_merge_requests": 11,
"review_requested_merge_requests": 0,
"todos": 1
}
```
......
......@@ -6,15 +6,17 @@ module API
resource :user_counts do
desc 'Return the user specific counts' do
detail 'Open MR Count'
detail 'Assigned open issues, assigned MRs and pending todos count'
end
get do
unauthorized! unless current_user
{
merge_requests: current_user.assigned_open_merge_requests_count, # @deprecated
assigned_issues: current_user.assigned_open_issues_count,
assigned_merge_requests: current_user.assigned_open_merge_requests_count,
review_requested_merge_requests: current_user.review_requested_open_merge_requests_count
review_requested_merge_requests: current_user.review_requested_open_merge_requests_count,
todos: current_user.todos_pending_count
}
end
end
......
......@@ -3,8 +3,10 @@
require 'spec_helper'
RSpec.describe API::UserCounts do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
let_it_be(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
let_it_be(:todo) { create(:todo, :pending, user: user, project: project) }
let!(:merge_request) { create(:merge_request, :simple, author: user, assignees: [user], source_project: project, title: "Test") }
......@@ -18,22 +20,36 @@ RSpec.describe API::UserCounts do
end
context 'when authenticated' do
it 'returns open counts for current user' do
it 'returns assigned issue counts for current_user' do
get api('/user_counts', user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash
expect(json_response['merge_requests']).to eq(1)
expect(json_response['assigned_issues']).to eq(1)
end
it 'updates the mr count when a new mr is assigned' do
create(:merge_request, source_project: project, author: user, assignees: [user])
context 'merge requests' do
it 'returns assigned MR counts for current user' do
get api('/user_counts', user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash
expect(json_response['merge_requests']).to eq(1)
end
it 'updates the mr count when a new mr is assigned' do
create(:merge_request, source_project: project, author: user, assignees: [user])
get api('/user_counts', user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash
expect(json_response['merge_requests']).to eq(2)
end
end
it 'returns pending todo counts for current_user' do
get api('/user_counts', user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash
expect(json_response['merge_requests']).to eq(2)
expect(json_response['todos']).to eq(1)
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