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
8d4d9705
Commit
8d4d9705
authored
Feb 11, 2020
by
Andy Soiron
Committed by
Mayra Cabrera
Feb 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert MR 23595
This reverts commit
007587cc
except migrations
parent
c8ace7cd
Changes
33
Hide whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
182 additions
and
200 deletions
+182
-200
app/controllers/admin/services_controller.rb
app/controllers/admin/services_controller.rb
+6
-6
app/models/project.rb
app/models/project.rb
+7
-7
app/models/project_services/issue_tracker_service.rb
app/models/project_services/issue_tracker_service.rb
+1
-1
app/models/project_services/prometheus_service.rb
app/models/project_services/prometheus_service.rb
+1
-1
app/models/service.rb
app/models/service.rb
+12
-8
app/services/projects/create_service.rb
app/services/projects/create_service.rb
+4
-4
app/services/projects/propagate_service_template.rb
app/services/projects/propagate_service_template.rb
+14
-14
app/views/projects/services/mattermost_slash_commands/_help.html.haml
...ojects/services/mattermost_slash_commands/_help.html.haml
+2
-2
app/views/projects/services/slack_slash_commands/_help.html.haml
...ws/projects/services/slack_slash_commands/_help.html.haml
+1
-1
app/workers/all_queues.yml
app/workers/all_queues.yml
+1
-1
app/workers/propagate_service_template_worker.rb
app/workers/propagate_service_template_worker.rb
+26
-0
changelogs/unreleased/rename_services_template_to_instance.yml
...elogs/unreleased/rename_services_template_to_instance.yml
+0
-5
config/sidekiq_queues.yml
config/sidekiq_queues.yml
+1
-1
db/migrate/20200123092602_rename_services_template_to_instance.rb
...te/20200123092602_rename_services_template_to_instance.rb
+0
-17
db/post_migrate/20191021101942_remove_empty_github_service_templates.rb
...e/20191021101942_remove_empty_github_service_templates.rb
+0
-4
db/post_migrate/20200123101859_cleanup_rename_services_template_to_instance.rb
...123101859_cleanup_rename_services_template_to_instance.rb
+0
-17
db/post_migrate/20200206111847_migrate_propagate_service_template_sidekiq_queue.rb
...11847_migrate_propagate_service_template_sidekiq_queue.rb
+0
-15
db/schema.rb
db/schema.rb
+2
-2
ee/app/views/projects/services/gitlab_slack_application/_help.html.haml
...rojects/services/gitlab_slack_application/_help.html.haml
+1
-1
lib/api/services.rb
lib/api/services.rb
+1
-1
lib/gitlab/import_export/import_export.yml
lib/gitlab/import_export/import_export.yml
+1
-1
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+1
-1
spec/controllers/admin/services_controller_spec.rb
spec/controllers/admin/services_controller_spec.rb
+6
-6
spec/controllers/projects/services_controller_spec.rb
spec/controllers/projects/services_controller_spec.rb
+3
-3
spec/fixtures/trace/sample_trace
spec/fixtures/trace/sample_trace
+1
-1
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+2
-2
spec/lib/gitlab/import_export/safe_model_attributes.yml
spec/lib/gitlab/import_export/safe_model_attributes.yml
+1
-1
spec/lib/gitlab/usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+1
-1
spec/migrations/migrate_propagate_service_template_sidekiq_queue_spec.rb
.../migrate_propagate_service_template_sidekiq_queue_spec.rb
+0
-29
spec/models/service_spec.rb
spec/models/service_spec.rb
+30
-22
spec/services/projects/create_service_spec.rb
spec/services/projects/create_service_spec.rb
+7
-7
spec/services/projects/propagate_service_template_spec.rb
spec/services/projects/propagate_service_template_spec.rb
+18
-18
spec/workers/propagate_service_template_worker_spec.rb
spec/workers/propagate_service_template_worker_spec.rb
+31
-0
No files found.
app/controllers/admin/services_controller.rb
View file @
8d4d9705
...
@@ -7,7 +7,7 @@ class Admin::ServicesController < Admin::ApplicationController
...
@@ -7,7 +7,7 @@ class Admin::ServicesController < Admin::ApplicationController
before_action
:service
,
only:
[
:edit
,
:update
]
before_action
:service
,
only:
[
:edit
,
:update
]
def
index
def
index
@services
=
instance_level_servic
es
@services
=
services_templat
es
end
end
def
edit
def
edit
...
@@ -19,7 +19,7 @@ class Admin::ServicesController < Admin::ApplicationController
...
@@ -19,7 +19,7 @@ class Admin::ServicesController < Admin::ApplicationController
def
update
def
update
if
service
.
update
(
service_params
[
:service
])
if
service
.
update
(
service_params
[
:service
])
Propagate
InstanceLevelServic
eWorker
.
perform_async
(
service
.
id
)
if
service
.
active?
Propagate
ServiceTemplat
eWorker
.
perform_async
(
service
.
id
)
if
service
.
active?
redirect_to
admin_application_settings_services_path
,
redirect_to
admin_application_settings_services_path
,
notice:
'Application settings saved successfully'
notice:
'Application settings saved successfully'
...
@@ -31,17 +31,17 @@ class Admin::ServicesController < Admin::ApplicationController
...
@@ -31,17 +31,17 @@ class Admin::ServicesController < Admin::ApplicationController
private
private
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
instance_level_servic
es
def
services_templat
es
Service
.
available_services_names
.
map
do
|
service_name
|
Service
.
available_services_names
.
map
do
|
service_name
|
service
=
"
#{
service_name
}
_service"
.
camelize
.
constantize
service
_template
=
"
#{
service_name
}
_service"
.
camelize
.
constantize
service
.
where
(
instanc
e:
true
).
first_or_create
service
_template
.
where
(
templat
e:
true
).
first_or_create
end
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
service
def
service
@service
||=
Service
.
where
(
id:
params
[
:id
],
instanc
e:
true
).
first
@service
||=
Service
.
where
(
id:
params
[
:id
],
templat
e:
true
).
first
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
...
...
app/models/project.rb
View file @
8d4d9705
...
@@ -1224,13 +1224,13 @@ class Project < ApplicationRecord
...
@@ -1224,13 +1224,13 @@ class Project < ApplicationRecord
service
=
find_service
(
services
,
name
)
service
=
find_service
(
services
,
name
)
return
service
if
service
return
service
if
service
# We should check if
an instance-level
service exists
# We should check if
template for the
service exists
instance_level_service
=
find_service
(
instance_level_servic
es
,
name
)
template
=
find_service
(
services_templat
es
,
name
)
if
instance_level_servic
e
if
templat
e
Service
.
build_from_
instance
(
id
,
instance_level_servic
e
)
Service
.
build_from_
template
(
id
,
templat
e
)
else
else
# If no
instance-level service exists, we should create a new servi
ce. Ex `build_gitlab_ci_service`
# If no
template, we should create an instan
ce. Ex `build_gitlab_ci_service`
public_send
(
"build_
#{
name
}
_service"
)
# rubocop:disable GitlabSecurity/PublicSend
public_send
(
"build_
#{
name
}
_service"
)
# rubocop:disable GitlabSecurity/PublicSend
end
end
end
end
...
@@ -2460,8 +2460,8 @@ class Project < ApplicationRecord
...
@@ -2460,8 +2460,8 @@ class Project < ApplicationRecord
end
end
end
end
def
instance_level_servic
es
def
services_templat
es
@
instance_level_services
||=
Service
.
where
(
instanc
e:
true
)
@
services_templates
||=
Service
.
where
(
templat
e:
true
)
end
end
def
ensure_pages_metadatum
def
ensure_pages_metadatum
...
...
app/models/project_services/issue_tracker_service.rb
View file @
8d4d9705
...
@@ -164,7 +164,7 @@ class IssueTrackerService < Service
...
@@ -164,7 +164,7 @@ class IssueTrackerService < Service
end
end
def
one_issue_tracker
def
one_issue_tracker
return
if
instanc
e?
return
if
templat
e?
return
if
project
.
blank?
return
if
project
.
blank?
if
project
.
services
.
external_issue_trackers
.
where
.
not
(
id:
id
).
any?
if
project
.
services
.
external_issue_trackers
.
where
.
not
(
id:
id
).
any?
...
...
app/models/project_services/prometheus_service.rb
View file @
8d4d9705
...
@@ -85,7 +85,7 @@ class PrometheusService < MonitoringService
...
@@ -85,7 +85,7 @@ class PrometheusService < MonitoringService
end
end
def
prometheus_available?
def
prometheus_available?
return
false
if
instanc
e?
return
false
if
templat
e?
return
false
unless
project
return
false
unless
project
project
.
all_clusters
.
enabled
.
any?
{
|
cluster
|
cluster
.
application_prometheus_available?
}
project
.
all_clusters
.
enabled
.
any?
{
|
cluster
|
cluster
.
application_prometheus_available?
}
...
...
app/models/service.rb
View file @
8d4d9705
...
@@ -32,7 +32,7 @@ class Service < ApplicationRecord
...
@@ -32,7 +32,7 @@ class Service < ApplicationRecord
belongs_to
:project
,
inverse_of: :services
belongs_to
:project
,
inverse_of: :services
has_one
:service_hook
has_one
:service_hook
validates
:project_id
,
presence:
true
,
unless:
proc
{
|
service
|
service
.
instanc
e?
}
validates
:project_id
,
presence:
true
,
unless:
proc
{
|
service
|
service
.
templat
e?
}
validates
:type
,
presence:
true
validates
:type
,
presence:
true
scope
:visible
,
->
{
where
.
not
(
type:
'GitlabIssueTrackerService'
)
}
scope
:visible
,
->
{
where
.
not
(
type:
'GitlabIssueTrackerService'
)
}
...
@@ -70,8 +70,8 @@ class Service < ApplicationRecord
...
@@ -70,8 +70,8 @@ class Service < ApplicationRecord
true
true
end
end
def
instanc
e?
def
templat
e?
instanc
e
templat
e
end
end
def
category
def
category
...
@@ -299,15 +299,15 @@ class Service < ApplicationRecord
...
@@ -299,15 +299,15 @@ class Service < ApplicationRecord
service_names
.
sort_by
(
&
:downcase
)
service_names
.
sort_by
(
&
:downcase
)
end
end
def
self
.
build_from_
instance
(
project_id
,
instance_level_servic
e
)
def
self
.
build_from_
template
(
project_id
,
templat
e
)
service
=
instance_level_servic
e
.
dup
service
=
templat
e
.
dup
if
instance_level_servic
e
.
supports_data_fields?
if
templat
e
.
supports_data_fields?
data_fields
=
instance_level_servic
e
.
data_fields
.
dup
data_fields
=
templat
e
.
data_fields
.
dup
data_fields
.
service
=
service
data_fields
.
service
=
service
end
end
service
.
instanc
e
=
false
service
.
templat
e
=
false
service
.
project_id
=
project_id
service
.
project_id
=
project_id
service
.
active
=
false
if
service
.
active?
&&
!
service
.
valid?
service
.
active
=
false
if
service
.
active?
&&
!
service
.
valid?
service
service
...
@@ -321,6 +321,10 @@ class Service < ApplicationRecord
...
@@ -321,6 +321,10 @@ class Service < ApplicationRecord
nil
nil
end
end
def
self
.
find_by_template
find_by
(
template:
true
)
end
# override if needed
# override if needed
def
supports_data_fields?
def
supports_data_fields?
false
false
...
...
app/services/projects/create_service.rb
View file @
8d4d9705
...
@@ -135,7 +135,7 @@ module Projects
...
@@ -135,7 +135,7 @@ module Projects
if
@project
.
save
if
@project
.
save
unless
@project
.
gitlab_project_import?
unless
@project
.
gitlab_project_import?
create_services_from_active_
instance_level_servic
es
(
@project
)
create_services_from_active_
templat
es
(
@project
)
@project
.
create_labels
@project
.
create_labels
end
end
...
@@ -161,9 +161,9 @@ module Projects
...
@@ -161,9 +161,9 @@ module Projects
end
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
create_services_from_active_
instance_level_servic
es
(
project
)
def
create_services_from_active_
templat
es
(
project
)
Service
.
where
(
instanc
e:
true
,
active:
true
).
each
do
|
template
|
Service
.
where
(
templat
e:
true
,
active:
true
).
each
do
|
template
|
service
=
Service
.
build_from_
instanc
e
(
project
.
id
,
template
)
service
=
Service
.
build_from_
templat
e
(
project
.
id
,
template
)
service
.
save!
service
.
save!
end
end
end
end
...
...
app/services/projects/propagate_
instance_level_servic
e.rb
→
app/services/projects/propagate_
service_templat
e.rb
View file @
8d4d9705
# frozen_string_literal: true
# frozen_string_literal: true
module
Projects
module
Projects
class
Propagate
InstanceLevelServic
e
class
Propagate
ServiceTemplat
e
BATCH_SIZE
=
100
BATCH_SIZE
=
100
def
self
.
propagate
(
*
args
)
def
self
.
propagate
(
*
args
)
new
(
*
args
).
propagate
new
(
*
args
).
propagate
end
end
def
initialize
(
instance_level_servic
e
)
def
initialize
(
templat
e
)
@
instance_level_service
=
instance_level_servic
e
@
template
=
templat
e
end
end
def
propagate
def
propagate
return
unless
@
instance_level_servic
e
.
active?
return
unless
@
templat
e
.
active?
Rails
.
logger
.
info
(
"Propagating services for
instance_level_service
#{
@instance_level_servic
e
.
id
}
"
)
# rubocop:disable Gitlab/RailsLogger
Rails
.
logger
.
info
(
"Propagating services for
template
#{
@templat
e
.
id
}
"
)
# rubocop:disable Gitlab/RailsLogger
propagate_projects_with_
instance_level_servic
e
propagate_projects_with_
templat
e
end
end
private
private
def
propagate_projects_with_
instance_level_servic
e
def
propagate_projects_with_
templat
e
loop
do
loop
do
batch
=
Project
.
uncached
{
project_ids_batch
}
batch
=
Project
.
uncached
{
project_ids_batch
}
bulk_create_from_
instance_level_servic
e
(
batch
)
unless
batch
.
empty?
bulk_create_from_
templat
e
(
batch
)
unless
batch
.
empty?
break
if
batch
.
size
<
BATCH_SIZE
break
if
batch
.
size
<
BATCH_SIZE
end
end
end
end
def
bulk_create_from_
instance_level_servic
e
(
batch
)
def
bulk_create_from_
templat
e
(
batch
)
service_list
=
batch
.
map
do
|
project_id
|
service_list
=
batch
.
map
do
|
project_id
|
service_hash
.
values
<<
project_id
service_hash
.
values
<<
project_id
end
end
...
@@ -52,7 +52,7 @@ module Projects
...
@@ -52,7 +52,7 @@ module Projects
SELECT true
SELECT true
FROM services
FROM services
WHERE services.project_id = projects.id
WHERE services.project_id = projects.id
AND services.type = '
#{
@
instance_level_servic
e
.
type
}
'
AND services.type = '
#{
@
templat
e
.
type
}
'
)
)
AND projects.pending_delete = false
AND projects.pending_delete = false
AND projects.archived = false
AND projects.archived = false
...
@@ -73,9 +73,9 @@ module Projects
...
@@ -73,9 +73,9 @@ module Projects
def
service_hash
def
service_hash
@service_hash
||=
@service_hash
||=
begin
begin
instance_hash
=
@instance_level_service
.
as_json
(
methods: :type
).
except
(
'id'
,
'instanc
e'
,
'project_id'
)
template_hash
=
@template
.
as_json
(
methods: :type
).
except
(
'id'
,
'templat
e'
,
'project_id'
)
instanc
e_hash
.
each_with_object
({})
do
|
(
key
,
value
),
service_hash
|
templat
e_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
service_hash
[
ActiveRecord
::
Base
.
connection
.
quote_column_name
(
key
)]
=
service_hash
[
ActiveRecord
::
Base
.
connection
.
quote_column_name
(
key
)]
=
...
@@ -97,11 +97,11 @@ module Projects
...
@@ -97,11 +97,11 @@ module Projects
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
def
active_external_issue_tracker?
def
active_external_issue_tracker?
@
instance_level_service
.
issue_tracker?
&&
!
@instance_level_servic
e
.
default
@
template
.
issue_tracker?
&&
!
@templat
e
.
default
end
end
def
active_external_wiki?
def
active_external_wiki?
@
instance_level_servic
e
.
type
==
'ExternalWikiService'
@
templat
e
.
type
==
'ExternalWikiService'
end
end
end
end
end
end
app/views/projects/services/mattermost_slash_commands/_help.html.haml
View file @
8d4d9705
...
@@ -10,8 +10,8 @@
...
@@ -10,8 +10,8 @@
%p
.inline
%p
.inline
=
s_
(
"MattermostService|See list of available commands in Mattermost after setting up this service, by entering"
)
=
s_
(
"MattermostService|See list of available commands in Mattermost after setting up this service, by entering"
)
%kbd
.inline
/
<
trigger
>
help
%kbd
.inline
/
<
trigger
>
help
-
unless
enabled
||
@service
.
instanc
e?
-
unless
enabled
||
@service
.
templat
e?
=
render
'projects/services/mattermost_slash_commands/detailed_help'
,
subject:
@service
=
render
'projects/services/mattermost_slash_commands/detailed_help'
,
subject:
@service
-
if
enabled
&&
!
@service
.
instanc
e?
-
if
enabled
&&
!
@service
.
templat
e?
=
render
'projects/services/mattermost_slash_commands/installation_info'
,
subject:
@service
=
render
'projects/services/mattermost_slash_commands/installation_info'
,
subject:
@service
app/views/projects/services/slack_slash_commands/_help.html.haml
View file @
8d4d9705
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
%p
.inline
%p
.inline
=
s_
(
"SlackService|See list of available commands in Slack after setting up this service, by entering"
)
=
s_
(
"SlackService|See list of available commands in Slack after setting up this service, by entering"
)
%kbd
.inline
/
<
command
>
help
%kbd
.inline
/
<
command
>
help
-
unless
@service
.
instanc
e?
-
unless
@service
.
templat
e?
%p
=
_
(
"To set up this service:"
)
%p
=
_
(
"To set up this service:"
)
%ul
.list-unstyled.indent-list
%ul
.list-unstyled.indent-list
%li
%li
...
...
app/workers/all_queues.yml
View file @
8d4d9705
...
@@ -969,7 +969,7 @@
...
@@ -969,7 +969,7 @@
:latency_sensitive:
:latency_sensitive:
:resource_boundary: :unknown
:resource_boundary: :unknown
:weight:
1
:weight:
1
-
:name: propagate_
instance_level_servic
e
-
:name: propagate_
service_templat
e
:feature_category: :source_code_management
:feature_category: :source_code_management
:has_external_dependencies:
:has_external_dependencies:
:latency_sensitive:
:latency_sensitive:
...
...
app/workers/propagate_
instance_level_servic
e_worker.rb
→
app/workers/propagate_
service_templat
e_worker.rb
View file @
8d4d9705
# frozen_string_literal: true
# frozen_string_literal: true
# Worker for updating any project specific caches.
# Worker for updating any project specific caches.
class
Propagate
InstanceLevelServic
eWorker
class
Propagate
ServiceTemplat
eWorker
include
ApplicationWorker
include
ApplicationWorker
feature_category
:source_code_management
feature_category
:source_code_management
...
@@ -9,18 +9,18 @@ class PropagateInstanceLevelServiceWorker
...
@@ -9,18 +9,18 @@ class PropagateInstanceLevelServiceWorker
LEASE_TIMEOUT
=
4
.
hours
.
to_i
LEASE_TIMEOUT
=
4
.
hours
.
to_i
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
perform
(
instance_level_servic
e_id
)
def
perform
(
templat
e_id
)
return
unless
try_obtain_lease_for
(
instance_level_servic
e_id
)
return
unless
try_obtain_lease_for
(
templat
e_id
)
Projects
::
Propagate
InstanceLevelService
.
propagate
(
Service
.
find_by
(
id:
instance_level_servic
e_id
))
Projects
::
Propagate
ServiceTemplate
.
propagate
(
Service
.
find_by
(
id:
templat
e_id
))
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
private
private
def
try_obtain_lease_for
(
instance_level_servic
e_id
)
def
try_obtain_lease_for
(
templat
e_id
)
Gitlab
::
ExclusiveLease
Gitlab
::
ExclusiveLease
.
new
(
"propagate_
instance_level_service_worker:
#{
instance_level_servic
e_id
}
"
,
timeout:
LEASE_TIMEOUT
)
.
new
(
"propagate_
service_template_worker:
#{
templat
e_id
}
"
,
timeout:
LEASE_TIMEOUT
)
.
try_obtain
.
try_obtain
end
end
end
end
changelogs/unreleased/rename_services_template_to_instance.yml
deleted
100644 → 0
View file @
c8ace7cd
---
title
:
'
Service
model:
Rename
template
attribute
to
instance'
merge_request
:
23595
author
:
type
:
other
config/sidekiq_queues.yml
View file @
8d4d9705
...
@@ -194,7 +194,7 @@
...
@@ -194,7 +194,7 @@
-
1
-
1
-
-
project_update_repository_storage
-
-
project_update_repository_storage
-
1
-
1
-
-
propagate_
instance_level_servic
e
-
-
propagate_
service_templat
e
-
1
-
1
-
-
reactive_caching
-
-
reactive_caching
-
1
-
1
...
...
db/migrate/20200123092602_rename_services_template_to_instance.rb
deleted
100644 → 0
View file @
c8ace7cd
# frozen_string_literal: true
class
RenameServicesTemplateToInstance
<
ActiveRecord
::
Migration
[
5.2
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
rename_column_concurrently
:services
,
:template
,
:instance
end
def
down
undo_rename_column_concurrently
:services
,
:template
,
:instance
end
end
db/post_migrate/20191021101942_remove_empty_github_service_templates.rb
View file @
8d4d9705
...
@@ -23,10 +23,6 @@ class RemoveEmptyGithubServiceTemplates < ActiveRecord::Migration[5.2]
...
@@ -23,10 +23,6 @@ class RemoveEmptyGithubServiceTemplates < ActiveRecord::Migration[5.2]
private
private
def
relationship
def
relationship
# The column `template` was renamed to `instance`. Column information needs
# to be resetted to avoid cache problems after migrating down.
RemoveEmptyGithubServiceTemplates
::
Service
.
reset_column_information
RemoveEmptyGithubServiceTemplates
::
Service
.
where
(
template:
true
,
type:
'GithubService'
)
RemoveEmptyGithubServiceTemplates
::
Service
.
where
(
template:
true
,
type:
'GithubService'
)
end
end
end
end
db/post_migrate/20200123101859_cleanup_rename_services_template_to_instance.rb
deleted
100644 → 0
View file @
c8ace7cd
# frozen_string_literal: true
class
CleanupRenameServicesTemplateToInstance
<
ActiveRecord
::
Migration
[
5.2
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
cleanup_concurrent_column_rename
:services
,
:template
,
:instance
end
def
down
undo_cleanup_concurrent_column_rename
:services
,
:template
,
:instance
end
end
db/post_migrate/20200206111847_migrate_propagate_service_template_sidekiq_queue.rb
deleted
100644 → 0
View file @
c8ace7cd
# frozen_string_literal: true
class
MigratePropagateServiceTemplateSidekiqQueue
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
up
sidekiq_queue_migrate
'propagate_service_template'
,
to:
'propagate_instance_level_service'
end
def
down
sidekiq_queue_migrate
'propagate_instance_level_service'
,
to:
'propagate_service_template'
end
end
db/schema.rb
View file @
8d4d9705
...
@@ -3858,9 +3858,9 @@ ActiveRecord::Schema.define(version: 2020_02_07_151640) do
...
@@ -3858,9 +3858,9 @@ ActiveRecord::Schema.define(version: 2020_02_07_151640) do
t
.
boolean
"deployment_events"
,
default:
false
,
null:
false
t
.
boolean
"deployment_events"
,
default:
false
,
null:
false
t
.
string
"description"
,
limit:
500
t
.
string
"description"
,
limit:
500
t
.
boolean
"comment_on_event_enabled"
,
default:
true
,
null:
false
t
.
boolean
"comment_on_event_enabled"
,
default:
true
,
null:
false
t
.
boolean
"instance"
,
default:
false
t
.
boolean
"template"
,
default:
false
t
.
index
[
"instance"
],
name:
"index_services_on_instance"
t
.
index
[
"project_id"
],
name:
"index_services_on_project_id"
t
.
index
[
"project_id"
],
name:
"index_services_on_project_id"
t
.
index
[
"template"
],
name:
"index_services_on_template"
t
.
index
[
"type"
],
name:
"index_services_on_type"
t
.
index
[
"type"
],
name:
"index_services_on_type"
end
end
...
...
ee/app/views/projects/services/gitlab_slack_application/_help.html.haml
View file @
8d4d9705
...
@@ -9,5 +9,5 @@
...
@@ -9,5 +9,5 @@
See the list of available commands in Slack after setting up this service
See the list of available commands in Slack after setting up this service
by entering
by entering
%kbd
.inline
/gitlab help
%kbd
.inline
/gitlab help
-
unless
@service
.
instanc
e?
-
unless
@service
.
templat
e?
=
render
"projects/services/
#{
@service
.
to_param
}
/slack_integration_form"
=
render
"projects/services/
#{
@service
.
to_param
}
/slack_integration_form"
lib/api/services.rb
View file @
8d4d9705
...
@@ -132,7 +132,7 @@ module API
...
@@ -132,7 +132,7 @@ module API
helpers
do
helpers
do
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
slash_command_service
(
project
,
service_slug
,
params
)
def
slash_command_service
(
project
,
service_slug
,
params
)
project
.
services
.
active
.
where
(
instanc
e:
false
).
find
do
|
service
|
project
.
services
.
active
.
where
(
templat
e:
false
).
find
do
|
service
|
service
.
try
(
:token
)
==
params
[
:token
]
&&
service
.
to_param
==
service_slug
.
underscore
service
.
try
(
:token
)
==
params
[
:token
]
&&
service
.
to_param
==
service_slug
.
underscore
end
end
end
end
...
...
lib/gitlab/import_export/import_export.yml
View file @
8d4d9705
...
@@ -257,7 +257,7 @@ excluded_attributes:
...
@@ -257,7 +257,7 @@ excluded_attributes:
-
:token
-
:token
-
:token_encrypted
-
:token_encrypted
services
:
services
:
-
:
instanc
e
-
:
templat
e
error_tracking_setting
:
error_tracking_setting
:
-
:encrypted_token
-
:encrypted_token
-
:encrypted_token_iv
-
:encrypted_token_iv
...
...
lib/gitlab/usage_data.rb
View file @
8d4d9705
...
@@ -179,7 +179,7 @@ module Gitlab
...
@@ -179,7 +179,7 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
services_usage
def
services_usage
service_counts
=
count
(
Service
.
active
.
where
(
instanc
e:
false
).
where
.
not
(
type:
'JiraService'
).
group
(
:type
),
fallback:
Hash
.
new
(
-
1
))
service_counts
=
count
(
Service
.
active
.
where
(
templat
e:
false
).
where
.
not
(
type:
'JiraService'
).
group
(
:type
),
fallback:
Hash
.
new
(
-
1
))
results
=
Service
.
available_services_names
.
each_with_object
({})
do
|
service_name
,
response
|
results
=
Service
.
available_services_names
.
each_with_object
({})
do
|
service_name
,
response
|
response
[
"projects_
#{
service_name
}
_active"
.
to_sym
]
=
service_counts
[
"
#{
service_name
}
_service"
.
camelize
]
||
0
response
[
"projects_
#{
service_name
}
_active"
.
to_sym
]
=
service_counts
[
"
#{
service_name
}
_service"
.
camelize
]
||
0
...
...
spec/controllers/admin/services_controller_spec.rb
View file @
8d4d9705
...
@@ -15,11 +15,11 @@ describe Admin::ServicesController do
...
@@ -15,11 +15,11 @@ describe Admin::ServicesController do
Service
.
available_services_names
.
each
do
|
service_name
|
Service
.
available_services_names
.
each
do
|
service_name
|
context
"
#{
service_name
}
"
do
context
"
#{
service_name
}
"
do
let!
(
:service
)
do
let!
(
:service
)
do
service_
instanc
e
=
"
#{
service_name
}
_service"
.
camelize
.
constantize
service_
templat
e
=
"
#{
service_name
}
_service"
.
camelize
.
constantize
service_
instance
.
where
(
instanc
e:
true
).
first_or_create
service_
template
.
where
(
templat
e:
true
).
first_or_create
end
end
it
'successfully displays the
servic
e'
do
it
'successfully displays the
templat
e'
do
get
:edit
,
params:
{
id:
service
.
id
}
get
:edit
,
params:
{
id:
service
.
id
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
...
@@ -34,7 +34,7 @@ describe Admin::ServicesController do
...
@@ -34,7 +34,7 @@ describe Admin::ServicesController do
RedmineService
.
create
(
RedmineService
.
create
(
project:
project
,
project:
project
,
active:
false
,
active:
false
,
instanc
e:
true
,
templat
e:
true
,
properties:
{
properties:
{
project_url:
'http://abc'
,
project_url:
'http://abc'
,
issues_url:
'http://abc'
,
issues_url:
'http://abc'
,
...
@@ -44,7 +44,7 @@ describe Admin::ServicesController do
...
@@ -44,7 +44,7 @@ describe Admin::ServicesController do
end
end
it
'calls the propagation worker when service is active'
do
it
'calls the propagation worker when service is active'
do
expect
(
Propagate
InstanceLevelServic
eWorker
).
to
receive
(
:perform_async
).
with
(
service
.
id
)
expect
(
Propagate
ServiceTemplat
eWorker
).
to
receive
(
:perform_async
).
with
(
service
.
id
)
put
:update
,
params:
{
id:
service
.
id
,
service:
{
active:
true
}
}
put
:update
,
params:
{
id:
service
.
id
,
service:
{
active:
true
}
}
...
@@ -52,7 +52,7 @@ describe Admin::ServicesController do
...
@@ -52,7 +52,7 @@ describe Admin::ServicesController do
end
end
it
'does not call the propagation worker when service is not active'
do
it
'does not call the propagation worker when service is not active'
do
expect
(
Propagate
InstanceLevelServic
eWorker
).
not_to
receive
(
:perform_async
)
expect
(
Propagate
ServiceTemplat
eWorker
).
not_to
receive
(
:perform_async
)
put
:update
,
params:
{
id:
service
.
id
,
service:
{
properties:
{}
}
}
put
:update
,
params:
{
id:
service
.
id
,
service:
{
properties:
{}
}
}
...
...
spec/controllers/projects/services_controller_spec.rb
View file @
8d4d9705
...
@@ -154,12 +154,12 @@ describe Projects::ServicesController do
...
@@ -154,12 +154,12 @@ describe Projects::ServicesController do
end
end
end
end
context
'when activating Jira service from
instance level servic
e'
do
context
'when activating Jira service from
a templat
e'
do
let
(
:service
)
do
let
(
:service
)
do
create
(
:jira_service
,
project:
project
,
instanc
e:
true
)
create
(
:jira_service
,
project:
project
,
templat
e:
true
)
end
end
it
'activate Jira service from
instance level servic
e'
do
it
'activate Jira service from
templat
e'
do
expect
(
flash
[
:notice
]).
to
eq
'Jira activated.'
expect
(
flash
[
:notice
]).
to
eq
'Jira activated.'
end
end
end
end
...
...
spec/fixtures/trace/sample_trace
View file @
8d4d9705
...
@@ -2736,7 +2736,7 @@ Service
...
@@ -2736,7 +2736,7 @@ Service
when repository is empty
when repository is empty
test runs execute
test runs execute
Template
Template
.build_from_
instanc
e
.build_from_
templat
e
when template is invalid
when template is invalid
sets service template to inactive when template is invalid
sets service template to inactive when template is invalid
for pushover service
for pushover service
...
...
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
8d4d9705
...
@@ -652,10 +652,10 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
...
@@ -652,10 +652,10 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
setup_import_export_config
(
'light'
)
setup_import_export_config
(
'light'
)
end
end
it
'does not import any
instance-level
services'
do
it
'does not import any
templated
services'
do
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
project
.
services
.
where
(
instanc
e:
true
).
count
).
to
eq
(
0
)
expect
(
project
.
services
.
where
(
templat
e:
true
).
count
).
to
eq
(
0
)
end
end
it
'imports labels'
do
it
'imports labels'
do
...
...
spec/lib/gitlab/import_export/safe_model_attributes.yml
View file @
8d4d9705
...
@@ -453,7 +453,7 @@ Service:
...
@@ -453,7 +453,7 @@ Service:
-
updated_at
-
updated_at
-
active
-
active
-
properties
-
properties
-
instanc
e
-
templat
e
-
push_events
-
push_events
-
issues_events
-
issues_events
-
commit_events
-
commit_events
...
...
spec/lib/gitlab/usage_data_spec.rb
View file @
8d4d9705
...
@@ -18,7 +18,7 @@ describe Gitlab::UsageData do
...
@@ -18,7 +18,7 @@ describe Gitlab::UsageData do
create
(
:service
,
project:
projects
[
1
],
type:
'SlackService'
,
active:
true
)
create
(
:service
,
project:
projects
[
1
],
type:
'SlackService'
,
active:
true
)
create
(
:service
,
project:
projects
[
2
],
type:
'SlackService'
,
active:
true
)
create
(
:service
,
project:
projects
[
2
],
type:
'SlackService'
,
active:
true
)
create
(
:service
,
project:
projects
[
2
],
type:
'MattermostService'
,
active:
false
)
create
(
:service
,
project:
projects
[
2
],
type:
'MattermostService'
,
active:
false
)
create
(
:service
,
project:
projects
[
2
],
type:
'MattermostService'
,
active:
true
,
instanc
e:
true
)
create
(
:service
,
project:
projects
[
2
],
type:
'MattermostService'
,
active:
true
,
templat
e:
true
)
create
(
:service
,
project:
projects
[
2
],
type:
'CustomIssueTrackerService'
,
active:
true
)
create
(
:service
,
project:
projects
[
2
],
type:
'CustomIssueTrackerService'
,
active:
true
)
create
(
:project_error_tracking_setting
,
project:
projects
[
0
])
create
(
:project_error_tracking_setting
,
project:
projects
[
0
])
create
(
:project_error_tracking_setting
,
project:
projects
[
1
],
enabled:
false
)
create
(
:project_error_tracking_setting
,
project:
projects
[
1
],
enabled:
false
)
...
...
spec/migrations/migrate_propagate_service_template_sidekiq_queue_spec.rb
deleted
100644 → 0
View file @
c8ace7cd
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20200206111847_migrate_propagate_service_template_sidekiq_queue.rb'
)
describe
MigratePropagateServiceTemplateSidekiqQueue
,
:sidekiq
,
:redis
do
include
Gitlab
::
Database
::
MigrationHelpers
include
StubWorker
context
'when there are jobs in the queue'
do
it
'correctly migrates queue when migrating up'
do
Sidekiq
::
Testing
.
disable!
do
stub_worker
(
queue:
'propagate_service_template'
).
perform_async
(
'Something'
,
[
1
])
stub_worker
(
queue:
'propagate_instance_level_service'
).
perform_async
(
'Something'
,
[
1
])
described_class
.
new
.
up
expect
(
sidekiq_queue_length
(
'propagate_service_template'
)).
to
eq
0
expect
(
sidekiq_queue_length
(
'propagate_instance_level_service'
)).
to
eq
2
end
end
end
context
'when there are no jobs in the queues'
do
it
'does not raise error when migrating up'
do
expect
{
described_class
.
new
.
up
}.
not_to
raise_error
end
end
end
spec/models/service_spec.rb
View file @
8d4d9705
...
@@ -97,23 +97,23 @@ describe Service do
...
@@ -97,23 +97,23 @@ describe Service do
end
end
end
end
describe
"
Instanc
e"
do
describe
"
Templat
e"
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
describe
'.build_from_
instanc
e'
do
describe
'.build_from_
templat
e'
do
context
'when
instance level integration
is invalid'
do
context
'when
template
is invalid'
do
it
'sets
instance level integration to inactive when instanc
e is invalid'
do
it
'sets
service template to inactive when templat
e is invalid'
do
instance
=
build
(
:prometheus_service
,
instanc
e:
true
,
active:
true
,
properties:
{})
template
=
build
(
:prometheus_service
,
templat
e:
true
,
active:
true
,
properties:
{})
instanc
e
.
save
(
validate:
false
)
templat
e
.
save
(
validate:
false
)
service
=
described_class
.
build_from_
instance
(
project
.
id
,
instanc
e
)
service
=
described_class
.
build_from_
template
(
project
.
id
,
templat
e
)
expect
(
service
).
to
be_valid
expect
(
service
).
to
be_valid
expect
(
service
.
active
).
to
be
false
expect
(
service
.
active
).
to
be
false
end
end
end
end
describe
'build issue tracker from a
instance level integration
'
do
describe
'build issue tracker from a
template
'
do
let
(
:title
)
{
'custom title'
}
let
(
:title
)
{
'custom title'
}
let
(
:description
)
{
'custom description'
}
let
(
:description
)
{
'custom description'
}
let
(
:url
)
{
'http://jira.example.com'
}
let
(
:url
)
{
'http://jira.example.com'
}
...
@@ -127,9 +127,9 @@ describe Service do
...
@@ -127,9 +127,9 @@ describe Service do
}
}
end
end
shared_examples
'
integration creation from instance level
'
do
shared_examples
'
service creation from a template
'
do
it
'creates a correct service'
do
it
'creates a correct service'
do
service
=
described_class
.
build_from_
instance
(
project
.
id
,
instance_level_integration
)
service
=
described_class
.
build_from_
template
(
project
.
id
,
template
)
expect
(
service
).
to
be_active
expect
(
service
).
to
be_active
expect
(
service
.
title
).
to
eq
(
title
)
expect
(
service
.
title
).
to
eq
(
title
)
...
@@ -144,38 +144,38 @@ describe Service do
...
@@ -144,38 +144,38 @@ describe Service do
# this will be removed as part of https://gitlab.com/gitlab-org/gitlab/issues/29404
# this will be removed as part of https://gitlab.com/gitlab-org/gitlab/issues/29404
context
'when data are stored in properties'
do
context
'when data are stored in properties'
do
let
(
:properties
)
{
data_params
.
merge
(
title:
title
,
description:
description
)
}
let
(
:properties
)
{
data_params
.
merge
(
title:
title
,
description:
description
)
}
let!
(
:
instance_level_integration
)
do
let!
(
:
template
)
do
create
(
:jira_service
,
:without_properties_callback
,
instanc
e:
true
,
properties:
properties
.
merge
(
additional:
'something'
))
create
(
:jira_service
,
:without_properties_callback
,
templat
e:
true
,
properties:
properties
.
merge
(
additional:
'something'
))
end
end
it_behaves_like
'
integration creation from instance level
'
it_behaves_like
'
service creation from a template
'
end
end
context
'when data are stored in separated fields'
do
context
'when data are stored in separated fields'
do
let
(
:
instance_level_integration
)
do
let
(
:
template
)
do
create
(
:jira_service
,
data_params
.
merge
(
properties:
{},
title:
title
,
description:
description
,
instanc
e:
true
))
create
(
:jira_service
,
data_params
.
merge
(
properties:
{},
title:
title
,
description:
description
,
templat
e:
true
))
end
end
it_behaves_like
'
integration creation from instance level
'
it_behaves_like
'
service creation from a template
'
end
end
context
'when data are stored in both properties and separated fields'
do
context
'when data are stored in both properties and separated fields'
do
let
(
:properties
)
{
data_params
.
merge
(
title:
title
,
description:
description
)
}
let
(
:properties
)
{
data_params
.
merge
(
title:
title
,
description:
description
)
}
let
(
:
instance_level_integration
)
do
let
(
:
template
)
do
create
(
:jira_service
,
:without_properties_callback
,
active:
true
,
instanc
e:
true
,
properties:
properties
).
tap
do
|
service
|
create
(
:jira_service
,
:without_properties_callback
,
active:
true
,
templat
e:
true
,
properties:
properties
).
tap
do
|
service
|
create
(
:jira_tracker_data
,
data_params
.
merge
(
service:
service
))
create
(
:jira_tracker_data
,
data_params
.
merge
(
service:
service
))
end
end
end
end
it_behaves_like
'
integration creation from instance level
'
it_behaves_like
'
service creation from a template
'
end
end
end
end
end
end
describe
"for pushover service"
do
describe
"for pushover service"
do
let!
(
:
instance_level_integration
)
do
let!
(
:
service_template
)
do
PushoverService
.
create
(
PushoverService
.
create
(
instanc
e:
true
,
templat
e:
true
,
properties:
{
properties:
{
device:
'MyDevice'
,
device:
'MyDevice'
,
sound:
'mic'
,
sound:
'mic'
,
...
@@ -188,7 +188,7 @@ describe Service do
...
@@ -188,7 +188,7 @@ describe Service do
it
"has all fields prefilled"
do
it
"has all fields prefilled"
do
service
=
project
.
find_or_initialize_service
(
'pushover'
)
service
=
project
.
find_or_initialize_service
(
'pushover'
)
expect
(
service
.
instanc
e
).
to
eq
(
false
)
expect
(
service
.
templat
e
).
to
eq
(
false
)
expect
(
service
.
device
).
to
eq
(
'MyDevice'
)
expect
(
service
.
device
).
to
eq
(
'MyDevice'
)
expect
(
service
.
sound
).
to
eq
(
'mic'
)
expect
(
service
.
sound
).
to
eq
(
'mic'
)
expect
(
service
.
priority
).
to
eq
(
4
)
expect
(
service
.
priority
).
to
eq
(
4
)
...
@@ -391,6 +391,14 @@ describe Service do
...
@@ -391,6 +391,14 @@ describe Service do
end
end
end
end
describe
'.find_by_template'
do
let!
(
:service
)
{
create
(
:service
,
template:
true
)
}
it
'returns service template'
do
expect
(
described_class
.
find_by_template
).
to
eq
(
service
)
end
end
describe
'#api_field_names'
do
describe
'#api_field_names'
do
let
(
:fake_service
)
do
let
(
:fake_service
)
do
Class
.
new
(
Service
)
do
Class
.
new
(
Service
)
do
...
...
spec/services/projects/create_service_spec.rb
View file @
8d4d9705
...
@@ -15,7 +15,7 @@ describe Projects::CreateService, '#execute' do
...
@@ -15,7 +15,7 @@ describe Projects::CreateService, '#execute' do
}
}
end
end
it
'creates labels on Project creation if there are
instance level servic
es'
do
it
'creates labels on Project creation if there are
templat
es'
do
Label
.
create
(
title:
"bug"
,
template:
true
)
Label
.
create
(
title:
"bug"
,
template:
true
)
project
=
create_project
(
user
,
opts
)
project
=
create_project
(
user
,
opts
)
...
@@ -96,7 +96,7 @@ describe Projects::CreateService, '#execute' do
...
@@ -96,7 +96,7 @@ describe Projects::CreateService, '#execute' do
end
end
it
'sets invalid service as inactive'
do
it
'sets invalid service as inactive'
do
create
(
:service
,
type:
'JiraService'
,
project:
nil
,
instanc
e:
true
,
active:
true
)
create
(
:service
,
type:
'JiraService'
,
project:
nil
,
templat
e:
true
,
active:
true
)
project
=
create_project
(
user
,
opts
)
project
=
create_project
(
user
,
opts
)
service
=
project
.
services
.
first
service
=
project
.
services
.
first
...
@@ -342,22 +342,22 @@ describe Projects::CreateService, '#execute' do
...
@@ -342,22 +342,22 @@ describe Projects::CreateService, '#execute' do
end
end
end
end
context
'when there is an active
instance level servic
e'
do
context
'when there is an active
service templat
e'
do
before
do
before
do
create
(
:service
,
project:
nil
,
instanc
e:
true
,
active:
true
)
create
(
:service
,
project:
nil
,
templat
e:
true
,
active:
true
)
end
end
it
'creates a service from
instance level servic
e'
do
it
'creates a service from
this templat
e'
do
project
=
create_project
(
user
,
opts
)
project
=
create_project
(
user
,
opts
)
expect
(
project
.
services
.
count
).
to
eq
1
expect
(
project
.
services
.
count
).
to
eq
1
end
end
end
end
context
'when a bad
instance level servic
e is created'
do
context
'when a bad
service templat
e is created'
do
it
'sets service to be inactive'
do
it
'sets service to be inactive'
do
opts
[
:import_url
]
=
'http://www.gitlab.com/gitlab-org/gitlab-foss'
opts
[
:import_url
]
=
'http://www.gitlab.com/gitlab-org/gitlab-foss'
create
(
:service
,
type:
'DroneCiService'
,
project:
nil
,
instanc
e:
true
,
active:
true
)
create
(
:service
,
type:
'DroneCiService'
,
project:
nil
,
templat
e:
true
,
active:
true
)
project
=
create_project
(
user
,
opts
)
project
=
create_project
(
user
,
opts
)
service
=
project
.
services
.
first
service
=
project
.
services
.
first
...
...
spec/services/projects/propagate_
instance_level_servic
e_spec.rb
→
spec/services/projects/propagate_
service_templat
e_spec.rb
View file @
8d4d9705
...
@@ -2,11 +2,11 @@
...
@@ -2,11 +2,11 @@
require
'spec_helper'
require
'spec_helper'
describe
Projects
::
Propagate
InstanceLevelServic
e
do
describe
Projects
::
Propagate
ServiceTemplat
e
do
describe
'.propagate'
do
describe
'.propagate'
do
let!
(
:
instance_level_integration
)
do
let!
(
:
service_template
)
do
PushoverService
.
create
(
PushoverService
.
create
(
instanc
e:
true
,
templat
e:
true
,
active:
true
,
active:
true
,
properties:
{
properties:
{
device:
'MyDevice'
,
device:
'MyDevice'
,
...
@@ -22,14 +22,14 @@ describe Projects::PropagateInstanceLevelService do
...
@@ -22,14 +22,14 @@ describe Projects::PropagateInstanceLevelService do
it
'creates services for projects'
do
it
'creates services for projects'
do
expect
(
project
.
pushover_service
).
to
be_nil
expect
(
project
.
pushover_service
).
to
be_nil
described_class
.
propagate
(
instance_level_integration
)
described_class
.
propagate
(
service_template
)
expect
(
project
.
reload
.
pushover_service
).
to
be_present
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
BambooService
.
create
(
BambooService
.
create
(
instanc
e:
true
,
templat
e:
true
,
active:
true
,
active:
true
,
project:
project
,
project:
project
,
properties:
{
properties:
{
...
@@ -42,14 +42,14 @@ describe Projects::PropagateInstanceLevelService do
...
@@ -42,14 +42,14 @@ describe Projects::PropagateInstanceLevelService do
expect
(
project
.
pushover_service
).
to
be_nil
expect
(
project
.
pushover_service
).
to
be_nil
described_class
.
propagate
(
instance_level_integration
)
described_class
.
propagate
(
service_template
)
expect
(
project
.
reload
.
pushover_service
).
to
be_present
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
other_service
=
BambooService
.
create
(
other_service
=
BambooService
.
create
(
instanc
e:
true
,
templat
e:
true
,
active:
true
,
active:
true
,
properties:
{
properties:
{
bamboo_url:
'http://gitlab.com'
,
bamboo_url:
'http://gitlab.com'
,
...
@@ -59,17 +59,17 @@ describe Projects::PropagateInstanceLevelService do
...
@@ -59,17 +59,17 @@ describe Projects::PropagateInstanceLevelService do
}
}
)
)
Service
.
build_from_
instance
(
project
.
id
,
instance_level_integration
).
save!
Service
.
build_from_
template
(
project
.
id
,
service_template
).
save!
Service
.
build_from_
instanc
e
(
project
.
id
,
other_service
).
save!
Service
.
build_from_
templat
e
(
project
.
id
,
other_service
).
save!
expect
{
described_class
.
propagate
(
instance_level_integration
)
}
expect
{
described_class
.
propagate
(
service_template
)
}
.
not_to
change
{
Service
.
count
}
.
not_to
change
{
Service
.
count
}
end
end
it
'creates the service containing the
instanc
e attributes'
do
it
'creates the service containing the
templat
e attributes'
do
described_class
.
propagate
(
instance_level_integration
)
described_class
.
propagate
(
service_template
)
expect
(
project
.
pushover_service
.
properties
).
to
eq
(
instance_level_integration
.
properties
)
expect
(
project
.
pushover_service
.
properties
).
to
eq
(
service_template
.
properties
)
end
end
describe
'bulk update'
,
:use_sql_query_cache
do
describe
'bulk update'
,
:use_sql_query_cache
do
...
@@ -80,7 +80,7 @@ describe Projects::PropagateInstanceLevelService do
...
@@ -80,7 +80,7 @@ describe Projects::PropagateInstanceLevelService do
project_total
.
times
{
create
(
:project
)
}
project_total
.
times
{
create
(
:project
)
}
described_class
.
propagate
(
instance_level_integration
)
described_class
.
propagate
(
service_template
)
end
end
it
'creates services for all projects'
do
it
'creates services for all projects'
do
...
@@ -90,18 +90,18 @@ describe Projects::PropagateInstanceLevelService do
...
@@ -90,18 +90,18 @@ describe Projects::PropagateInstanceLevelService do
describe
'external tracker'
do
describe
'external tracker'
do
it
'updates the project external tracker'
do
it
'updates the project external tracker'
do
instance_level_integration
.
update!
(
category:
'issue_tracker'
,
default:
false
)
service_template
.
update!
(
category:
'issue_tracker'
,
default:
false
)
expect
{
described_class
.
propagate
(
instance_level_integration
)
}
expect
{
described_class
.
propagate
(
service_template
)
}
.
to
change
{
project
.
reload
.
has_external_issue_tracker
}.
to
(
true
)
.
to
change
{
project
.
reload
.
has_external_issue_tracker
}.
to
(
true
)
end
end
end
end
describe
'external wiki'
do
describe
'external wiki'
do
it
'updates the project external tracker'
do
it
'updates the project external tracker'
do
instance_level_integration
.
update!
(
type:
'ExternalWikiService'
)
service_template
.
update!
(
type:
'ExternalWikiService'
)
expect
{
described_class
.
propagate
(
instance_level_integration
)
}
expect
{
described_class
.
propagate
(
service_template
)
}
.
to
change
{
project
.
reload
.
has_external_wiki
}.
to
(
true
)
.
to
change
{
project
.
reload
.
has_external_wiki
}.
to
(
true
)
end
end
end
end
...
...
spec/workers/propagate_
instance_level_servic
e_worker_spec.rb
→
spec/workers/propagate_
service_templat
e_worker_spec.rb
View file @
8d4d9705
...
@@ -2,13 +2,13 @@
...
@@ -2,13 +2,13 @@
require
'spec_helper'
require
'spec_helper'
describe
Propagate
InstanceLevelServic
eWorker
do
describe
Propagate
ServiceTemplat
eWorker
do
include
ExclusiveLeaseHelpers
include
ExclusiveLeaseHelpers
describe
'#perform'
do
describe
'#perform'
do
it
'calls the propagate service with the
instance level servic
e'
do
it
'calls the propagate service with the
templat
e'
do
instance_level_servic
e
=
PushoverService
.
create
(
templat
e
=
PushoverService
.
create
(
instanc
e:
true
,
templat
e:
true
,
active:
true
,
active:
true
,
properties:
{
properties:
{
device:
'MyDevice'
,
device:
'MyDevice'
,
...
@@ -18,14 +18,14 @@ describe PropagateInstanceLevelServiceWorker do
...
@@ -18,14 +18,14 @@ describe PropagateInstanceLevelServiceWorker do
api_key:
'123456789'
api_key:
'123456789'
})
})
stub_exclusive_lease
(
"propagate_
instance_level_service_worker:
#{
instance_level_servic
e
.
id
}
"
,
stub_exclusive_lease
(
"propagate_
service_template_worker:
#{
templat
e
.
id
}
"
,
timeout:
Propagate
InstanceLevelServic
eWorker
::
LEASE_TIMEOUT
)
timeout:
Propagate
ServiceTemplat
eWorker
::
LEASE_TIMEOUT
)
expect
(
Projects
::
Propagate
InstanceLevelServic
e
)
expect
(
Projects
::
Propagate
ServiceTemplat
e
)
.
to
receive
(
:propagate
)
.
to
receive
(
:propagate
)
.
with
(
instance_level_servic
e
)
.
with
(
templat
e
)
subject
.
perform
(
instance_level_servic
e
.
id
)
subject
.
perform
(
templat
e
.
id
)
end
end
end
end
end
end
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