Commit eede4ab1 authored by Lin Jen-Shin's avatar Lin Jen-Shin

0 for unlimited, disallow blank, feedback:

https://gitlab.com/gitlab-org/gitlab-ce/issues/27762#note_23520780
parent 37cc3aae
...@@ -269,14 +269,6 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -269,14 +269,6 @@ class ApplicationSetting < ActiveRecord::Base
self.repository_storages = [value] self.repository_storages = [value]
end end
def default_artifacts_expire_in=(value)
if value.present?
super(value.squish)
else
super(nil)
end
end
# Choose one of the available repository storage options. Currently all have # Choose one of the available repository storage options. Currently all have
# equal weighting. # equal weighting.
def pick_repository_storage def pick_repository_storage
...@@ -306,10 +298,10 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -306,10 +298,10 @@ class ApplicationSetting < ActiveRecord::Base
end end
def check_default_artifacts_expire_in def check_default_artifacts_expire_in
if default_artifacts_expire_in && if default_artifacts_expire_in.blank?
ChronicDuration.parse(default_artifacts_expire_in).nil? errors.add(:default_artifacts_expiration, "is not presented")
errors.add(:default_artifacts_expiration, else
"can't be 0. Leave it blank for no expiration") ChronicDuration.parse(default_artifacts_expire_in)
end end
rescue ChronicDuration::DurationParseError rescue ChronicDuration::DurationParseError
errors.add(:default_artifacts_expiration, "is invalid") errors.add(:default_artifacts_expiration, "is invalid")
......
...@@ -509,7 +509,7 @@ module Ci ...@@ -509,7 +509,7 @@ module Ci
def artifacts_expire_in=(value) def artifacts_expire_in=(value)
self.artifacts_expire_at = self.artifacts_expire_at =
if value if value
Time.now + ChronicDuration.parse(value) ChronicDuration.parse(value)&.seconds&.from_now
end end
end end
......
...@@ -219,10 +219,11 @@ ...@@ -219,10 +219,11 @@
.col-sm-10 .col-sm-10
= f.text_field :default_artifacts_expire_in, class: 'form-control' = f.text_field :default_artifacts_expire_in, class: 'form-control'
.help-block .help-block
Set the default expiration time for each job's artifacts Set the default expiration time for each job's artifacts.
0 for unlimited.
= surround '(', ')' do = surround '(', ')' do
= link_to 'syntax', help_page_path('ci/yaml/README', anchor: 'artifactsexpire_in') = link_to 'syntax', help_page_path('ci/yaml/README', anchor: 'artifactsexpire_in')
= link_to icon('question-circle'), help_page_path('user/admin_area/settings/continuous_integration', anchor: 'default-artifacts-expiration-time') = link_to icon('question-circle'), help_page_path('user/admin_area/settings/continuous_integration', anchor: 'default-artifacts-expiration')
- if Gitlab.config.registry.enabled - if Gitlab.config.registry.enabled
%fieldset %fieldset
......
...@@ -5,7 +5,7 @@ class AddDefaultArtifactsExpirationToApplicationSettings < ActiveRecord::Migrati ...@@ -5,7 +5,7 @@ class AddDefaultArtifactsExpirationToApplicationSettings < ActiveRecord::Migrati
def change def change
add_column :application_settings, add_column :application_settings,
:default_artifacts_expire_in, :default_artifacts_expire_in, :string,
:string, null: true null: false, default: '0'
end end
end end
...@@ -111,7 +111,7 @@ ActiveRecord::Schema.define(version: 20170214111112) do ...@@ -111,7 +111,7 @@ ActiveRecord::Schema.define(version: 20170214111112) do
t.boolean "plantuml_enabled" t.boolean "plantuml_enabled"
t.integer "max_pages_size", default: 100, null: false t.integer "max_pages_size", default: 100, null: false
t.integer "terminal_max_session_time", default: 0, null: false t.integer "terminal_max_session_time", default: 0, null: false
t.string "default_artifacts_expire_in", limit: 255 t.string "default_artifacts_expire_in", default: '0', null: false
end end
create_table "audit_events", force: :cascade do |t| create_table "audit_events", force: :cascade do |t|
......
...@@ -18,13 +18,13 @@ that this setting is set for each job. ...@@ -18,13 +18,13 @@ that this setting is set for each job.
[art-yml]: ../../../administration/build_artifacts [art-yml]: ../../../administration/build_artifacts
## Default artifacts expiration time ## Default artifacts expiration
The default expiration time of the [build artifacts][art-yml] can be set in The default expiration time of the [job artifacts][art-yml] can be set in
the Admin area of your GitLab instance. The syntax of duration is described the Admin area of your GitLab instance. The syntax of duration is described
in [artifacts:expire_in][duration-syntax]. The default is `30 days`. Note that in [artifacts:expire_in][duration-syntax]. The default is `30 days`. Note that
this setting is set for each job. Leave it blank if you don't want to set this setting is set for each job. Set it to 0 if you don't want default
default expiration time. expiration.
1. Go to **Admin area > Settings** (`/admin/application_settings`). 1. Go to **Admin area > Settings** (`/admin/application_settings`).
......
...@@ -30,20 +30,16 @@ describe ApplicationSetting, models: true do ...@@ -30,20 +30,16 @@ describe ApplicationSetting, models: true do
end end
describe 'default_artifacts_expire_in' do describe 'default_artifacts_expire_in' do
it 'sets an error if it is invalid' do it 'sets an error if it cannot parse' do
setting.update(default_artifacts_expire_in: 'a') setting.update(default_artifacts_expire_in: 'a')
expect(setting).to be_invalid expect_invalid
expect(setting.errors.messages)
.to have_key(:default_artifacts_expiration)
end end
it 'does not allow 0' do it 'sets an error if it is blank' do
setting.update(default_artifacts_expire_in: '0') setting.update(default_artifacts_expire_in: ' ')
expect(setting).to be_invalid expect_invalid
expect(setting.errors.messages)
.to have_key(:default_artifacts_expiration)
end end
it 'sets the value if it is valid' do it 'sets the value if it is valid' do
...@@ -53,11 +49,17 @@ describe ApplicationSetting, models: true do ...@@ -53,11 +49,17 @@ describe ApplicationSetting, models: true do
expect(setting.default_artifacts_expire_in).to eq('30 days') expect(setting.default_artifacts_expire_in).to eq('30 days')
end end
it 'does not set it if it is blank' do it 'sets the value if it is 0' do
setting.update(default_artifacts_expire_in: ' ') setting.update(default_artifacts_expire_in: '0')
expect(setting).to be_valid expect(setting).to be_valid
expect(setting.default_artifacts_expire_in).to be_nil expect(setting.default_artifacts_expire_in).to eq('0')
end
def expect_invalid
expect(setting).to be_invalid
expect(setting.errors.messages)
.to have_key(:default_artifacts_expiration)
end end
end end
......
...@@ -166,6 +166,12 @@ describe Ci::Build, :models do ...@@ -166,6 +166,12 @@ describe Ci::Build, :models do
is_expected.to be_nil is_expected.to be_nil
end end
it 'when setting to 0' do
build.artifacts_expire_in = '0'
is_expected.to be_nil
end
end end
describe '#commit' do describe '#commit' 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