summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2016-12-13 13:51:30 +0100
committerRobert Schilling <rschilling@student.tugraz.at>2016-12-13 13:54:36 +0100
commit7841be243e5f28828cea95500b554d7f5cc039eb (patch)
treef9c4dcc6f5015323f65025dcfe693a8e52ca0f3f
parent9a3c53fd4e79b73e51c8aadeb8a996db65088811 (diff)
downloadgitlab-ce-api-simple-group-project.tar.gz
API: Ability to get group's project in simple representationapi-simple-group-project
-rw-r--r--changelogs/unreleased/api-simple-group-project.yml4
-rw-r--r--doc/api/groups.md17
-rw-r--r--lib/api/groups.rb5
-rw-r--r--spec/requests/api/groups_spec.rb15
4 files changed, 32 insertions, 9 deletions
diff --git a/changelogs/unreleased/api-simple-group-project.yml b/changelogs/unreleased/api-simple-group-project.yml
new file mode 100644
index 00000000000..54c8de610a6
--- /dev/null
+++ b/changelogs/unreleased/api-simple-group-project.yml
@@ -0,0 +1,4 @@
+---
+title: 'API: Simple representation of group''s projects'
+merge_request: 8060
+author: Robert Schilling
diff --git a/doc/api/groups.md b/doc/api/groups.md
index 5e6f498c365..134d7bda22f 100644
--- a/doc/api/groups.md
+++ b/doc/api/groups.md
@@ -50,12 +50,17 @@ GET /groups/:id/projects
Parameters:
-- `archived` (optional) - if passed, limit by archived status
-- `visibility` (optional) - if passed, limit by visibility `public`, `internal`, `private`
-- `order_by` (optional) - Return requests ordered by `id`, `name`, `path`, `created_at`, `updated_at` or `last_activity_at` fields. Default is `created_at`
-- `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc`
-- `search` (optional) - Return list of authorized projects according to a search criteria
-- `ci_enabled_first` - Return projects ordered by ci_enabled flag. Projects with enabled GitLab CI go first
+| Attribute | Type | Required | Description |
+| --------- | ---- | -------- | ----------- |
+| `id` | integer/string | yes | The ID or path of a group |
+| `archived` | boolean | no | Limit by archived status |
+| `visibility` | string | no | Limit by visibility `public`, `internal`, or `private` |
+| `order_by` | string | no | Return projects ordered by `id`, `name`, `path`, `created_at`, `updated_at`, or `last_activity_at` fields. Default is `created_at` |
+| `sort` | string | no | Return projects sorted in `asc` or `desc` order. Default is `desc` |
+| `search` | string | no | Return list of authorized projects matching the search criteria |
+| `simple` | boolean | no | Return only the ID, URL, name, and path of each project |
+
+Example response:
```json
[
diff --git a/lib/api/groups.rb b/lib/api/groups.rb
index 105d3ee342e..9b9d3df7435 100644
--- a/lib/api/groups.rb
+++ b/lib/api/groups.rb
@@ -125,13 +125,16 @@ module API
default: 'created_at', desc: 'Return projects ordered by field'
optional :sort, type: String, values: %w[asc desc], default: 'desc',
desc: 'Return projects sorted in ascending and descending order'
+ optional :simple, type: Boolean, default: false,
+ desc: 'Return only the ID, URL, name, and path of each project'
use :pagination
end
get ":id/projects" do
group = find_group!(params[:id])
projects = GroupProjectsFinder.new(group).execute(current_user)
projects = filter_projects(projects)
- present paginate(projects), with: Entities::Project, user: current_user
+ entity = params[:simple] ? Entities::BasicProjectDetails : Entities::Project
+ present paginate(projects), with: entity, user: current_user
end
desc 'Transfer a project to the group namespace. Available only for admin.' do
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index 15647b262b6..a75ba824e85 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -243,17 +243,28 @@ describe API::Groups, api: true do
expect(json_response.length).to eq(2)
project_names = json_response.map { |proj| proj['name' ] }
expect(project_names).to match_array([project1.name, project3.name])
+ expect(json_response.first['default_branch']).to be_present
+ end
+
+ it "returns the group's projects with simple representation" do
+ get api("/groups/#{group1.id}/projects", user1), simple: true
+
+ expect(response).to have_http_status(200)
+ expect(json_response.length).to eq(2)
+ project_names = json_response.map { |proj| proj['name' ] }
+ expect(project_names).to match_array([project1.name, project3.name])
+ expect(json_response.first['default_branch']).not_to be_present
end
it 'filters the groups projects' do
- public_projet = create(:project, :public, path: 'test1', group: group1)
+ public_project = create(:project, :public, path: 'test1', group: group1)
get api("/groups/#{group1.id}/projects", user1), visibility: 'public'
expect(response).to have_http_status(200)
expect(json_response).to be_an(Array)
expect(json_response.length).to eq(1)
- expect(json_response.first['name']).to eq(public_projet.name)
+ expect(json_response.first['name']).to eq(public_project.name)
end
it "does not return a non existing group" do