diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-12-16 22:49:28 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-12-16 22:49:28 +0000 |
commit | 9ede66f619bb030ad351a7abf7b1be2148de7f99 (patch) | |
tree | 91ea3217593e7b654eb620dd9dd9715e9f312272 | |
parent | a9b078535b870e52c113f2a624fc3518b4f6b208 (diff) | |
parent | c36821df9f571855b477b09c102b90a78b9079e9 (diff) | |
download | gitlab-ce-9ede66f619bb030ad351a7abf7b1be2148de7f99.tar.gz |
Merge branch 'api-support-starred-projects' into 'master'
Api support for requesting starred projects for user
Closes #4112
Note: probably targets the wrong release in the `CHANGELOG`, though 8.4 was not there yet
See merge request !2127
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | doc/api/projects.md | 15 | ||||
-rw-r--r-- | lib/api/projects.rb | 11 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 21 |
4 files changed, 47 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG index 3e00c8dc6d3..53aa970d45c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.3.0 (unreleased) + - API support for starred projects for authorized user (Zeger-Jan van de Weg) - Add open_issues_count to project API (Stan Hu) - Expand character set of usernames created by Omniauth (Corey Hinshaw) - Add button to automatically merge a merge request when the build succeeds (Zeger-Jan van de Weg) diff --git a/doc/api/projects.md b/doc/api/projects.md index 2c7a3d5c552..658e65c6f01 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -139,6 +139,21 @@ Parameters: - `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 +### List starred projects + +Get a list of projects which are starred by the authenticated user. + +``` +GET /projects/starred +``` + +Parameters: + +- `archived` (optional) - if passed, limit by archived status +- `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 + ### List ALL projects Get a list of all GitLab projects (admin only). diff --git a/lib/api/projects.rb b/lib/api/projects.rb index bdf4b77596e..5e75cd35c56 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -39,6 +39,17 @@ module API present @projects, with: Entities::Project end + # Gets starred project for the authenticated user + # + # Example Request: + # GET /projects/starred + get '/starred' do + @projects = current_user.starred_projects + @projects = filter_projects(@projects) + @projects = paginate @projects + present @projects, with: Entities::Project + end + # Get all projects for admin user # # Example Request: diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index c01ab94e715..01d2ec79482 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -139,6 +139,25 @@ describe API::API, api: true do end end + describe 'GET /projects/starred' do + before do + admin.starred_projects << project + admin.save! + end + + it 'should return the starred projects' do + get api('/projects/all', admin) + expect(response.status).to eq(200) + expect(json_response).to be_an Array + + expect(json_response).to satisfy do |response| + response.one? do |entry| + entry['name'] == project.name + end + end + end + end + describe 'POST /projects' do context 'maximum number of projects reached' do it 'should not create new project and respond with 403' do @@ -471,7 +490,7 @@ describe API::API, api: true do end end - describe 'PUT /projects/:id/snippets/:shippet_id' do + describe 'PUT /projects/:id/snippets/:snippet_id' do it 'should update an existing project snippet' do put api("/projects/#{project.id}/snippets/#{snippet.id}", user), code: 'updated code' |