Commit 86800bf5 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by Phil Hughes

Support expiration date in CI API when uploading artifacts

parent 1501940e
...@@ -146,7 +146,7 @@ module Ci ...@@ -146,7 +146,7 @@ module Ci
build.artifacts_file = artifacts build.artifacts_file = artifacts
build.artifacts_metadata = metadata build.artifacts_metadata = metadata
build.artifacts_expire_at = Time.now + ChronicDuration.parse(params['expire_in']) build.artifacts_expire_in = params['expire_in']
if build.save if build.save
present(build, with: Entities::BuildDetails) present(build, with: Entities::BuildDetails)
......
...@@ -29,6 +29,7 @@ module Ci ...@@ -29,6 +29,7 @@ module Ci
expose :before_sha expose :before_sha
expose :allow_git_fetch expose :allow_git_fetch
expose :token expose :token
expose :artifacts_expire_at, if: lambda { |build, opts| build.artifacts? }
expose :options do |model| expose :options do |model|
model.options model.options
......
...@@ -364,6 +364,42 @@ describe Ci::API::API do ...@@ -364,6 +364,42 @@ describe Ci::API::API do
end end
end end
context 'expire date' do
let!(:artifacts) { file_upload }
let(:post_data) do
{ 'file.path' => artifacts.path,
'file.name' => artifacts.original_filename,
'expire_in' => expire_in }
end
before do
post(post_url, post_data, headers_with_token)
end
context 'updates when specified' do
let(:expire_in) { '7 days' }
it do
build.reload
expect(response.status).to eq(201)
expect(json_response['artifacts_expire_at']).not_to be_empty
expect(build.artifacts_expire_at).to be_within(5.minutes).of(Time.now + 7.days)
end
end
context 'ignores if not specified' do
let(:expire_in) { nil }
it do
build.reload
expect(response.status).to eq(201)
expect(json_response['artifacts_expire_at']).to be_nil
expect(build.artifacts_expire_at).to be_nil
end
end
end
context "artifacts file is too large" do context "artifacts file is too large" do
it "should fail to post too large artifact" do it "should fail to post too large artifact" do
stub_application_setting(max_artifacts_size: 0) stub_application_setting(max_artifacts_size: 0)
......
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