slack-notifier 1.3.1 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/slack-notifier/link_formatter.rb +2 -2
- data/lib/slack-notifier/version.rb +1 -1
- data/lib/slack-notifier.rb +27 -2
- data/spec/integration/ping_integration_test.rb +1 -0
- data/spec/lib/slack-notifier/link_formatter_spec.rb +10 -0
- data/spec/lib/slack-notifier_spec.rb +43 -0
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e74413c9d125dd2a973d6035bdc86e6f28549839
|
|
4
|
+
data.tar.gz: 6081e63972a12dc07acc866e13f8e6bae8a1992d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 252d1d23a8bb02cfe9ebee51c8d68436799daa59c95572dd18bc481797069ed2fa6fac96869845ffeae900fbf5d73c9df9b4e910f9190f7ca85937293e8d3e31
|
|
7
|
+
data.tar.gz: bda7747d3bd8e34a0ca2798d50c06c4f2b6e426c2552c2d389247f6ed60ce48a82d26e7f77e7e9c179388e831163d36a237dfe139cdddec689fdb154ee3b7d1b
|
|
@@ -52,9 +52,9 @@ module Slack
|
|
|
52
52
|
/ <a (?:.*?) href=['"](.+?)['"] (?:.*?)> (.+?) <\/a> /x
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
# http://rubular.com/r/
|
|
55
|
+
# http://rubular.com/r/guJbTK6x1f
|
|
56
56
|
def markdown_pattern
|
|
57
|
-
/\[ ([^\[\]]*?) \] \( (https?:\/\/.*?) \) /x
|
|
57
|
+
/\[ ([^\[\]]*?) \] \( ((https?:\/\/.*?) | (mailto:.*?)) \) /x
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
end
|
data/lib/slack-notifier.rb
CHANGED
|
@@ -15,11 +15,26 @@ module Slack
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def ping message, options={}
|
|
18
|
-
message
|
|
19
|
-
|
|
18
|
+
if message.is_a?(Hash)
|
|
19
|
+
message, options = nil, message
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
if attachments = options[:attachments] || options["attachments"]
|
|
23
|
+
wrap_array(attachments).each do |attachment|
|
|
24
|
+
["text", :text].each do |key|
|
|
25
|
+
attachment[key] = LinkFormatter.format(attachment[key]) if attachment.has_key?(key)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
payload = default_payload.merge(options)
|
|
20
31
|
client = payload.delete(:http_client) || http_client
|
|
21
32
|
http_options = payload.delete(:http_options)
|
|
22
33
|
|
|
34
|
+
unless message.nil?
|
|
35
|
+
payload.merge!(text: LinkFormatter.format(message))
|
|
36
|
+
end
|
|
37
|
+
|
|
23
38
|
params = { payload: payload.to_json }
|
|
24
39
|
params[:http_options] = http_options if http_options
|
|
25
40
|
|
|
@@ -52,5 +67,15 @@ module Slack
|
|
|
52
67
|
def escape(text)
|
|
53
68
|
text.gsub(HTML_ESCAPE_REGEXP, HTML_ESCAPE)
|
|
54
69
|
end
|
|
70
|
+
|
|
71
|
+
def wrap_array(object)
|
|
72
|
+
if object.nil?
|
|
73
|
+
[]
|
|
74
|
+
elsif object.respond_to?(:to_ary)
|
|
75
|
+
object.to_ary || [object]
|
|
76
|
+
else
|
|
77
|
+
[object]
|
|
78
|
+
end
|
|
79
|
+
end
|
|
55
80
|
end
|
|
56
81
|
end
|
|
@@ -4,3 +4,4 @@ require_relative '../../lib/slack-notifier'
|
|
|
4
4
|
notifier = Slack::Notifier.new ENV['SLACK_WEBHOOK_URL'], username: 'notifier'
|
|
5
5
|
puts "testing with ruby #{RUBY_VERSION}"
|
|
6
6
|
notifier.ping "hello/こんにちは from notifier test script on ruby: #{RUBY_VERSION}\225"
|
|
7
|
+
notifier.ping attachments: [{color:"#1BF5AF",fallback:"fallback",text:"attachment"}]
|
|
@@ -63,6 +63,16 @@ describe Slack::Notifier::LinkFormatter do
|
|
|
63
63
|
expect(formatted).to eq "こんにちは"
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
+
it "handles mailto links in markdown" do
|
|
67
|
+
formatted = described_class.format("[John](mailto:john@example.com)")
|
|
68
|
+
expect(formatted).to eq "<mailto:john@example.com|John>"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "handles mailto links in html" do
|
|
72
|
+
formatted = described_class.format("<a href='mailto:john@example.com'>John</a>")
|
|
73
|
+
expect(formatted).to eq "<mailto:john@example.com|John>"
|
|
74
|
+
end
|
|
75
|
+
|
|
66
76
|
end
|
|
67
77
|
|
|
68
78
|
end
|
|
@@ -32,6 +32,49 @@ describe Slack::Notifier do
|
|
|
32
32
|
described_class.new('http://example.com').ping "the message", channel: 'foo'
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
it "passes attachment messages through LinkFormatter" do
|
|
36
|
+
expect( Slack::Notifier::LinkFormatter ).to receive(:format)
|
|
37
|
+
.with("the message")
|
|
38
|
+
expect( Slack::Notifier::LinkFormatter ).to receive(:format)
|
|
39
|
+
.with("attachment message")
|
|
40
|
+
|
|
41
|
+
described_class.new('http://example.com').ping "the message", channel: 'foo',
|
|
42
|
+
attachments: [{
|
|
43
|
+
color: "#000",
|
|
44
|
+
text: "attachment message",
|
|
45
|
+
fallback: "fallback message"
|
|
46
|
+
}]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "allows sending only an attachment" do
|
|
50
|
+
expect( Slack::Notifier::DefaultHTTPClient ).to receive(:post).with(
|
|
51
|
+
URI.parse('http://example.com'),
|
|
52
|
+
payload: '{"channel":"foo","attachments":[{"text":"attachment","fallback":"fallback"}]}'
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
expect{
|
|
56
|
+
described_class.new('http://example.com')
|
|
57
|
+
.ping channel: 'foo',
|
|
58
|
+
attachments: [{
|
|
59
|
+
text: 'attachment',
|
|
60
|
+
fallback: 'fallback'
|
|
61
|
+
}]
|
|
62
|
+
}.not_to raise_error
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "passes attachment messages through LinkFormatter, even if a single value is passed" do
|
|
66
|
+
expect( Slack::Notifier::LinkFormatter ).to receive(:format)
|
|
67
|
+
.with("a random message")
|
|
68
|
+
expect( Slack::Notifier::LinkFormatter ).to receive(:format)
|
|
69
|
+
.with("attachment message")
|
|
70
|
+
attachment = {
|
|
71
|
+
color: "#000",
|
|
72
|
+
text: "attachment message",
|
|
73
|
+
fallback: "fallback message"
|
|
74
|
+
}
|
|
75
|
+
subject.ping "a random message", attachments: attachment
|
|
76
|
+
end
|
|
77
|
+
|
|
35
78
|
context "with a default channel set" do
|
|
36
79
|
|
|
37
80
|
before :each do
|
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slack-notifier
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steven Sloan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-12-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description:
|
|
13
|
+
description: " A slim ruby wrapper for posting to slack webhooks "
|
|
14
14
|
email:
|
|
15
15
|
- stevenosloan@gmail.com
|
|
16
16
|
executables: []
|
|
@@ -36,17 +36,17 @@ require_paths:
|
|
|
36
36
|
- lib
|
|
37
37
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
38
|
requirements:
|
|
39
|
-
- -
|
|
39
|
+
- - ">="
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
41
|
version: '0'
|
|
42
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
|
-
- -
|
|
44
|
+
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
46
|
version: '0'
|
|
47
47
|
requirements: []
|
|
48
48
|
rubyforge_project:
|
|
49
|
-
rubygems_version: 2.4.5
|
|
49
|
+
rubygems_version: 2.4.5.1
|
|
50
50
|
signing_key:
|
|
51
51
|
specification_version: 4
|
|
52
52
|
summary: A slim ruby wrapper for posting to slack webhooks
|