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
Jérome Perrin
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
Show 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
...
@@ -16,6 +16,7 @@ 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
...
@@ -33,6 +34,7 @@ class Projects::TriggersController < Projects::ApplicationController
...
@@ -33,6 +34,7 @@ class Projects::TriggersController < Projects::ApplicationController
end
end
def
edit
def
edit
@trigger
.
build_trigger_schedule
unless
@trigger
.
trigger_schedule
.
present?
end
end
def
update
def
update
...
@@ -69,15 +71,15 @@ class Projects::TriggersController < Projects::ApplicationController
...
@@ -69,15 +71,15 @@ class Projects::TriggersController < Projects::ApplicationController
def
create_params
def
create_params
params
.
require
(
:trigger
).
permit
(
params
.
require
(
:trigger
).
permit
(
:description
,
:ref
,
:trigger_schedule_on
,
:description
,
:ref
,
trigger_schedule_attributes:
[
:cron
,
:cron_timezone
]
trigger_schedule_attributes:
[
:cron
,
:cron_timezone
,
:_destroy
]
)
)
end
end
def
update_params
def
update_params
params
.
require
(
:trigger
).
permit
(
params
.
require
(
:trigger
).
permit
(
:description
,
:ref
,
:trigger_schedule_on
,
:description
,
:ref
,
trigger_schedule_attributes:
[
:cron
,
:cron_timezone
]
trigger_schedule_attributes:
[
:cron
,
:cron_timezone
,
:_destroy
]
)
)
end
end
end
end
app/models/ci/trigger.rb
View file @
76c0364c
...
@@ -8,27 +8,16 @@ module Ci
...
@@ -8,27 +8,16 @@ 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
has_one
:trigger_schedule
,
dependent: :destroy
,
inverse_of: :trigger
validates
:token
,
presence:
true
,
uniqueness:
true
validates
:token
,
presence:
true
,
uniqueness:
true
before_validation
:set_default_values
before_validation
:set_default_values
accepts_nested_attributes_for
:trigger_schedule
accepts_nested_attributes_for
:trigger_schedule
,
allow_destroy:
true
attr_accessor
:trigger_schedule_on
def
set_default_values
def
set_default_values
self
.
token
=
SecureRandom
.
hex
(
15
)
if
self
.
token
.
blank?
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
end
def
last_trigger_request
def
last_trigger_request
...
...
app/models/ci/trigger_schedule.rb
View file @
76c0364c
...
@@ -6,11 +6,11 @@ module Ci
...
@@ -6,11 +6,11 @@ module Ci
acts_as_paranoid
acts_as_paranoid
belongs_to
:project
belongs_to
:project
belongs_to
:trigger
belongs_to
:trigger
,
inverse_of: :trigger_schedule
delegate
:ref
,
to: :trigger
,
allow_nil:
true
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
,
cron:
true
,
presence:
{
unless: :importing?
}
validates
:cron_timezone
,
cron_timezone:
true
,
presence:
{
unless: :importing?
}
validates
:cron_timezone
,
cron_timezone:
true
,
presence:
{
unless: :importing?
}
validates
:ref
,
presence:
{
unless: :importing?
}
validates
:ref
,
presence:
{
unless: :importing?
}
...
@@ -19,6 +19,7 @@ module Ci
...
@@ -19,6 +19,7 @@ module Ci
def
set_next_run_at
def
set_next_run_at
self
.
next_run_at
=
Gitlab
::
Ci
::
CronParser
.
new
(
cron
,
cron_timezone
).
next_time_from
(
Time
.
now
)
self
.
next_run_at
=
Gitlab
::
Ci
::
CronParser
.
new
(
cron
,
cron_timezone
).
next_time_from
(
Time
.
now
)
self
.
project
=
trigger
.
project
end
end
def
schedule_next_run!
def
schedule_next_run!
...
...
app/views/projects/triggers/_form.html.haml
View file @
76c0364c
...
@@ -18,13 +18,10 @@
...
@@ -18,13 +18,10 @@
.form-group
.form-group
=
f
.
label
:ref
,
"Ref (For scheduled trigger)"
,
class:
"label-light"
=
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"
=
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
.form-group
.checkbox
.checkbox
=
f
.
label
:trigger_schedule_on
do
=
schedule_fields
.
label
:_destroy
do
=
f
.
check_box
:trigger_schedule_on
=
schedule_fields
.
check_box
:_destroy
,
{
checked:
(
@trigger
.
trigger_schedule
.
id
.
present?
)
},
0
,
1
%strong
Register as scheduled trigger
%strong
Register as scheduled trigger
.help-block
.help-block
If checked, this trigger will be executed periodically according to `cron`, `cron_timezone` and `ref`
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