Merge branch '27032-add-a-house-keeping-api-call' into 'master'

Add housekeeping endpoint for Projects API

Closes #27032

See merge request !9421
This commit is contained in:
Rémy Coutable 2017-02-22 15:49:51 +00:00
commit 91335c59fd
4 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
title: Add housekeeping endpoint for Projects API
merge_request: 9421
author:

View File

@ -1195,3 +1195,17 @@ Parameters:
| `query` | string | yes | A string contained in the project name |
| `order_by` | string | no | Return requests ordered by `id`, `name`, `created_at` or `last_activity_at` fields |
| `sort` | string | no | Return requests sorted in `asc` or `desc` order |
## Start the Housekeeping task for a Project
>**Note:** This feature was introduced in GitLab 9.0
```
POST /projects/:id/housekeeping
```
Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |

View File

@ -374,6 +374,19 @@ module API
present paginate(users), with: Entities::UserBasic
end
desc 'Start the housekeeping task for a project' do
detail 'This feature was introduced in GitLab 9.0.'
end
post ':id/housekeeping' do
authorize_admin_project
begin
::Projects::HousekeepingService.new(user_project).execute
rescue ::Projects::HousekeepingService::LeaseTaken => error
conflict!(error.message)
end
end
end
end
end

View File

@ -1422,4 +1422,53 @@ describe API::Projects, api: true do
end
end
end
describe 'POST /projects/:id/housekeeping' do
let(:housekeeping) { Projects::HousekeepingService.new(project) }
before do
allow(Projects::HousekeepingService).to receive(:new).with(project).and_return(housekeeping)
end
context 'when authenticated as owner' do
it 'starts the housekeeping process' do
expect(housekeeping).to receive(:execute).once
post api("/projects/#{project.id}/housekeeping", user)
expect(response).to have_http_status(201)
end
context 'when housekeeping lease is taken' do
it 'returns conflict' do
expect(housekeeping).to receive(:execute).once.and_raise(Projects::HousekeepingService::LeaseTaken)
post api("/projects/#{project.id}/housekeeping", user)
expect(response).to have_http_status(409)
expect(json_response['message']).to match(/Somebody already triggered housekeeping for this project/)
end
end
end
context 'when authenticated as developer' do
before do
project_member2
end
it 'returns forbidden error' do
post api("/projects/#{project.id}/housekeeping", user3)
expect(response).to have_http_status(403)
end
end
context 'when unauthenticated' do
it 'returns authentication error' do
post api("/projects/#{project.id}/housekeeping")
expect(response).to have_http_status(401)
end
end
end
end