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
1945f57c
Commit
1945f57c
authored
Aug 27, 2020
by
Arturo Herrero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Service class: Move all class methods together
parent
af246a26
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
102 deletions
+102
-102
app/models/service.rb
app/models/service.rb
+102
-102
No files found.
app/models/service.rb
View file @
1945f57c
...
...
@@ -129,6 +129,108 @@ class Service < ApplicationRecord
end
end
def
self
.
to_param
raise
NotImplementedError
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
ServicesHelper
.
service_event_field_name
(
event
)
}
end
def
self
.
supported_event_actions
%w()
end
def
self
.
supported_events
%w(commit push tag_push issue confidential_issue merge_request wiki_page)
end
def
self
.
find_or_create_templates
create_nonexistent_templates
for_template
end
private_class_method
def
self
.
create_nonexistent_templates
nonexistent_services
=
list_nonexistent_services_for
(
for_template
)
return
if
nonexistent_services
.
empty?
# Create within a transaction to perform the lowest possible SQL queries.
transaction
do
nonexistent_services
.
each
do
|
service_type
|
service_type
.
constantize
.
create
(
template:
true
)
end
end
end
def
self
.
find_or_initialize_integration
(
name
,
instance:
false
,
group_id:
nil
)
if
name
.
in?
(
available_services_names
)
"
#{
name
}
_service"
.
camelize
.
constantize
.
find_or_initialize_by
(
instance:
instance
,
group_id:
group_id
)
end
end
def
self
.
find_or_initialize_all
(
scope
)
scope
+
build_nonexistent_services_for
(
scope
)
end
private_class_method
def
self
.
build_nonexistent_services_for
(
scope
)
list_nonexistent_services_for
(
scope
).
map
do
|
service_type
|
service_type
.
constantize
.
new
end
end
private_class_method
def
self
.
list_nonexistent_services_for
(
scope
)
available_services_types
-
scope
.
map
(
&
:type
)
end
def
self
.
available_services_names
service_names
=
services_names
service_names
+=
dev_services_names
service_names
.
sort_by
(
&
:downcase
)
end
def
self
.
services_names
SERVICE_NAMES
end
def
self
.
dev_services_names
return
[]
unless
Rails
.
env
.
development?
DEV_SERVICE_NAMES
end
def
self
.
available_services_types
available_services_names
.
map
{
|
service_name
|
"
#{
service_name
}
_service"
.
camelize
}
end
def
self
.
services_types
services_names
.
map
{
|
service_name
|
"
#{
service_name
}
_service"
.
camelize
}
end
def
self
.
build_from_integration
(
project_id
,
integration
)
service
=
integration
.
dup
if
integration
.
supports_data_fields?
data_fields
=
integration
.
data_fields
.
dup
data_fields
.
service
=
service
end
service
.
template
=
false
service
.
instance
=
false
service
.
inherit_from_id
=
integration
.
id
if
integration
.
instance?
service
.
project_id
=
project_id
service
.
active
=
false
if
service
.
invalid?
service
end
def
self
.
instance_exists_for?
(
type
)
exists?
(
instance:
true
,
type:
type
)
end
def
self
.
instance_for
(
type
)
find_by
(
instance:
true
,
type:
type
)
end
def
activated?
active
end
...
...
@@ -170,10 +272,6 @@ class Service < ApplicationRecord
self
.
class
.
to_param
end
def
self
.
to_param
raise
NotImplementedError
end
def
fields
# implement inside child
[]
...
...
@@ -202,10 +300,6 @@ class Service < ApplicationRecord
self
.
class
.
event_names
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
ServicesHelper
.
service_event_field_name
(
event
)
}
end
def
event_field
(
event
)
nil
end
...
...
@@ -234,18 +328,10 @@ class Service < ApplicationRecord
self
.
class
.
supported_event_actions
end
def
self
.
supported_event_actions
%w()
end
def
supported_events
self
.
class
.
supported_events
end
def
self
.
supported_events
%w(commit push tag_push issue confidential_issue merge_request wiki_page)
end
def
execute
(
data
)
# implement inside child
end
...
...
@@ -286,92 +372,6 @@ class Service < ApplicationRecord
self
.
category
==
:issue_tracker
end
def
self
.
find_or_create_templates
create_nonexistent_templates
for_template
end
private_class_method
def
self
.
create_nonexistent_templates
nonexistent_services
=
list_nonexistent_services_for
(
for_template
)
return
if
nonexistent_services
.
empty?
# Create within a transaction to perform the lowest possible SQL queries.
transaction
do
nonexistent_services
.
each
do
|
service_type
|
service_type
.
constantize
.
create
(
template:
true
)
end
end
end
def
self
.
find_or_initialize_integration
(
name
,
instance:
false
,
group_id:
nil
)
if
name
.
in?
(
available_services_names
)
"
#{
name
}
_service"
.
camelize
.
constantize
.
find_or_initialize_by
(
instance:
instance
,
group_id:
group_id
)
end
end
def
self
.
find_or_initialize_all
(
scope
)
scope
+
build_nonexistent_services_for
(
scope
)
end
private_class_method
def
self
.
build_nonexistent_services_for
(
scope
)
list_nonexistent_services_for
(
scope
).
map
do
|
service_type
|
service_type
.
constantize
.
new
end
end
private_class_method
def
self
.
list_nonexistent_services_for
(
scope
)
available_services_types
-
scope
.
map
(
&
:type
)
end
def
self
.
available_services_names
service_names
=
services_names
service_names
+=
dev_services_names
service_names
.
sort_by
(
&
:downcase
)
end
def
self
.
services_names
SERVICE_NAMES
end
def
self
.
dev_services_names
return
[]
unless
Rails
.
env
.
development?
DEV_SERVICE_NAMES
end
def
self
.
available_services_types
available_services_names
.
map
{
|
service_name
|
"
#{
service_name
}
_service"
.
camelize
}
end
def
self
.
services_types
services_names
.
map
{
|
service_name
|
"
#{
service_name
}
_service"
.
camelize
}
end
def
self
.
build_from_integration
(
project_id
,
integration
)
service
=
integration
.
dup
if
integration
.
supports_data_fields?
data_fields
=
integration
.
data_fields
.
dup
data_fields
.
service
=
service
end
service
.
template
=
false
service
.
instance
=
false
service
.
inherit_from_id
=
integration
.
id
if
integration
.
instance?
service
.
project_id
=
project_id
service
.
active
=
false
if
service
.
invalid?
service
end
def
self
.
instance_exists_for?
(
type
)
exists?
(
instance:
true
,
type:
type
)
end
def
self
.
instance_for
(
type
)
find_by
(
instance:
true
,
type:
type
)
end
# override if needed
def
supports_data_fields?
false
...
...
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