Commit a67aff6d authored by Shinya Maeda's avatar Shinya Maeda

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

parent 97cc6777
module Ci
class TriggerSchedule < ActiveRecord::Base
extend Ci::Model
include Importable
acts_as_paranoid
......@@ -9,10 +10,10 @@ module Ci
delegate :ref, to: :trigger
validates :trigger, presence: true
validates :cron, cron: true, presence: true
validates :cron_time_zone, presence: true
validates :ref, ref: true, presence: true
validates :trigger, presence: { unless: :importing? }
validates :cron, cron: true, presence: { unless: :importing? }
validates :cron_time_zone, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing? }
# validate :check_cron_frequency
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:
- :author
- :events
- :statuses
- :triggers # TODO: Need to confirm
- triggers:
- :trigger_schedule
- :deploy_keys
- :services
- :hooks
......
......@@ -5,6 +5,7 @@ module Gitlab
pipelines: 'Ci::Pipeline',
statuses: 'commit_status',
triggers: 'Ci::Trigger',
trigger_schedule: 'Ci::TriggerSchedule',
builds: 'Ci::Build',
hooks: 'ProjectHook',
merge_access_levels: 'ProtectedBranch::MergeAccessLevel',
......
......@@ -100,6 +100,8 @@ triggers:
- trigger_requests
- owner
- trigger_schedule
trigger_schedule:
- trigger
deploy_keys:
- user
- deploy_keys_projects
......
......@@ -249,6 +249,7 @@ Ci::TriggerSchedule:
- created_at
- updated_at
- cron
- cron_time_zone
- next_run_at
DeployKey:
- id
......
......@@ -5,13 +5,6 @@ describe Ci::TriggerSchedule, models: true do
it { is_expected.to belong_to(:trigger) }
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
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