diff options
author | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2014-10-06 16:14:48 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2014-10-06 16:14:48 +0000 |
commit | 70004f4ef6160e788e6a600b9da06608c8559aa2 (patch) | |
tree | 7ee7c7990126555f6edd0ba95bb8b5bf1927d029 /app | |
parent | 0fed1b587630ff98808c61881511ee7c077c3db6 (diff) | |
parent | eceef546d19c16d16772868a05e6769907442f83 (diff) | |
download | gitlab-ce-70004f4ef6160e788e6a600b9da06608c8559aa2.tar.gz |
Merge branch 'slack_integration' into 'master'
Slack integration
See merge request !1151
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/services_controller.rb | 2 | ||||
-rw-r--r-- | app/models/project_services/slack_service.rb | 21 |
2 files changed, 11 insertions, 12 deletions
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb index 4c558e137ea..b50f6286459 100644 --- a/app/controllers/projects/services_controller.rb +++ b/app/controllers/projects/services_controller.rb @@ -40,7 +40,7 @@ class Projects::ServicesController < Projects::ApplicationController def service_params params.require(:service).permit( :title, :token, :type, :active, :api_key, :subdomain, - :room, :recipients, :project_url, + :room, :recipients, :project_url, :webhook, :user_key, :device, :priority, :sound ) end diff --git a/app/models/project_services/slack_service.rb b/app/models/project_services/slack_service.rb index 4bda93f6006..dfa1e9c9820 100644 --- a/app/models/project_services/slack_service.rb +++ b/app/models/project_services/slack_service.rb @@ -13,10 +13,8 @@ # class SlackService < Service - prop_accessor :room, :subdomain, :token - validates :room, presence: true, if: :activated? - validates :subdomain, presence: true, if: :activated? - validates :token, presence: true, if: :activated? + prop_accessor :webhook + validates :webhook, presence: true, if: :activated? def title 'Slack' @@ -32,9 +30,7 @@ class SlackService < Service def fields [ - { type: 'text', name: 'subdomain', placeholder: '' }, - { type: 'text', name: 'token', placeholder: '' }, - { type: 'text', name: 'room', placeholder: 'Ex. #general' }, + { type: 'text', name: 'webhook', placeholder: '' } ] end @@ -44,10 +40,13 @@ class SlackService < Service project_name: project_name )) - notifier = Slack::Notifier.new(subdomain, token) - notifier.channel = room - notifier.username = 'GitLab' - notifier.ping(message.pretext, attachments: message.attachments) + credentials = webhook.match(/(\w*).slack.com.*services\/(.*)/) + if credentials.present? + subdomain = credentials[1] + token = credentials[2].split("token=").last + notifier = Slack::Notifier.new(subdomain, token) + notifier.ping(message.pretext, attachments: message.attachments) + end end private |