diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-18 10:00:40 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-18 10:00:40 +0100 |
commit | 0d04724fa1cd670124b8ad9a3860bfa476c50f99 (patch) | |
tree | fc8b96d32eda2bfe9633fa0eff1569237e4d454e /lib | |
parent | 778b5a5a04c4861c84408c944fa8dc01411cbf55 (diff) | |
download | gitlab-ce-0d04724fa1cd670124b8ad9a3860bfa476c50f99.tar.gz |
More coverage on service level
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/helpers.rb | 9 | ||||
-rw-r--r-- | lib/api/services.rb | 7 | ||||
-rw-r--r-- | lib/mattermost/presenter.rb | 6 |
3 files changed, 15 insertions, 7 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) diff --git a/lib/mattermost/presenter.rb b/lib/mattermost/presenter.rb index 7722022c658..d7455d39bce 100644 --- a/lib/mattermost/presenter.rb +++ b/lib/mattermost/presenter.rb @@ -4,7 +4,11 @@ module Mattermost include Rails.application.routes.url_helpers def authorize_chat_name(url) - message = ":wave: Hi there! Before I do anything for you, please [connect your GitLab account](#{url})." + message = if url + ":wave: Hi there! Before I do anything for you, please [connect your GitLab account](#{url})." + else + ":sweat_smile: Couldn't identify you, nor can I autorize you!" + end ephemeral_response(message) end |