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
e364c118
Commit
e364c118
authored
Jun 26, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement variables_attributes create/update cases
parent
507fedf3
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
315 additions
and
298 deletions
+315
-298
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
+284
-284
No files found.
app/controllers/projects/pipeline_schedules_controller.rb
View file @
e364c118
...
...
@@ -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 @
e364c118
...
...
@@ -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 @
e364c118
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 @
e364c118
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