rake_notification 0.0.3 → 0.0.4
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/README.md +18 -0
- data/lib/rake_notification/version.rb +1 -1
- data/lib/rake_notifier/slack.rb +9 -3
- data/spec/lib/rake_notifier/slack_spec.rb +63 -1
- data/spec/spec_helper.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 651cdd19573953198185b9bf0e12dbb032a09b2f
|
4
|
+
data.tar.gz: 085a81246f721c1b40a2c139f1e89ae7d4790c09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 514d8d9b91e3109a0bdf948fe695ecb3ce8cd7e94471d4a720c2ae88119a1bd66b7877a5be478276463c2137168aa38adfafbc0abe8391f476f52e04822e051f
|
7
|
+
data.tar.gz: fd23c639108d9f67ff480fa9bce78b1eccae4b193d8397f5f620427ba4a796d78382c6dac049748613da4c8faae593484b75b14aabba906b0da5bc7eda4632df
|
data/README.md
CHANGED
@@ -33,6 +33,24 @@ Rake.application.register_interceptor ikachan
|
|
33
33
|
Rake.application.register_observer ikachan
|
34
34
|
```
|
35
35
|
|
36
|
+
#### Slack Notifier
|
37
|
+
|
38
|
+
```rb
|
39
|
+
# config/rake_notification.rb
|
40
|
+
|
41
|
+
token = 'xoxp-XXXXXXXXXXXXXX...'
|
42
|
+
channel = '#rake_notification'
|
43
|
+
slack = RakeNotifier::Slack.new(
|
44
|
+
token, channel,
|
45
|
+
icon: 'http://www.pubnub.com/docs/img/ruby.png',
|
46
|
+
username: 'rake result',
|
47
|
+
notice_when_fail: '@here' # false when not to make notice
|
48
|
+
)
|
49
|
+
|
50
|
+
Rake.application.register_interceptor slack
|
51
|
+
Rake.application.register_observer slack
|
52
|
+
```
|
53
|
+
|
36
54
|
#### Custom Notifier
|
37
55
|
|
38
56
|
```rb
|
data/lib/rake_notifier/slack.rb
CHANGED
@@ -8,8 +8,12 @@ module RakeNotifier
|
|
8
8
|
SUCCESS_LABEL = ":congratulations: *[SUCCESS]*"
|
9
9
|
FAILED_LABEL = ":x: *[FAILED]*"
|
10
10
|
|
11
|
-
def initialize(token, channel, icon: nil, username: nil)
|
11
|
+
def initialize(token, channel, icon: nil, username: nil, notice_when_fail: false)
|
12
12
|
@client = Client.new(token, channel: channel, icon: icon, username: username)
|
13
|
+
@notice_when_fail = notice_when_fail
|
14
|
+
if @notice_when_fail and !@notice_when_fail.is_a?(String)
|
15
|
+
@notice_when_fail = "@channel"
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
def started_task(task)
|
@@ -20,9 +24,11 @@ module RakeNotifier
|
|
20
24
|
end
|
21
25
|
|
22
26
|
def completed_task(task, system_exit)
|
23
|
-
|
27
|
+
success = system_exit.success?
|
28
|
+
label = success ? SUCCESS_LABEL : FAILED_LABEL
|
29
|
+
at_channel = (success or !@notice_when_fail) ? "" : " #{@notice_when_fail}"
|
24
30
|
notice <<-EOS.strip_heredoc
|
25
|
-
#{label} `$ #{task.reconstructed_command_line}
|
31
|
+
#{label} `$ #{task.reconstructed_command_line}`#{at_channel}
|
26
32
|
>>> exit #{system_exit.status} from #{hostname} at #{Time.now} RAILS_ENV=#{rails_env}
|
27
33
|
EOS
|
28
34
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RakeNotifier::Slack do
|
4
|
-
let(:notifier) { described_class.new(token, channel, username: username, icon: icon) }
|
4
|
+
let(:notifier) { described_class.new(token, channel, username: username, icon: icon, notice_when_fail: notice_when_fail) }
|
5
5
|
subject { notifier }
|
6
6
|
|
7
7
|
let(:token) { 'xoxo-Example-T0k3N' }
|
8
8
|
let(:channel) { '#rake_notification' }
|
9
9
|
let(:username) { nil }
|
10
10
|
let(:icon) { nil }
|
11
|
+
let(:notice_when_fail) { false }
|
11
12
|
let(:task) { double(:reconstructed_command_line => 'rake sample') }
|
12
13
|
|
13
14
|
it { is_expected.to respond_to :started_task }
|
@@ -49,4 +50,65 @@ describe RakeNotifier::Slack do
|
|
49
50
|
|
50
51
|
it { subject.started_task(task) }
|
51
52
|
end
|
53
|
+
|
54
|
+
context 'messages to post' do
|
55
|
+
now = Time.now
|
56
|
+
let(:time_now) { now }
|
57
|
+
|
58
|
+
before do
|
59
|
+
allow(Time).to receive(:now) { time_now }
|
60
|
+
allow(subject).to receive(:hostname) { 'rake.example.com' }
|
61
|
+
|
62
|
+
allow(subject).to receive(:notice) do |arg|
|
63
|
+
@string_to_be_posted = arg
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'on start' do
|
68
|
+
it {
|
69
|
+
subject.started_task(task)
|
70
|
+
expect(@string_to_be_posted).to eq(<<-EOS)
|
71
|
+
:construction: *[START]* `$ rake sample`
|
72
|
+
>>> from rake.example.com at #{time_now.to_s} RAILS_ENV=development
|
73
|
+
EOS
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'on success' do
|
78
|
+
let(:exit_status) { double(:success? => true, :status => 0) }
|
79
|
+
|
80
|
+
it {
|
81
|
+
subject.completed_task(task, exit_status)
|
82
|
+
expect(@string_to_be_posted).to eq(<<-EOS)
|
83
|
+
:congratulations: *[SUCCESS]* `$ rake sample`
|
84
|
+
>>> exit 0 from rake.example.com at #{time_now.to_s} RAILS_ENV=development
|
85
|
+
EOS
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'on failed' do
|
90
|
+
let(:exit_status) { double(:success? => false, :status => 127) }
|
91
|
+
|
92
|
+
it {
|
93
|
+
subject.completed_task(task, exit_status)
|
94
|
+
expect(@string_to_be_posted).to eq(<<-EOS)
|
95
|
+
:x: *[FAILED]* `$ rake sample`
|
96
|
+
>>> exit 127 from rake.example.com at #{time_now.to_s} RAILS_ENV=development
|
97
|
+
EOS
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'on failed when notice' do
|
102
|
+
let(:exit_status) { double(:success? => false, :status => 127) }
|
103
|
+
let(:notice_when_fail) { '@here' }
|
104
|
+
|
105
|
+
it {
|
106
|
+
subject.completed_task(task, exit_status)
|
107
|
+
expect(@string_to_be_posted).to eq(<<-EOS)
|
108
|
+
:x: *[FAILED]* `$ rake sample` @here
|
109
|
+
>>> exit 127 from rake.example.com at #{time_now.to_s} RAILS_ENV=development
|
110
|
+
EOS
|
111
|
+
}
|
112
|
+
end
|
113
|
+
end
|
52
114
|
end
|
data/spec/spec_helper.rb
CHANGED
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mizokami
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.4.5
|
158
|
+
rubygems_version: 2.4.5.1
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Rake notification
|