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
856a511b
Commit
856a511b
authored
May 05, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor code based on feedback
parent
f15466bd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
15 deletions
+17
-15
app/services/projects/propagate_service_template.rb
app/services/projects/propagate_service_template.rb
+6
-6
app/workers/propagate_service_template_worker.rb
app/workers/propagate_service_template_worker.rb
+0
-2
spec/services/projects/propagate_service_template_spec.rb
spec/services/projects/propagate_service_template_spec.rb
+11
-7
No files found.
app/services/projects/propagate_service_template.rb
View file @
856a511b
...
@@ -11,7 +11,7 @@ module Projects
...
@@ -11,7 +11,7 @@ module Projects
end
end
def
propagate
def
propagate
return
unless
@template
&
.
active?
return
unless
@template
.
active?
Rails
.
logger
.
info
(
"Propagating services for template
#{
@template
.
id
}
"
)
Rails
.
logger
.
info
(
"Propagating services for template
#{
@template
.
id
}
"
)
...
@@ -32,11 +32,11 @@ module Projects
...
@@ -32,11 +32,11 @@ module Projects
def
bulk_create_from_template
(
batch
)
def
bulk_create_from_template
(
batch
)
service_list
=
batch
.
map
do
|
project_id
|
service_list
=
batch
.
map
do
|
project_id
|
service_hash
.
merge
(
'project_id'
=>
project_id
).
values
service_hash
.
values
<<
project_id
end
end
Project
.
transaction
do
Project
.
transaction
do
bulk_insert_services
(
service_hash
.
keys
+
[
'project_id'
]
,
service_list
)
bulk_insert_services
(
service_hash
.
keys
<<
'project_id'
,
service_list
)
run_callbacks
(
batch
)
run_callbacks
(
batch
)
end
end
end
end
...
@@ -75,9 +75,9 @@ module Projects
...
@@ -75,9 +75,9 @@ module Projects
template_hash
.
each_with_object
({})
do
|
(
key
,
value
),
service_hash
|
template_hash
.
each_with_object
({})
do
|
(
key
,
value
),
service_hash
|
value
=
value
.
is_a?
(
Hash
)
?
value
.
to_json
:
value
value
=
value
.
is_a?
(
Hash
)
?
value
.
to_json
:
value
key
=
Gitlab
::
Database
.
postgresql?
?
"
\"
#{
key
}
\"
"
:
"`
#{
key
}
`"
service_hash
[
key
]
=
ActiveRecord
::
Base
.
sanitize
(
value
)
service_hash
[
ActiveRecord
::
Base
.
connection
.
quote_column_name
(
key
)]
=
ActiveRecord
::
Base
.
sanitize
(
value
)
end
end
end
end
end
end
...
@@ -93,7 +93,7 @@ module Projects
...
@@ -93,7 +93,7 @@ module Projects
end
end
def
active_external_issue_tracker?
def
active_external_issue_tracker?
@template
.
category
==
:issue_tracker
&&
!
@template
.
default
@template
.
issue_tracker?
&&
!
@template
.
default
end
end
def
active_external_wiki?
def
active_external_wiki?
...
...
app/workers/propagate_service_template_worker.rb
View file @
856a511b
...
@@ -3,8 +3,6 @@ class PropagateServiceTemplateWorker
...
@@ -3,8 +3,6 @@ class PropagateServiceTemplateWorker
include
Sidekiq
::
Worker
include
Sidekiq
::
Worker
include
DedicatedSidekiqQueue
include
DedicatedSidekiqQueue
sidekiq_options
retry:
3
LEASE_TIMEOUT
=
4
.
hours
.
to_i
LEASE_TIMEOUT
=
4
.
hours
.
to_i
def
perform
(
template_id
)
def
perform
(
template_id
)
...
...
spec/services/projects/propagate_service_template_spec.rb
View file @
856a511b
...
@@ -18,8 +18,11 @@ describe Projects::PropagateServiceTemplate, services: true do
...
@@ -18,8 +18,11 @@ describe Projects::PropagateServiceTemplate, services: true do
let!
(
:project
)
{
create
(
:empty_project
)
}
let!
(
:project
)
{
create
(
:empty_project
)
}
it
'creates services for projects'
do
it
'creates services for projects'
do
expect
{
described_class
.
propagate
(
service_template
)
}.
expect
(
project
.
pushover_service
).
to
be_nil
to
change
{
Service
.
count
}.
by
(
1
)
described_class
.
propagate
(
service_template
)
expect
(
project
.
reload
.
pushover_service
).
to
be_present
end
end
it
'creates services for a project that has another service'
do
it
'creates services for a project that has another service'
do
...
@@ -35,8 +38,11 @@ describe Projects::PropagateServiceTemplate, services: true do
...
@@ -35,8 +38,11 @@ describe Projects::PropagateServiceTemplate, services: true do
}
}
)
)
expect
{
described_class
.
propagate
(
service_template
)
}.
expect
(
project
.
pushover_service
).
to
be_nil
to
change
{
Service
.
count
}.
by
(
1
)
described_class
.
propagate
(
service_template
)
expect
(
project
.
reload
.
pushover_service
).
to
be_present
end
end
it
'does not create the service if it exists already'
do
it
'does not create the service if it exists already'
do
...
@@ -61,9 +67,7 @@ describe Projects::PropagateServiceTemplate, services: true do
...
@@ -61,9 +67,7 @@ describe Projects::PropagateServiceTemplate, services: true do
it
'creates the service containing the template attributes'
do
it
'creates the service containing the template attributes'
do
described_class
.
propagate
(
service_template
)
described_class
.
propagate
(
service_template
)
service
=
Service
.
find_by!
(
type:
service_template
.
type
,
template:
false
)
expect
(
project
.
pushover_service
.
properties
).
to
eq
(
service_template
.
properties
)
expect
(
service
.
properties
).
to
eq
(
service_template
.
properties
)
end
end
describe
'bulk update'
do
describe
'bulk update'
do
...
...
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