BigW Consortium Gitlab

Commit 75b0627f by Rémy Coutable

Merge branch 'api-simple-group-project' into 'master'

API: Ability to get group's project in simple representation Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/25412 See merge request !8060
parents 921673b0 7841be24
---
title: 'API: Simple representation of group''s projects'
merge_request: 8060
author: Robert Schilling
...@@ -50,12 +50,17 @@ GET /groups/:id/projects ...@@ -50,12 +50,17 @@ GET /groups/:id/projects
Parameters: Parameters:
- `archived` (optional) - if passed, limit by archived status | Attribute | Type | Required | Description |
- `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` | `id` | integer/string | yes | The ID or path of a group |
- `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc` | `archived` | boolean | no | Limit by archived status |
- `search` (optional) - Return list of authorized projects according to a search criteria | `visibility` | string | no | Limit by visibility `public`, `internal`, or `private` |
- `ci_enabled_first` - Return projects ordered by ci_enabled flag. Projects with enabled GitLab CI go first | `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 ```json
[ [
......
...@@ -125,13 +125,16 @@ module API ...@@ -125,13 +125,16 @@ module API
default: 'created_at', desc: 'Return projects ordered by field' default: 'created_at', desc: 'Return projects ordered by field'
optional :sort, type: String, values: %w[asc desc], default: 'desc', optional :sort, type: String, values: %w[asc desc], default: 'desc',
desc: 'Return projects sorted in ascending and descending order' 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 use :pagination
end end
get ":id/projects" do get ":id/projects" do
group = find_group!(params[:id]) group = find_group!(params[:id])
projects = GroupProjectsFinder.new(group).execute(current_user) projects = GroupProjectsFinder.new(group).execute(current_user)
projects = filter_projects(projects) 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 end
desc 'Transfer a project to the group namespace. Available only for admin.' do desc 'Transfer a project to the group namespace. Available only for admin.' do
......
...@@ -243,17 +243,28 @@ describe API::Groups, api: true do ...@@ -243,17 +243,28 @@ describe API::Groups, api: true do
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
project_names = json_response.map { |proj| proj['name' ] } project_names = json_response.map { |proj| proj['name' ] }
expect(project_names).to match_array([project1.name, project3.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 end
it 'filters the groups projects' do 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' get api("/groups/#{group1.id}/projects", user1), visibility: 'public'
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an(Array) expect(json_response).to be_an(Array)
expect(json_response.length).to eq(1) 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 end
it "does not return a non existing group" do it "does not return a non existing group" do
......
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