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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5599f6fb6901d7b9c7009d6343288916829b97a
4
- data.tar.gz: 60d21036bd104a7bda04b8dbb9da0b4a0747a8b7
3
+ metadata.gz: 8d741922d25b1c2a19c397045f22e37565f6f665
4
+ data.tar.gz: 25b452bb8bb9ffee8ed85c60a5c9e9dd522470a8
5
5
  SHA512:
6
- metadata.gz: b6199f52c950a2470e651937f2f91ceb67abf95d0987b3c7cf441f9fe3e2e8b405a14a3570d110f367c308bdebafe7bd4f797661c9ce6f563d1ec5d54ea077bf
7
- data.tar.gz: 9b7efc69cbeaa137a68e6240f94a198e8932ec4ea7deb48b45d9b46b5091b8118a1ad511d455c4eb91de7d38471c5e54119f5122586d7fed6b9463b6b4525daa
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
- attachments = payload.fetch(:attachments, payload["attachments"])
12
- wrap_array(attachments).each do |attachment|
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
 
@@ -24,6 +24,8 @@ module Slack
24
24
 
25
25
  # rubocop:disable Style/GuardClause
26
26
  def formatted
27
+ return @orig unless @orig.respond_to?(:gsub)
28
+
27
29
  sub_markdown_links(sub_html_links(@orig))
28
30
  rescue => e
29
31
  if RUBY_VERSION < "2.1" && e.message.include?("invalid byte sequence")
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Slack
3
3
  class Notifier
4
- VERSION = "2.2.1".freeze # rubocop:disable Style/RedundantFreeze
4
+ VERSION = "2.2.2".freeze # rubocop:disable Style/RedundantFreeze
5
5
  end
6
6
  end
@@ -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.1
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-05-29 00:00:00.000000000 Z
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: