slack-notifier 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slack-notifier/payload_middleware/format_attachments.rb +8 -2
- data/lib/slack-notifier/util/link_formatter.rb +2 -0
- data/lib/slack-notifier/version.rb +1 -1
- data/spec/end_to_end_spec.rb +12 -2
- data/spec/lib/slack-notifier/payload_middleware/format_attachments_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d741922d25b1c2a19c397045f22e37565f6f665
|
4
|
+
data.tar.gz: 25b452bb8bb9ffee8ed85c60a5c9e9dd522470a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d54f11cc362ca57bd76792dc38d2e7755cc0f483144cce7721da028825a53227b4ecf703eac2fa910225a8a2ac02748e982b7fd3d372250cf9fe4bc1ce57519
|
7
|
+
data.tar.gz: c9eee1509416474730ff6a7f4aa63819c9f3297ce3720f28505489359cb12f7426e004b76ce3fc04b9047166eab36a2beed4c45e186ed5389211b4b5e806388e
|
@@ -8,15 +8,21 @@ module Slack
|
|
8
8
|
options formats: [:html, :markdown]
|
9
9
|
|
10
10
|
def call payload={}
|
11
|
-
|
12
|
-
|
11
|
+
payload = payload.dup
|
12
|
+
attachments = payload.delete(:attachments)
|
13
|
+
attachments = payload.delete("attachments") unless attachments
|
14
|
+
|
15
|
+
attachments = wrap_array(attachments).map do |attachment|
|
13
16
|
["text", :text].each do |key|
|
14
17
|
if attachment.key?(key)
|
15
18
|
attachment[key] = Util::LinkFormatter.format(attachment[key], options)
|
16
19
|
end
|
17
20
|
end
|
21
|
+
|
22
|
+
attachment
|
18
23
|
end
|
19
24
|
|
25
|
+
payload[:attachments] = attachments if attachments && !attachments.empty?
|
20
26
|
payload
|
21
27
|
end
|
22
28
|
|
data/spec/end_to_end_spec.rb
CHANGED
@@ -31,6 +31,9 @@ RSpec.describe Slack::Notifier do
|
|
31
31
|
{ text: "hello", channel: "hodor" } =>
|
32
32
|
{ payload: { text: "hello", channel: "hodor" } },
|
33
33
|
|
34
|
+
{ text: nil, attachments: [{ text: "attachment message" }] } =>
|
35
|
+
{ payload: { text: nil, attachments: [{ text: "attachment message" }] } },
|
36
|
+
|
34
37
|
{ text: "the message", channel: "foo", attachments: [{ color: "#000",
|
35
38
|
text: "attachment message",
|
36
39
|
fallback: "fallback message" }] } =>
|
@@ -50,9 +53,16 @@ RSpec.describe Slack::Notifier do
|
|
50
53
|
{ attachments: { color: "#000",
|
51
54
|
text: "attachment message [hodor](http://winterfell.com)",
|
52
55
|
fallback: "fallback message" } } =>
|
53
|
-
{ payload: { attachments: { color: "#000",
|
56
|
+
{ payload: { attachments: [{ color: "#000",
|
54
57
|
text: "attachment message <http://winterfell.com|hodor>",
|
55
|
-
fallback: "fallback message" } } },
|
58
|
+
fallback: "fallback message" }] } },
|
59
|
+
|
60
|
+
{ attachments: { color: "#000",
|
61
|
+
text: nil,
|
62
|
+
fallback: "fallback message" } } =>
|
63
|
+
{ payload: { attachments: [{ color: "#000",
|
64
|
+
text: nil,
|
65
|
+
fallback: "fallback message" }] } },
|
56
66
|
|
57
67
|
{ text: "hello", http_options: { timeout: 5 } } =>
|
58
68
|
{ http_options: { timeout: 5 }, payload: { text: "hello" } }
|
@@ -26,6 +26,18 @@ RSpec.describe Slack::Notifier::PayloadMiddleware::FormatAttachments do
|
|
26
26
|
subject.call(attachments: { text: "hello" })
|
27
27
|
end
|
28
28
|
|
29
|
+
it "wraps attachment into array if given as a single hash" do
|
30
|
+
params = {
|
31
|
+
attachments: { text: "hello" }
|
32
|
+
}
|
33
|
+
payload = {
|
34
|
+
attachments: [{ text: "hello" }]
|
35
|
+
}
|
36
|
+
subject = described_class.new(:notifier);
|
37
|
+
|
38
|
+
expect(subject.call(params)).to eq payload
|
39
|
+
end
|
40
|
+
|
29
41
|
it "returns the payload unmodified if not :attachments key" do
|
30
42
|
payload = { foo: :bar }
|
31
43
|
subject = described_class.new(:notifier)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Sloan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " A slim ruby wrapper for posting to slack webhooks "
|
14
14
|
email:
|