Commit 03088552 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix ref reference

parent 1ae1d85c
...@@ -16,7 +16,6 @@ class Projects::TriggersController < Projects::ApplicationController ...@@ -16,7 +16,6 @@ class Projects::TriggersController < Projects::ApplicationController
if @trigger.valid? if @trigger.valid?
flash[:notice] = 'Trigger was created successfully.' flash[:notice] = 'Trigger was created successfully.'
else else
puts "@trigger.errors: #{@trigger.errors.inspect}"
flash[:alert] = 'You could not create a new trigger.' flash[:alert] = 'You could not create a new trigger.'
end end
...@@ -70,8 +69,8 @@ class Projects::TriggersController < Projects::ApplicationController ...@@ -70,8 +69,8 @@ class Projects::TriggersController < Projects::ApplicationController
def trigger_params def trigger_params
params.require(:trigger).permit( params.require(:trigger).permit(
:description, :ref, :description,
trigger_schedule_attributes: [:cron, :cron_timezone, :_destroy] trigger_schedule_attributes: [:id, :active, :cron, :cron_timezone, :ref]
) )
end end
end end
...@@ -8,7 +8,7 @@ module Ci ...@@ -8,7 +8,7 @@ module Ci
belongs_to :owner, class_name: "User" belongs_to :owner, class_name: "User"
has_many :trigger_requests, dependent: :destroy has_many :trigger_requests, dependent: :destroy
has_one :trigger_schedule, dependent: :destroy, inverse_of: :trigger has_one :trigger_schedule, dependent: :destroy
validates :token, presence: true, uniqueness: true validates :token, presence: true, uniqueness: true
...@@ -41,7 +41,7 @@ module Ci ...@@ -41,7 +41,7 @@ module Ci
end end
def trigger_schedule def trigger_schedule
super || build_trigger_schedule super || build_trigger_schedule(project: project)
end end
end end
end end
...@@ -6,20 +6,19 @@ module Ci ...@@ -6,20 +6,19 @@ module Ci
acts_as_paranoid acts_as_paranoid
belongs_to :project belongs_to :project
belongs_to :trigger, inverse_of: :trigger_schedule belongs_to :trigger
delegate :ref, to: :trigger, allow_nil: true
validates :trigger, presence: { unless: :importing? } validates :trigger, presence: { unless: :importing? }
validates :cron, cron: true, presence: { unless: :importing? } validates :cron, unless: :importing_or_inactive?, cron: true, presence: { unless: :importing_or_inactive? }
validates :cron_timezone, cron_timezone: true, presence: { unless: :importing? } validates :cron_timezone, cron_timezone: true, presence: { unless: :importing_or_inactive? }
validates :ref, presence: { unless: :importing? } validates :ref, presence: { unless: :importing_or_inactive? }
before_create :set_project
before_save :set_next_run_at before_save :set_next_run_at
def set_project scope :active, -> { where(active: true) }
self.project = trigger.project
def importing_or_inactive?
importing? || !active?
end end
def set_next_run_at def set_next_run_at
......
...@@ -6,24 +6,39 @@ ...@@ -6,24 +6,39 @@
%label.label-light Token %label.label-light Token
%p.form-control-static= @trigger.token %p.form-control-static= @trigger.token
.form-group .form-group
= f.label :key, "Description (For extenral trigger and scheduled trigger)", class: "label-light" = f.label :key, "Description", class: "label-light"
= f.text_field :description, class: "form-control", required: true, title: 'Trigger description is required.', placeholder: "Trigger description" = f.text_field :description, class: "form-control", required: true, title: 'Trigger description is required.', placeholder: "Trigger description"
= f.fields_for :trigger_schedule do |schedule_fields| - if @trigger.persisted?
.form-group %hr
= schedule_fields.label :cron, "Cron (For scheduled trigger)", class: "label-light" = f.fields_for :trigger_schedule do |schedule_fields|
= schedule_fields.text_field :cron, class: "form-control", title: 'Trigger Schedule cron is required.', placeholder: "0 1 * * *" = schedule_fields.hidden_field :id
.form-group .form-group
= schedule_fields.label :cron_timezone, "Cron timezone (For scheduled trigger)", class: "label-light" .checkbox
= schedule_fields.text_field :cron_timezone, class: "form-control", title: 'Trigger Schedule cron_timezone is required.', placeholder: "UTC" = schedule_fields.label :active do
.form-group = schedule_fields.check_box :active
= f.label :ref, "Ref (For scheduled trigger)", class: "label-light" %strong Schedule trigger
= f.text_field :ref, class: "form-control", title: 'Trigger Schedule Ref is required.', placeholder: "master" .help-block
.form-group If checked, this trigger will be executed periodically according to `cron`, `cron_timezone` and `ref`
.checkbox = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'visibility-of-pipelines')
= schedule_fields.label :_destroy do .form-group
= schedule_fields.check_box :_destroy, { checked: (@trigger.trigger_schedule.id.present?) }, 0, 1 = schedule_fields.label :cron, "Cron", class: "label-light"
%strong Register as scheduled trigger = schedule_fields.text_field :cron, class: "form-control", title: 'Trigger Schedule cron is required.', placeholder: "0 1 * * *"
.help-block .form-group
If checked, this trigger will be executed periodically according to `cron`, `cron_timezone` and `ref` = schedule_fields.label :cron, "Timezone", class: "label-light"
= link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'visibility-of-pipelines') = schedule_fields.text_field :cron_timezone, class: "form-control", title: 'Trigger Schedule cron_timezone is required.', placeholder: "UTC"
.form-group
- schedule_ref = @trigger.trigger_schedule.ref || @project.default_branch
= schedule_fields.label :ref, "Branch or tag", class: "label-light"
= hidden_field_tag 'trigger[trigger_schedule_attributes][ref]', schedule_ref
= dropdown_tag(schedule_ref,
options: { toggle_class: 'js-branch-select wide',
filter: true, dropdown_class: "dropdown-menu-selectable", placeholder: "Search branches",
data: { selected: schedule_ref, field_name: 'trigger[trigger_schedule_attributes][ref]' } })
.help-block Existing branch name, tag
= f.submit btn_text, class: "btn btn-save" = f.submit btn_text, class: "btn btn-save"
:javascript
var availableRefs = #{@project.repository.ref_names.to_json};
new NewBranchForm($('.js-new-pipeline-form'), availableRefs)
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
Never Never
%td %td
- if trigger.trigger_schedule.persisted? - if trigger.trigger_schedule.present? && trigger.trigger_schedule.active?
= trigger.trigger_schedule.real_next_run = trigger.trigger_schedule.real_next_run
- else - else
None (External trigger) None
%td.text-right.trigger-actions %td.text-right.trigger-actions
- take_ownership_confirmation = "By taking ownership you will bind this trigger to your user account. With this the trigger will have access to all your projects as if it was you. Are you sure?" - take_ownership_confirmation = "By taking ownership you will bind this trigger to your user account. With this the trigger will have access to all your projects as if it was you. Are you sure?"
......
...@@ -3,7 +3,7 @@ class TriggerScheduleWorker ...@@ -3,7 +3,7 @@ class TriggerScheduleWorker
include CronjobQueue include CronjobQueue
def perform def perform
Ci::TriggerSchedule.where("next_run_at < ?", Time.now).find_each do |trigger_schedule| Ci::TriggerSchedule.active.where("next_run_at < ?", Time.now).find_each do |trigger_schedule|
begin begin
Ci::CreateTriggerRequestService.new.execute(trigger_schedule.project, Ci::CreateTriggerRequestService.new.execute(trigger_schedule.project,
trigger_schedule.trigger, trigger_schedule.trigger,
......
---
title: Add UI for Trigger Schedule
merge_request:
author:
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddRefToCiTriggerSchedule < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
# DOWNTIME_REASON = ''
# When using the methods "add_concurrent_index", "remove_concurrent_index" or
# "add_column_with_default" you must disable the use of transactions
# as these methods can not run in an existing transaction.
# When using "add_concurrent_index" or "remove_concurrent_index" methods make sure
# that either of them is the _only_ method called in the migration,
# any other changes should go in a separate migration.
# This ensures that upon failure _only_ the index creation or removing fails
# and can be retried or reverted easily.
#
# To disable transactions uncomment the following line and remove these
# comments:
# disable_ddl_transaction!
def change
add_column :ci_trigger_schedules, :ref, :string
end
end
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddActiveToCiTriggerSchedule < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
# DOWNTIME_REASON = ''
# When using the methods "add_concurrent_index", "remove_concurrent_index" or
# "add_column_with_default" you must disable the use of transactions
# as these methods can not run in an existing transaction.
# When using "add_concurrent_index" or "remove_concurrent_index" methods make sure
# that either of them is the _only_ method called in the migration,
# any other changes should go in a separate migration.
# This ensures that upon failure _only_ the index creation or removing fails
# and can be retried or reverted easily.
#
# To disable transactions uncomment the following line and remove these
# comments:
# disable_ddl_transaction!
def change
add_column :ci_trigger_schedules, :active, :boolean
end
end
...@@ -4,6 +4,10 @@ FactoryGirl.define do ...@@ -4,6 +4,10 @@ FactoryGirl.define do
cron '0 1 * * *' cron '0 1 * * *'
cron_timezone Gitlab::Ci::CronParser::VALID_SYNTAX_SAMPLE_TIME_ZONE cron_timezone Gitlab::Ci::CronParser::VALID_SYNTAX_SAMPLE_TIME_ZONE
after(:build) do |trigger_schedule, evaluator|
trigger_schedule.update!(project: trigger_schedule.trigger.project)
end
trait :nightly do trait :nightly do
cron '0 1 * * *' cron '0 1 * * *'
cron_timezone Gitlab::Ci::CronParser::VALID_SYNTAX_SAMPLE_TIME_ZONE cron_timezone Gitlab::Ci::CronParser::VALID_SYNTAX_SAMPLE_TIME_ZONE
......
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