rake_notification 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rake_notification/version.rb +1 -1
- data/lib/rake_notifier/slack.rb +72 -0
- data/lib/rake_notifier.rb +1 -0
- data/rake_notification.gemspec +1 -0
- data/spec/lib/rake_notifier/slack_spec.rb +52 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07560d974879e7daaef1ce69dd0e9afbe02f6ff7
|
4
|
+
data.tar.gz: a1fbf4e5eab50209297c7e41f0436e819838a99f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1bb34963c920fe7305cf887a950ac60747374fb00e5f39d1acc09acc9de32942b705dd6e15db22fa4a6dbb782c01bd70138d01b19fa9e2654b3ad1278ea0b62
|
7
|
+
data.tar.gz: 9f8cefe36de1166f5a362960f620e464554ec8d323524c777d992cc5297a6b1edadbfbc4095943e3d6c6947baa3d12321f524a0050329261780317edb922a79a
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'active_support/core_ext/string/strip'
|
2
|
+
require 'breacan'
|
3
|
+
|
4
|
+
module RakeNotifier
|
5
|
+
class Slack < Base
|
6
|
+
|
7
|
+
START_LABEL = ":construction: *[START]*"
|
8
|
+
SUCCESS_LABEL = ":congratulations: *[SUCCESS]*"
|
9
|
+
FAILED_LABEL = ":x: *[FAILED]*"
|
10
|
+
|
11
|
+
def initialize(token, channel, icon: nil, username: nil)
|
12
|
+
@client = Client.new(token, channel: channel, icon: icon, username: username)
|
13
|
+
end
|
14
|
+
|
15
|
+
def started_task(task)
|
16
|
+
notice <<-EOS.strip_heredoc
|
17
|
+
#{START_LABEL} `$ #{task.reconstructed_command_line}`
|
18
|
+
>>> from #{hostname} at #{Time.now} RAILS_ENV=#{rails_env}
|
19
|
+
EOS
|
20
|
+
end
|
21
|
+
|
22
|
+
def completed_task(task, system_exit)
|
23
|
+
label = system_exit.success? ? SUCCESS_LABEL : FAILED_LABEL
|
24
|
+
notice <<-EOS.strip_heredoc
|
25
|
+
#{label} `$ #{task.reconstructed_command_line}`
|
26
|
+
>>> exit #{system_exit.status} from #{hostname} at #{Time.now} RAILS_ENV=#{rails_env}
|
27
|
+
EOS
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def notice(msg)
|
32
|
+
@client.ping(msg)
|
33
|
+
end
|
34
|
+
|
35
|
+
class Client
|
36
|
+
def initialize(token, channel: '#test', icon: nil, username: nil)
|
37
|
+
Breacan.access_token = @token = token
|
38
|
+
@channel = channel
|
39
|
+
@icon = icon
|
40
|
+
@username = username
|
41
|
+
end
|
42
|
+
attr_accessor :token, :channel, :icon, :username
|
43
|
+
|
44
|
+
def args_to_post(msg)
|
45
|
+
arg = {
|
46
|
+
channel: channel,
|
47
|
+
text: msg,
|
48
|
+
as_user: false,
|
49
|
+
}
|
50
|
+
arg[icon_key(icon)] = icon if icon
|
51
|
+
arg[:username] = username if username
|
52
|
+
arg
|
53
|
+
end
|
54
|
+
|
55
|
+
def ping(msg)
|
56
|
+
Breacan.chat_post_message(args_to_post(msg))
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def icon_key(icon_info)
|
61
|
+
case icon_info
|
62
|
+
when /^https?:\/\//
|
63
|
+
:icon_url
|
64
|
+
when /^:.+:$/
|
65
|
+
:icon_emoji
|
66
|
+
else
|
67
|
+
raise "May be invalid icon format: #{icon_info}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/rake_notifier.rb
CHANGED
data/rake_notification.gemspec
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RakeNotifier::Slack do
|
4
|
+
let(:notifier) { described_class.new(token, channel, username: username, icon: icon) }
|
5
|
+
subject { notifier }
|
6
|
+
|
7
|
+
let(:token) { 'xoxo-Example-T0k3N' }
|
8
|
+
let(:channel) { '#rake_notification' }
|
9
|
+
let(:username) { nil }
|
10
|
+
let(:icon) { nil }
|
11
|
+
let(:task) { double(:reconstructed_command_line => 'rake sample') }
|
12
|
+
|
13
|
+
it { is_expected.to respond_to :started_task }
|
14
|
+
it { is_expected.to respond_to :completed_task }
|
15
|
+
|
16
|
+
context 'variables' do
|
17
|
+
subject { notifier.instance_variable_get(:@client) }
|
18
|
+
|
19
|
+
let(:username) { 'Rake bot' }
|
20
|
+
let(:icon) { 'http://example.com/icon.png' }
|
21
|
+
|
22
|
+
its(:channel) { is_expected.to eq '#rake_notification' }
|
23
|
+
its(:username) { is_expected.to eq 'Rake bot' }
|
24
|
+
its(:icon) { is_expected.to eq 'http://example.com/icon.png' }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'posting' do
|
28
|
+
before do
|
29
|
+
expect(subject.instance_variable_get(:@client)).to receive(:ping).with(an_instance_of(String)).once
|
30
|
+
end
|
31
|
+
|
32
|
+
it { subject.started_task(task) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'posting to internal client' do
|
36
|
+
let(:username) { 'Rake bot' }
|
37
|
+
let(:icon) { 'http://example.com/icon.png' }
|
38
|
+
|
39
|
+
before do
|
40
|
+
expect(Breacan).to receive(:chat_post_message)
|
41
|
+
.with(hash_including(
|
42
|
+
channel: channel,
|
43
|
+
icon_url: icon,
|
44
|
+
username: username,
|
45
|
+
as_user: false,
|
46
|
+
text: an_instance_of(String)
|
47
|
+
)).once
|
48
|
+
end
|
49
|
+
|
50
|
+
it { subject.started_task(task) }
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake_notification
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mizokami
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: breacan
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,10 +127,12 @@ files:
|
|
113
127
|
- lib/rake_notification/version.rb
|
114
128
|
- lib/rake_notifier.rb
|
115
129
|
- lib/rake_notifier/ikachan.rb
|
130
|
+
- lib/rake_notifier/slack.rb
|
116
131
|
- rake_notification.gemspec
|
117
132
|
- spec/lib/rake_notification_spec.rb
|
118
133
|
- spec/lib/rake_notifier/ikachan/client_spec.rb
|
119
134
|
- spec/lib/rake_notifier/ikachan_spec.rb
|
135
|
+
- spec/lib/rake_notifier/slack_spec.rb
|
120
136
|
- spec/lib/rake_notifier_spec.rb
|
121
137
|
- spec/spec_helper.rb
|
122
138
|
homepage: ''
|
@@ -139,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
155
|
version: '0'
|
140
156
|
requirements: []
|
141
157
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.4.5
|
143
159
|
signing_key:
|
144
160
|
specification_version: 4
|
145
161
|
summary: Rake notification
|
@@ -147,5 +163,6 @@ test_files:
|
|
147
163
|
- spec/lib/rake_notification_spec.rb
|
148
164
|
- spec/lib/rake_notifier/ikachan/client_spec.rb
|
149
165
|
- spec/lib/rake_notifier/ikachan_spec.rb
|
166
|
+
- spec/lib/rake_notifier/slack_spec.rb
|
150
167
|
- spec/lib/rake_notifier_spec.rb
|
151
168
|
- spec/spec_helper.rb
|