Commit a67aff6d authored by Shinya Maeda's avatar Shinya Maeda

Add Import/Export Setting for trigger_schedule. Remove ref validation.

parent 97cc6777
module Ci module Ci
class TriggerSchedule < ActiveRecord::Base class TriggerSchedule < ActiveRecord::Base
extend Ci::Model extend Ci::Model
include Importable
acts_as_paranoid acts_as_paranoid
...@@ -9,10 +10,10 @@ module Ci ...@@ -9,10 +10,10 @@ module Ci
delegate :ref, to: :trigger delegate :ref, to: :trigger
validates :trigger, presence: true validates :trigger, presence: { unless: :importing? }
validates :cron, cron: true, presence: true validates :cron, cron: true, presence: { unless: :importing? }
validates :cron_time_zone, presence: true validates :cron_time_zone, presence: { unless: :importing? }
validates :ref, ref: true, presence: true validates :ref, presence: { unless: :importing? }
# validate :check_cron_frequency # validate :check_cron_frequency
after_create :schedule_next_run! after_create :schedule_next_run!
......
# RefValidator
#
# Custom validator for Ref.
class RefValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless record.project.repository.branch_exists?(value)
record.errors.add(attribute, " does not exist")
end
end
end
...@@ -39,7 +39,8 @@ project_tree: ...@@ -39,7 +39,8 @@ project_tree:
- :author - :author
- :events - :events
- :statuses - :statuses
- :triggers # TODO: Need to confirm - triggers:
- :trigger_schedule
- :deploy_keys - :deploy_keys
- :services - :services
- :hooks - :hooks
......
...@@ -5,6 +5,7 @@ module Gitlab ...@@ -5,6 +5,7 @@ module Gitlab
pipelines: 'Ci::Pipeline', pipelines: 'Ci::Pipeline',
statuses: 'commit_status', statuses: 'commit_status',
triggers: 'Ci::Trigger', triggers: 'Ci::Trigger',
trigger_schedule: 'Ci::TriggerSchedule',
builds: 'Ci::Build', builds: 'Ci::Build',
hooks: 'ProjectHook', hooks: 'ProjectHook',
merge_access_levels: 'ProtectedBranch::MergeAccessLevel', merge_access_levels: 'ProtectedBranch::MergeAccessLevel',
......
...@@ -100,6 +100,8 @@ triggers: ...@@ -100,6 +100,8 @@ triggers:
- trigger_requests - trigger_requests
- owner - owner
- trigger_schedule - trigger_schedule
trigger_schedule:
- trigger
deploy_keys: deploy_keys:
- user - user
- deploy_keys_projects - deploy_keys_projects
......
...@@ -249,6 +249,7 @@ Ci::TriggerSchedule: ...@@ -249,6 +249,7 @@ Ci::TriggerSchedule:
- created_at - created_at
- updated_at - updated_at
- cron - cron
- cron_time_zone
- next_run_at - next_run_at
DeployKey: DeployKey:
- id - id
......
...@@ -5,13 +5,6 @@ describe Ci::TriggerSchedule, models: true do ...@@ -5,13 +5,6 @@ describe Ci::TriggerSchedule, models: true do
it { is_expected.to belong_to(:trigger) } it { is_expected.to belong_to(:trigger) }
it { is_expected.to respond_to :ref } it { is_expected.to respond_to :ref }
it 'should validate ref existence' do
trigger_schedule = create(:ci_trigger_schedule, :cron_nightly_build)
trigger_schedule.trigger.ref = 'invalid-ref'
trigger_schedule.valid?
expect(trigger_schedule.errors[:ref].first).to include('does not exist')
end
describe '#schedule_next_run!' do describe '#schedule_next_run!' do
let(:trigger_schedule) { create(:ci_trigger_schedule, :cron_nightly_build, next_run_at: nil) } let(:trigger_schedule) { create(:ci_trigger_schedule, :cron_nightly_build, next_run_at: nil) }
......
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