Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
03088552
Commit
03088552
authored
Apr 07, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ref reference
parent
1ae1d85c
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
119 additions
and
36 deletions
+119
-36
app/controllers/projects/triggers_controller.rb
app/controllers/projects/triggers_controller.rb
+2
-3
app/models/ci/trigger.rb
app/models/ci/trigger.rb
+2
-2
app/models/ci/trigger_schedule.rb
app/models/ci/trigger_schedule.rb
+8
-9
app/views/projects/triggers/_form.html.haml
app/views/projects/triggers/_form.html.haml
+34
-19
app/views/projects/triggers/_trigger.html.haml
app/views/projects/triggers/_trigger.html.haml
+2
-2
app/workers/trigger_schedule_worker.rb
app/workers/trigger_schedule_worker.rb
+1
-1
changelogs/unreleased/add-ui-for-trigger-schedule.yml
changelogs/unreleased/add-ui-for-trigger-schedule.yml
+4
-0
db/migrate/20170407114956_add_ref_to_ci_trigger_schedule.rb
db/migrate/20170407114956_add_ref_to_ci_trigger_schedule.rb
+31
-0
db/migrate/20170407122426_add_active_to_ci_trigger_schedule.rb
...grate/20170407122426_add_active_to_ci_trigger_schedule.rb
+31
-0
spec/factories/ci/trigger_schedules.rb
spec/factories/ci/trigger_schedules.rb
+4
-0
No files found.
app/controllers/projects/triggers_controller.rb
View file @
03088552
...
...
@@ -16,7 +16,6 @@ class Projects::TriggersController < Projects::ApplicationController
if
@trigger
.
valid?
flash
[
:notice
]
=
'Trigger was created successfully.'
else
puts
"@trigger.errors:
#{
@trigger
.
errors
.
inspect
}
"
flash
[
:alert
]
=
'You could not create a new trigger.'
end
...
...
@@ -70,8 +69,8 @@ class Projects::TriggersController < Projects::ApplicationController
def
trigger_params
params
.
require
(
:trigger
).
permit
(
:description
,
:ref
,
trigger_schedule_attributes:
[
:
cron
,
:cron_timezone
,
:_destroy
]
:description
,
trigger_schedule_attributes:
[
:
id
,
:active
,
:cron
,
:cron_timezone
,
:ref
]
)
end
end
app/models/ci/trigger.rb
View file @
03088552
...
...
@@ -8,7 +8,7 @@ module Ci
belongs_to
:owner
,
class_name:
"User"
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
...
...
@@ -41,7 +41,7 @@ module Ci
end
def
trigger_schedule
super
||
build_trigger_schedule
super
||
build_trigger_schedule
(
project:
project
)
end
end
end
app/models/ci/trigger_schedule.rb
View file @
03088552
...
...
@@ -6,20 +6,19 @@ module Ci
acts_as_paranoid
belongs_to
:project
belongs_to
:trigger
,
inverse_of: :trigger_schedule
delegate
:ref
,
to: :trigger
,
allow_nil:
true
belongs_to
:trigger
validates
:trigger
,
presence:
{
unless: :importing?
}
validates
:cron
,
cron:
true
,
presence:
{
unless: :importing
?
}
validates
:cron_timezone
,
cron_timezone:
true
,
presence:
{
unless: :importing?
}
validates
:ref
,
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
_or_inactive
?
}
validates
:ref
,
presence:
{
unless: :importing
_or_inactive
?
}
before_create
:set_project
before_save
:set_next_run_at
def
set_project
self
.
project
=
trigger
.
project
scope
:active
,
->
{
where
(
active:
true
)
}
def
importing_or_inactive?
importing?
||
!
active?
end
def
set_next_run_at
...
...
app/views/projects/triggers/_form.html.haml
View file @
03088552
...
...
@@ -6,24 +6,39 @@
%label
.label-light
Token
%p
.form-control-static
=
@trigger
.
token
.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
.
fields_for
:trigger_schedule
do
|
schedule_fields
|
.form-group
=
schedule_fields
.
label
:cron
,
"Cron (For scheduled trigger)"
,
class:
"label-light"
=
schedule_fields
.
text_field
:cron
,
class:
"form-control"
,
title:
'Trigger Schedule cron is required.'
,
placeholder:
"0 1 * * *"
.form-group
=
schedule_fields
.
label
:cron_timezone
,
"Cron timezone (For scheduled trigger)"
,
class:
"label-light"
=
schedule_fields
.
text_field
:cron_timezone
,
class:
"form-control"
,
title:
'Trigger Schedule cron_timezone is required.'
,
placeholder:
"UTC"
.form-group
=
f
.
label
:ref
,
"Ref (For scheduled trigger)"
,
class:
"label-light"
=
f
.
text_field
:ref
,
class:
"form-control"
,
title:
'Trigger Schedule Ref is required.'
,
placeholder:
"master"
.form-group
.checkbox
=
schedule_fields
.
label
:_destroy
do
=
schedule_fields
.
check_box
:_destroy
,
{
checked:
(
@trigger
.
trigger_schedule
.
id
.
present?
)
},
0
,
1
%strong
Register as scheduled trigger
.help-block
If checked, this trigger will be executed periodically according to `cron`, `cron_timezone` and `ref`
=
link_to
icon
(
'question-circle'
),
help_page_path
(
'user/project/pipelines/settings'
,
anchor:
'visibility-of-pipelines'
)
-
if
@trigger
.
persisted?
%hr
=
f
.
fields_for
:trigger_schedule
do
|
schedule_fields
|
=
schedule_fields
.
hidden_field
:id
.form-group
.checkbox
=
schedule_fields
.
label
:active
do
=
schedule_fields
.
check_box
:active
%strong
Schedule trigger
.help-block
If checked, this trigger will be executed periodically according to `cron`, `cron_timezone` and `ref`
=
link_to
icon
(
'question-circle'
),
help_page_path
(
'user/project/pipelines/settings'
,
anchor:
'visibility-of-pipelines'
)
.form-group
=
schedule_fields
.
label
:cron
,
"Cron"
,
class:
"label-light"
=
schedule_fields
.
text_field
:cron
,
class:
"form-control"
,
title:
'Trigger Schedule cron is required.'
,
placeholder:
"0 1 * * *"
.form-group
=
schedule_fields
.
label
:cron
,
"Timezone"
,
class:
"label-light"
=
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"
:javascript
var
availableRefs
=
#{
@project
.
repository
.
ref_names
.
to_json
}
;
new
NewBranchForm
(
$
(
'
.js-new-pipeline-form
'
),
availableRefs
)
app/views/projects/triggers/_trigger.html.haml
View file @
03088552
...
...
@@ -30,10 +30,10 @@
Never
%td
-
if
trigger
.
trigger_schedule
.
p
ersisted
?
-
if
trigger
.
trigger_schedule
.
p
resent?
&&
trigger
.
trigger_schedule
.
active
?
=
trigger
.
trigger_schedule
.
real_next_run
-
else
None
(External trigger)
None
%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?"
...
...
app/workers/trigger_schedule_worker.rb
View file @
03088552
...
...
@@ -3,7 +3,7 @@ class TriggerScheduleWorker
include
CronjobQueue
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
Ci
::
CreateTriggerRequestService
.
new
.
execute
(
trigger_schedule
.
project
,
trigger_schedule
.
trigger
,
...
...
changelogs/unreleased/add-ui-for-trigger-schedule.yml
0 → 100644
View file @
03088552
---
title
:
Add UI for Trigger Schedule
merge_request
:
author
:
db/migrate/20170407114956_add_ref_to_ci_trigger_schedule.rb
0 → 100644
View file @
03088552
# 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
db/migrate/20170407122426_add_active_to_ci_trigger_schedule.rb
0 → 100644
View file @
03088552
# 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
spec/factories/ci/trigger_schedules.rb
View file @
03088552
...
...
@@ -4,6 +4,10 @@ FactoryGirl.define do
cron
'0 1 * * *'
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
cron
'0 1 * * *'
cron_timezone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment