summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Fletcher <mark@gitlab.com>2017-05-01 17:42:42 +0800
committerMark Fletcher <mark@gitlab.com>2017-05-03 18:45:19 +0800
commit21f5515a5ffb46bb2e710c17690122903bca126e (patch)
tree64e75fdfd749195d2f6b3fb9fb42572ab88b6a4a
parent3aca8b6557a638e0634065a1c72d87861b9ace4a (diff)
downloadgitlab-ce-21f5515a5ffb46bb2e710c17690122903bca126e.tar.gz
Expose project statistics on single requests via the API
+ The statistics parameter was already accepted * This commit ensure that it is respected for GET /projects/:id endpoint + Add documentation of the parameter and update the example response for stats
-rw-r--r--changelogs/unreleased/31544-size-of-project-from-api.yml4
-rw-r--r--doc/api/projects.md10
-rw-r--r--lib/api/projects.rb14
-rw-r--r--spec/requests/api/projects_spec.rb14
4 files changed, 36 insertions, 6 deletions
diff --git a/changelogs/unreleased/31544-size-of-project-from-api.yml b/changelogs/unreleased/31544-size-of-project-from-api.yml
new file mode 100644
index 00000000000..a707d49aecd
--- /dev/null
+++ b/changelogs/unreleased/31544-size-of-project-from-api.yml
@@ -0,0 +1,4 @@
+---
+title: Expose project statistics on single requests via the API
+merge_request:
+author:
diff --git a/doc/api/projects.md b/doc/api/projects.md
index 873b1ca9b2b..188fbe7447d 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -185,6 +185,7 @@ Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) |
+| `statistics` | boolean | no | Include project statistics |
```json
{
@@ -256,7 +257,14 @@ Parameters:
],
"only_allow_merge_if_pipeline_succeeds": false,
"only_allow_merge_if_all_discussions_are_resolved": false,
- "request_access_enabled": false
+ "request_access_enabled": false,
+ "statistics": {
+ "commit_count": 37,
+ "storage_size": 1038090,
+ "repository_size": 1038090,
+ "lfs_objects_size": 0,
+ "job_artifacts_size": 0
+ }
}
```
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index db4b31b55bc..1ba691cbea1 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -26,6 +26,10 @@ module API
params :optional_params do
use :optional_params_ce
end
+
+ params :statistics_params do
+ optional :statistics, type: Boolean, default: false, desc: 'Include project statistics'
+ end
end
resource :projects do
@@ -56,10 +60,6 @@ module API
optional :membership, type: Boolean, default: false, desc: 'Limit by projects that the current user is a member of'
end
- params :statistics_params do
- optional :statistics, type: Boolean, default: false, desc: 'Include project statistics'
- end
-
params :create_params do
optional :namespace_id, type: Integer, desc: 'Namespace ID for the new project. Default to the user namespace.'
optional :import_url, type: String, desc: 'URL from which the project is imported'
@@ -85,6 +85,7 @@ module API
end
params do
use :collection_params
+ use :statistics_params
end
get do
entity = current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails
@@ -151,10 +152,13 @@ module API
desc 'Get a single project' do
success Entities::ProjectWithAccess
end
+ params do
+ use :statistics_params
+ end
get ":id" do
entity = current_user ? Entities::ProjectWithAccess : Entities::BasicProjectDetails
present user_project, with: entity, current_user: current_user,
- user_can_admin_project: can?(current_user, :admin_project, user_project)
+ user_can_admin_project: can?(current_user, :admin_project, user_project), statistics: params[:statistics]
end
desc 'Get events for a single project' do
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index cc03d7a933b..ab70ce5cd2f 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -665,6 +665,20 @@ describe API::Projects do
})
end
+ it "does not include statistics by default" do
+ get api("/projects/#{project.id}", user)
+
+ expect(response).to have_http_status(200)
+ expect(json_response).not_to include 'statistics'
+ end
+
+ it "includes statistics if requested" do
+ get api("/projects/#{project.id}", user), statistics: true
+
+ expect(response).to have_http_status(200)
+ expect(json_response).to include 'statistics'
+ end
+
describe 'permissions' do
context 'all projects' do
before { project.team << [user, :master] }