summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/helpers.rb9
-rw-r--r--lib/api/services.rb7
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 84cc9200d1b..d6526ec4fdc 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -90,6 +90,15 @@ module API
@project_service || not_found!("Service")
end
+ def service_by_slug(project, slug)
+ underscored_service = slug.underscore
+
+ not_found!('Service') unless Service.available_services_names.include?(underscored_service)
+ service_method = "#{underscored_service}_service"
+
+ service = project.public_send(service_method)
+ end
+
def service_attributes
@service_attributes ||= project_service.fields.inject([]) do |arr, hash|
arr << hash[:name].to_sym
diff --git a/lib/api/services.rb b/lib/api/services.rb
index b0a94508d10..163187d450d 100644
--- a/lib/api/services.rb
+++ b/lib/api/services.rb
@@ -67,12 +67,7 @@ module API
post ':id/services/:service_slug/trigger' do
project = Project.find_with_namespace(params[:id]) || Project.find_by(id: params[:id])
- underscored_service = params[:service_slug].underscore
-
- not_found!('Service') unless Service.available_services_names.include?(underscored_service)
- service_method = "#{underscored_service}_service"
-
- service = project.public_send(service_method)
+ service = service_by_slug(project, params[:service_slug])
result = service.try(:active?) && service.try(:trigger, params)