summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/services_controller.rb2
-rw-r--r--app/models/project_services/slack_service.rb21
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