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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
76c0364c
Commit
76c0364c
authored
Apr 07, 2017
by
Shinya Maeda
Committed by
Kamil Trzcinski
Apr 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use allow_destroy. Remove condtion from form.haml.
parent
2548c155
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
24 deletions
+13
-24
app/controllers/projects/triggers_controller.rb
app/controllers/projects/triggers_controller.rb
+6
-4
app/models/ci/trigger.rb
app/models/ci/trigger.rb
+2
-13
app/models/ci/trigger_schedule.rb
app/models/ci/trigger_schedule.rb
+3
-2
app/views/projects/triggers/_form.html.haml
app/views/projects/triggers/_form.html.haml
+2
-5
No files found.
app/controllers/projects/triggers_controller.rb
View file @
76c0364c
...
...
@@ -16,6 +16,7 @@ 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
...
...
@@ -33,6 +34,7 @@ class Projects::TriggersController < Projects::ApplicationController
end
def
edit
@trigger
.
build_trigger_schedule
unless
@trigger
.
trigger_schedule
.
present?
end
def
update
...
...
@@ -69,15 +71,15 @@ class Projects::TriggersController < Projects::ApplicationController
def
create_params
params
.
require
(
:trigger
).
permit
(
:description
,
:ref
,
:trigger_schedule_on
,
trigger_schedule_attributes:
[
:cron
,
:cron_timezone
]
:description
,
:ref
,
trigger_schedule_attributes:
[
:cron
,
:cron_timezone
,
:_destroy
]
)
end
def
update_params
params
.
require
(
:trigger
).
permit
(
:description
,
:ref
,
:trigger_schedule_on
,
trigger_schedule_attributes:
[
:cron
,
:cron_timezone
]
:description
,
:ref
,
trigger_schedule_attributes:
[
:cron
,
:cron_timezone
,
:_destroy
]
)
end
end
app/models/ci/trigger.rb
View file @
76c0364c
...
...
@@ -8,27 +8,16 @@ module Ci
belongs_to
:owner
,
class_name:
"User"
has_many
:trigger_requests
,
dependent: :destroy
has_one
:trigger_schedule
,
dependent: :destroy
has_one
:trigger_schedule
,
dependent: :destroy
,
inverse_of: :trigger
validates
:token
,
presence:
true
,
uniqueness:
true
before_validation
:set_default_values
accepts_nested_attributes_for
:trigger_schedule
attr_accessor
:trigger_schedule_on
accepts_nested_attributes_for
:trigger_schedule
,
allow_destroy:
true
def
set_default_values
self
.
token
=
SecureRandom
.
hex
(
15
)
if
self
.
token
.
blank?
if
trigger_schedule_on
.
present?
if
trigger_schedule_on
.
to_i
==
1
self
.
trigger_schedule
.
project
=
project
self
.
trigger_schedule
.
trigger
=
self
else
self
.
trigger_schedule
=
nil
end
end
end
def
last_trigger_request
...
...
app/models/ci/trigger_schedule.rb
View file @
76c0364c
...
...
@@ -6,11 +6,11 @@ module Ci
acts_as_paranoid
belongs_to
:project
belongs_to
:trigger
belongs_to
:trigger
,
inverse_of: :trigger_schedule
delegate
:ref
,
to: :trigger
,
allow_nil:
true
validates
:trigger
,
presence:
{
unless: :importing?
}
validates
_presence_of
:trigger
validates
:cron
,
cron:
true
,
presence:
{
unless: :importing?
}
validates
:cron_timezone
,
cron_timezone:
true
,
presence:
{
unless: :importing?
}
validates
:ref
,
presence:
{
unless: :importing?
}
...
...
@@ -19,6 +19,7 @@ module Ci
def
set_next_run_at
self
.
next_run_at
=
Gitlab
::
Ci
::
CronParser
.
new
(
cron
,
cron_timezone
).
next_time_from
(
Time
.
now
)
self
.
project
=
trigger
.
project
end
def
schedule_next_run!
...
...
app/views/projects/triggers/_form.html.haml
View file @
76c0364c
...
...
@@ -18,13 +18,10 @@
.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"
-
if
action_name
==
'edit'
=
f
.
hidden_field
:trigger_schedule_on
,
:value
=>
@trigger
.
trigger_schedule
.
present?
?
1
:
0
-
else
.form-group
.checkbox
=
f
.
label
:trigger_schedule_on
do
=
f
.
check_box
:trigger_schedule_on
=
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`
...
...
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