Skip to content

Commit

Permalink
Merge pull request #613 from reedloden/slack_webhook_url
Browse files Browse the repository at this point in the history
Add webhook URL config for Slack (with tests!)
  • Loading branch information
tombruijn committed Dec 5, 2014
2 parents fe7a5b9 + 106693d commit 6f59d4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 34 deletions.
10 changes: 3 additions & 7 deletions lib/backup/notifier/slack.rb
Expand Up @@ -7,12 +7,8 @@ module Notifier
class Slack < Base

##
# The Team name
attr_accessor :team

##
# The Integration Token
attr_accessor :token
# The incoming webhook url
attr_accessor :webhook_url

##
# The channel to send messages to
Expand Down Expand Up @@ -151,7 +147,7 @@ def title(status)
end

def uri
@uri ||= "https://#{team}.slack.com/services/hooks/incoming-webhook?token=#{token}"
@uri ||= webhook_url
end
end
end
Expand Down
41 changes: 18 additions & 23 deletions spec/notifier/slack_spec.rb
Expand Up @@ -12,11 +12,10 @@ module Backup

describe '#initialize' do
it 'provides default values' do
expect( notifier.team ).to be_nil
expect( notifier.token ).to be_nil
expect( notifier.channel ).to be_nil
expect( notifier.username ).to be_nil
expect( notifier.icon_emoji ).to eq(':floppy_disk:')
expect( notifier.webhook_url ).to be_nil
expect( notifier.channel ).to be_nil
expect( notifier.username ).to be_nil
expect( notifier.icon_emoji ).to eq(':floppy_disk:')

expect( notifier.on_success ).to be(true)
expect( notifier.on_warning ).to be(true)
Expand All @@ -27,11 +26,10 @@ module Backup

it 'configures the notifier' do
notifier = Notifier::Slack.new(model) do |slack|
slack.team = 'my_team'
slack.token = 'my_token'
slack.channel = 'my_channel'
slack.username = 'my_username'
slack.icon_emoji = ':vhs:'
slack.webhook_url = 'my_webhook_url'
slack.channel = 'my_channel'
slack.username = 'my_username'
slack.icon_emoji = ':vhs:'

slack.on_success = false
slack.on_warning = false
Expand All @@ -41,11 +39,10 @@ module Backup
end


expect( notifier.team ).to eq 'my_team'
expect( notifier.token ).to eq 'my_token'
expect( notifier.channel ).to eq 'my_channel'
expect( notifier.username ).to eq 'my_username'
expect( notifier.icon_emoji ).to eq ':vhs:'
expect( notifier.webhook_url ).to eq 'my_webhook_url'
expect( notifier.channel ).to eq 'my_channel'
expect( notifier.username ).to eq 'my_username'
expect( notifier.icon_emoji ).to eq ':vhs:'

expect( notifier.on_success ).to be(false)
expect( notifier.on_warning ).to be(false)
Expand Down Expand Up @@ -85,13 +82,12 @@ def expected_excon_params(_url, options, expected_payload, send_log = false)

let(:notifier) {
Notifier::Slack.new(model) do |slack|
slack.team = 'my_team'
slack.token = 'my_token'
slack.webhook_url = 'my_webhook_url'
end
}

let(:url) {
'https://my_team.slack.com/services/hooks/incoming-webhook?token=my_token'
'my_webhook_url'
}

context 'when status is :success' do
Expand Down Expand Up @@ -127,11 +123,10 @@ def expected_excon_params(_url, options, expected_payload, send_log = false)
context 'when optional parameters are provided' do
let(:notifier) {
Notifier::Slack.new(model) do |slack|
slack.team = 'my_team'
slack.token = 'my_token'
slack.channel = 'my_channel'
slack.username = 'my_username'
slack.icon_emoji = ':vhs:'
slack.webhook_url = 'my_webhook_url'
slack.channel = 'my_channel'
slack.username = 'my_username'
slack.icon_emoji = ':vhs:'
end
}

Expand Down
7 changes: 3 additions & 4 deletions templates/cli/notifiers/slack
Expand Up @@ -6,11 +6,10 @@
slack.on_warning = true
slack.on_failure = true

# The team name
slack.team = 'my_team'
# The incoming webhook url
# https://hooks.slack.com/services/xxxxxxxx/xxxxxxxxx/xxxxxxxxxx
slack.webhook_url = 'xxxxxxxxxxxxxxxxxxxxxxxx'

# The integration token
slack.token = 'xxxxxxxxxxxxxxxxxxxxxxxx'

##
# Optional
Expand Down

0 comments on commit 6f59d4f

Please sign in to comment.