Commit 97cf5659 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'ag-add-recent-members-entity' into 'master'

Expose new members count in Group Activity API

See merge request gitlab-org/gitlab!26601
parents ab54df1f d42291e9
...@@ -120,7 +120,7 @@ The following API resources are available outside of project and group contexts ...@@ -120,7 +120,7 @@ The following API resources are available outside of project and group contexts
| [Events](events.md) | `/events`, `/users/:id/events` (also available for projects) | | [Events](events.md) | `/events`, `/users/:id/events` (also available for projects) |
| [Feature flags](features.md) | `/features` | | [Feature flags](features.md) | `/features` |
| [Geo Nodes](geo_nodes.md) **(PREMIUM ONLY)** | `/geo_nodes` | | [Geo Nodes](geo_nodes.md) **(PREMIUM ONLY)** | `/geo_nodes` |
| [Group Activity Analytics](group_activity_analytics.md) **(STARTER)** | `/analytics/group_activity/{issues_count | merge_requests_count}` | | [Group Activity Analytics](group_activity_analytics.md) **(STARTER)** | `/analytics/group_activity/{issues_count | merge_requests_count | new_members_count }` |
| [Import repository from GitHub](import.md) | `/import/github` | | [Import repository from GitHub](import.md) | `/import/github` |
| [Issues](issues.md) | `/issues` (also available for groups and projects) | | [Issues](issues.md) | `/issues` (also available for groups and projects) |
| [Issues Statistics](issues_statistics.md) | `/issues_statistics` (also available for groups and projects) | | [Issues Statistics](issues_statistics.md) | `/issues_statistics` (also available for groups and projects) |
......
...@@ -49,3 +49,27 @@ Example response: ...@@ -49,3 +49,27 @@ Example response:
```json ```json
{ "merge_requests_count": 10 } { "merge_requests_count": 10 }
``` ```
## Get count of members recently added to group
```plaintext
GET /analytics/group_activity/new_members_count
```
Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `group_path` | string | yes | Group path |
Example request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/analytics/group_activity/new_members_count?group_path=gitlab-org
```
Example response:
```json
{ "new_members_count": 10 }
```
---
title: Add API endpoint for new members' count in Group Activity Analytics
merge_request: 26601
author:
type: added
...@@ -9,7 +9,6 @@ module API ...@@ -9,7 +9,6 @@ module API
before do before do
authenticate! authenticate!
not_found! unless Feature.enabled?(:group_activity_analytics)
end end
helpers do helpers do
...@@ -35,7 +34,11 @@ module API ...@@ -35,7 +34,11 @@ module API
end end
get 'issues_count' do get 'issues_count' do
not_found! unless
Feature.enabled?(:group_activity_analytics, group)
authorize! :read_group_activity_analytics, group authorize! :read_group_activity_analytics, group
present( present(
calculator, calculator,
with: EE::API::Entities::Analytics::GroupActivity::IssuesCount with: EE::API::Entities::Analytics::GroupActivity::IssuesCount
...@@ -52,12 +55,37 @@ module API ...@@ -52,12 +55,37 @@ module API
end end
get 'merge_requests_count' do get 'merge_requests_count' do
not_found! unless
Feature.enabled?(:group_activity_analytics, group)
authorize! :read_group_activity_analytics, group authorize! :read_group_activity_analytics, group
present( present(
calculator, calculator,
with: EE::API::Entities::Analytics::GroupActivity::MergeRequestsCount with: EE::API::Entities::Analytics::GroupActivity::MergeRequestsCount
) )
end end
desc 'Get count of recently created group members' do
detail DESCRIPTION_DETAIL
success EE::API::Entities::Analytics::GroupActivity::NewMembersCount
end
params do
requires :group_path, type: String, desc: 'Group Path'
end
get 'new_members_count' do
not_found! unless
Feature.enabled?(:group_activity_analytics, group)
authorize! :read_group_activity_analytics, group
present(
calculator,
with: EE::API::Entities::Analytics::GroupActivity::NewMembersCount
)
end
end end
end end
end end
......
# frozen_string_literal: true
module EE
module API
module Entities
module Analytics
module GroupActivity
class NewMembersCount < Grape::Entity
expose :new_members_count
end
end
end
end
end
end
...@@ -16,10 +16,20 @@ describe EE::API::Entities::Analytics::GroupActivity do ...@@ -16,10 +16,20 @@ describe EE::API::Entities::Analytics::GroupActivity do
end end
context 'issues count' do context 'issues count' do
it_behaves_like 'exposes count', 'issues_count', EE::API::Entities::Analytics::GroupActivity::IssuesCount it_behaves_like 'exposes count',
'issues_count',
EE::API::Entities::Analytics::GroupActivity::IssuesCount
end end
context 'merge requests count' do context 'merge requests count' do
it_behaves_like 'exposes count', 'merge_requests_count', EE::API::Entities::Analytics::GroupActivity::MergeRequestsCount it_behaves_like 'exposes count',
'merge_requests_count',
EE::API::Entities::Analytics::GroupActivity::MergeRequestsCount
end
context 'new members count' do
it_behaves_like 'exposes count',
'new_members_count',
EE::API::Entities::Analytics::GroupActivity::NewMembersCount
end end
end end
...@@ -11,7 +11,7 @@ describe API::Analytics::GroupActivityAnalytics do ...@@ -11,7 +11,7 @@ describe API::Analytics::GroupActivityAnalytics do
let_it_be(:anonymous_user) { create(:user) } let_it_be(:anonymous_user) { create(:user) }
shared_examples 'GET group_activity' do |activity| shared_examples 'GET group_activity' do |activity, count|
let(:feature_enabled) { true } let(:feature_enabled) { true }
let(:params) { { group_path: group.full_path } } let(:params) { { group_path: group.full_path } }
let(:current_user) { reporter } let(:current_user) { reporter }
...@@ -29,7 +29,7 @@ describe API::Analytics::GroupActivityAnalytics do ...@@ -29,7 +29,7 @@ describe API::Analytics::GroupActivityAnalytics do
end end
it 'is returns a count' do it 'is returns a count' do
expect(response.parsed_body).to eq({ "#{activity}_count" => 0 }) expect(response.parsed_body).to eq({ "#{activity}_count" => count })
end end
context 'when feature is not available in plan' do context 'when feature is not available in plan' do
...@@ -58,10 +58,14 @@ describe API::Analytics::GroupActivityAnalytics do ...@@ -58,10 +58,14 @@ describe API::Analytics::GroupActivityAnalytics do
end end
context 'GET /group_activity/issues_count' do context 'GET /group_activity/issues_count' do
it_behaves_like 'GET group_activity', 'issues' it_behaves_like 'GET group_activity', 'issues', 0
end end
context 'GET /group_activity/merge_requests_count' do context 'GET /group_activity/merge_requests_count' do
it_behaves_like 'GET group_activity', 'merge_requests' it_behaves_like 'GET group_activity', 'merge_requests', 0
end
context 'GET /group_activity/new_members_count' do
it_behaves_like 'GET group_activity', 'new_members', 1 # reporter
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