Skip to content

Commit 5706b9d

Browse files
committed
Merge pull request smartinez87#243 from a-suenami/use_webhook_url_for_slack_notifier
Use webhook url for slack notifier.
2 parents f5dd6eb + 9f39b42 commit 5706b9d

File tree

5 files changed

+13
-54
lines changed

5 files changed

+13
-54
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ GEM
127127
multi_json (~> 1.0)
128128
simplecov-html (~> 0.7.1)
129129
simplecov-html (0.7.1)
130-
slack-notifier (0.5.0)
130+
slack-notifier (1.0.0)
131131
sprockets (2.1.3)
132132
hike (~> 1.2)
133133
rack (~> 1.0)
@@ -169,6 +169,6 @@ DEPENDENCIES
169169
rails (>= 3.0.4)
170170
resque (~> 1.2.0)
171171
sidekiq (~> 3.0)
172-
slack-notifier (>= 0.5)
172+
slack-notifier (>= 1.0.0)
173173
sqlite3 (>= 1.3.4)
174174
tinder (~> 1.8)

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,7 @@ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
571571
:exception_recipients => %w{[email protected]}
572572
},
573573
:slack => {
574-
:team => "myteam",
575-
:token => "secret-token",
574+
:webhook_url => "[Your webhook url]",
576575
:channel => "#exceptions",
577576
:additional_parameters => {
578577
:icon_url => "http://image.jpg"

exception_notification.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ Gem::Specification.new do |s|
3030
s.add_development_dependency "appraisal", "~> 1.0.0"
3131
s.add_development_dependency "hipchat", ">= 1.0.0"
3232
s.add_development_dependency "carrier-pigeon", ">= 0.7.0"
33-
s.add_development_dependency "slack-notifier", ">= 0.5"
33+
s.add_development_dependency "slack-notifier", ">= 1.0.0"
3434
end

lib/exception_notifier/slack_notifier.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,10 @@ class SlackNotifier
55

66
def initialize(options)
77
begin
8-
team = options.fetch(:team)
9-
token = options.fetch(:token)
10-
custom_hook = options.fetch(:custom_hook, nil)
8+
webhook_url = options.fetch(:webhook_url)
119
options[:username] ||= 'ExceptionNotifierBot'
1210
@message_opts = options.fetch(:additional_parameters, {})
13-
14-
if custom_hook.nil?
15-
@notifier = Slack::Notifier.new team, token, options
16-
else
17-
@notifier = Slack::Notifier.new team, token, custom_hook, options
18-
end
11+
@notifier = Slack::Notifier.new webhook_url, options
1912
rescue
2013
@notifier = nil
2114
end

test/exception_notifier/slack_notifier_test.rb

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ class SlackNotifierTest < ActiveSupport::TestCase
55

66
test "should send a slack notification if properly configured" do
77
options = {
8-
token: "token",
9-
team: "team"
8+
webhook_url: "http://slack.webhook.url"
109
}
1110

1211
Slack::Notifier.any_instance.expects(:ping).with(fake_notification, {})
@@ -15,25 +14,9 @@ class SlackNotifierTest < ActiveSupport::TestCase
1514
slack_notifier.call(fake_exception)
1615
end
1716

18-
test "should send a notification as the specified hook" do
19-
options = {
20-
token: "token",
21-
team: "team",
22-
custom_hook: "custom"
23-
}
24-
25-
Slack::Notifier.any_instance.expects(:ping).with(fake_notification, {})
26-
27-
slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
28-
slack_notifier.call(fake_exception)
29-
30-
assert_equal slack_notifier.notifier.hook_name, "custom"
31-
end
32-
3317
test "should send the notification to the specified channel" do
3418
options = {
35-
token: "token",
36-
team: "team",
19+
webhook_url: "http://slack.webhook.url",
3720
channel: "channel"
3821
}
3922

@@ -47,8 +30,7 @@ class SlackNotifierTest < ActiveSupport::TestCase
4730

4831
test "should send the notification to the specified username" do
4932
options = {
50-
token: "token",
51-
team: "team",
33+
webhook_url: "http://slack.webhook.url",
5234
username: "username"
5335
}
5436

@@ -62,8 +44,7 @@ class SlackNotifierTest < ActiveSupport::TestCase
6244

6345
test "should have the username 'ExceptionNotifierBot' when unspecified" do
6446
options = {
65-
token: "token",
66-
team: "team",
47+
webhook_url: "http://slack.webhook.url",
6748
}
6849

6950
Slack::Notifier.any_instance.expects(:ping).with(fake_notification, {})
@@ -76,8 +57,7 @@ class SlackNotifierTest < ActiveSupport::TestCase
7657

7758
test "should pass the additional parameters to Slack::Notifier.ping" do
7859
options = {
79-
token: "token",
80-
team: "team",
60+
webhook_url: "http://slack.webhook.url",
8161
username: "test",
8262
custom_hook: "hook",
8363
additional_parameters: {
@@ -91,21 +71,8 @@ class SlackNotifierTest < ActiveSupport::TestCase
9171
slack_notifier.call(fake_exception)
9272
end
9373

94-
test "shouldn't send a slack notification if token is missing" do
95-
options = {
96-
team: "test"
97-
}
98-
99-
slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
100-
101-
assert_nil slack_notifier.notifier
102-
assert_nil slack_notifier.call(fake_exception)
103-
end
104-
105-
test "shouldn't send a slack notification if team is missing" do
106-
options = {
107-
token: "test"
108-
}
74+
test "shouldn't send a slack notification if webhook url is missing" do
75+
options = {}
10976

11077
slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
11178

0 commit comments

Comments
 (0)