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
3ea04616
Commit
3ea04616
authored
Jun 26, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement variables_attributes create/update cases
parent
58d8b9ae
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
376 additions
and
22 deletions
+376
-22
app/controllers/projects/pipeline_schedules_controller.rb
app/controllers/projects/pipeline_schedules_controller.rb
+3
-2
app/models/ci/pipeline_schedule.rb
app/models/ci/pipeline_schedule.rb
+0
-10
app/services/ci/create_pipeline_schedule_service.rb
app/services/ci/create_pipeline_schedule_service.rb
+28
-2
spec/controllers/projects/pipeline_schedules_controller_spec.rb
...ontrollers/projects/pipeline_schedules_controller_spec.rb
+345
-8
No files found.
app/controllers/projects/pipeline_schedules_controller.rb
View file @
3ea04616
...
...
@@ -33,7 +33,8 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
end
def
update
if
schedule
.
update
(
schedule_params
)
if
Ci
::
CreatePipelineScheduleService
.
new
(
@project
,
current_user
,
schedule_params
).
update
(
schedule
)
redirect_to
namespace_project_pipeline_schedules_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
)
else
render
:edit
...
...
@@ -67,6 +68,6 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
def
schedule_params
params
.
require
(
:schedule
)
.
permit
(
:description
,
:cron
,
:cron_timezone
,
:ref
,
:active
,
variables_attributes:
[
:
key
,
:value
]
)
variables_attributes:
[
:
id
,
:key
,
:value
,
:_destroy
]
)
end
end
app/models/ci/pipeline_schedule.rb
View file @
3ea04616
...
...
@@ -15,7 +15,6 @@ module Ci
validates
:cron_timezone
,
cron_timezone:
true
,
presence:
{
unless: :importing?
}
validates
:ref
,
presence:
{
unless: :importing?
}
validates
:description
,
presence:
true
validates_associated
:variables
before_save
:set_next_run_at
...
...
@@ -24,15 +23,6 @@ module Ci
accepts_nested_attributes_for
:variables
,
allow_destroy:
true
before_validation
(
on: :update
)
do
# TODO: if validation failed, restore the deleted_obj
deleted_obj
=
Ci
::
PipelineScheduleVariable
.
where
(
pipeline_schedule_id:
self
).
destroy_all
end
after_validation
(
on: :update
)
do
# TODO: if validation failed, restore the deleted_obj
end
def
owned_by?
(
current_user
)
owner
==
current_user
end
...
...
app/services/ci/create_pipeline_schedule_service.rb
View file @
3ea04616
module
Ci
class
CreatePipelineScheduleService
<
BaseService
def
execute
project
.
pipeline_schedules
.
create
(
pipeline_schedule_params
)
pipeline_schedule
=
project
.
pipeline_schedules
.
build
(
pipeline_schedule_params
)
if
variable_keys_duplicated?
pipeline_schedule
.
errors
.
add
(
'variables.key'
,
"keys are duplicated"
)
return
pipeline_schedule
end
pipeline_schedule
.
save
pipeline_schedule
end
def
update
(
pipeline_schedule
)
if
variable_keys_duplicated?
pipeline_schedule
.
errors
.
add
(
'variables.key'
,
"keys are duplicated"
)
return
false
end
pipeline_schedule
.
update
(
pipeline_schedule_params
)
end
private
def
pipeline_schedule_params
params
.
merge
(
owner:
current_user
)
@pipeline_schedule_params
||=
params
.
merge
(
owner:
current_user
)
end
def
variable_keys_duplicated?
attributes
=
pipeline_schedule_params
[
'variables_attributes'
]
return
false
unless
attributes
.
is_a?
(
Array
)
attributes
.
map
{
|
v
|
v
[
'key'
]
}.
uniq
.
length
!=
attributes
.
length
end
end
end
spec/controllers/projects/pipeline_schedules_controller_spec.rb
View file @
3ea04616
This diff is collapsed.
Click to expand it.
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