Added keep artifacts API endpoint
This commit is contained in:
parent
7e9273dd94
commit
6013768fec
3 changed files with 96 additions and 0 deletions
|
@ -443,3 +443,53 @@ Example of response
|
|||
"user": null
|
||||
}
|
||||
```
|
||||
|
||||
## Keep artifacts
|
||||
|
||||
Prevents artifacts from being deleted when expiration is set
|
||||
|
||||
```
|
||||
POST /projects/:id/builds/:build_id/artifacts/keep
|
||||
```
|
||||
|
||||
Parameters
|
||||
|
||||
| Attribute | Type | required | Description |
|
||||
|-------------|---------|----------|---------------------|
|
||||
| `id` | integer | yes | The ID of a project |
|
||||
| `build_id` | integer | yes | The ID of a build |
|
||||
|
||||
Example of request
|
||||
|
||||
```
|
||||
curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/builds/1/artifacts/keep"
|
||||
```
|
||||
|
||||
Example of response
|
||||
|
||||
```json
|
||||
{
|
||||
"commit": {
|
||||
"author_email": "admin@example.com",
|
||||
"author_name": "Administrator",
|
||||
"created_at": "2015-12-24T16:51:14.000+01:00",
|
||||
"id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
|
||||
"message": "Test the CI integration.",
|
||||
"short_id": "0ff3ae19",
|
||||
"title": "Test the CI integration."
|
||||
},
|
||||
"coverage": null,
|
||||
"download_url": null,
|
||||
"id": 69,
|
||||
"name": "rubocop",
|
||||
"ref": "master",
|
||||
"runner": null,
|
||||
"stage": "test",
|
||||
"created_at": "2016-01-11T10:13:33.506Z",
|
||||
"started_at": "2016-01-11T10:13:33.506Z",
|
||||
"finished_at": "2016-01-11T10:15:10.506Z",
|
||||
"status": "failed",
|
||||
"tag": false,
|
||||
"user": null
|
||||
}
|
||||
```
|
||||
|
|
|
@ -166,6 +166,25 @@ module API
|
|||
present build, with: Entities::Build,
|
||||
user_can_download_artifacts: can?(current_user, :download_build_artifacts, user_project)
|
||||
end
|
||||
|
||||
# Keep the artifacts to prevent them to be deleted
|
||||
#
|
||||
# Parameters:
|
||||
# id (required) - The ID of a build
|
||||
# Example Request:
|
||||
# POST /projects/:id/builds/:build_id/artifacts/keep
|
||||
post ':id/builds/:build_id/artifacts/keep' do
|
||||
authorize_update_builds!
|
||||
|
||||
build = get_build(params[:build_id])
|
||||
return not_found!(build) unless build && build.artifacts?
|
||||
|
||||
build.keep_artifacts!
|
||||
|
||||
status 200
|
||||
present build, with: Entities::Build,
|
||||
user_can_download_artifacts: can?(current_user, :read_build, user_project)
|
||||
end
|
||||
end
|
||||
|
||||
helpers do
|
||||
|
|
|
@ -241,4 +241,31 @@ describe API::API, api: true do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /projects/:id/builds/:build_id/artifacts/keep' do
|
||||
before do
|
||||
post api("/projects/#{project.id}/builds/#{build.id}/artifacts/keep", user)
|
||||
end
|
||||
|
||||
context 'artifacts did not expire' do
|
||||
let(:build) do
|
||||
create(:ci_build, :trace, :artifacts, :success,
|
||||
project: project, pipeline: pipeline, artifacts_expire_at: Time.now + 7.days)
|
||||
end
|
||||
|
||||
it 'should keep artifacts' do
|
||||
expect(response.status).to eq 200
|
||||
build.reload
|
||||
expect(build.artifacts_expire_at).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'no artifacts' do
|
||||
let(:build) { create(:ci_build, project: project, pipeline: pipeline) }
|
||||
|
||||
it 'should respond with not found' do
|
||||
expect(response.status).to eq 404
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue