rake_notification 0.0.3 → 0.0.4

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: 07560d974879e7daaef1ce69dd0e9afbe02f6ff7
4
- data.tar.gz: a1fbf4e5eab50209297c7e41f0436e819838a99f
3
+ metadata.gz: 651cdd19573953198185b9bf0e12dbb032a09b2f
4
+ data.tar.gz: 085a81246f721c1b40a2c139f1e89ae7d4790c09
5
5
  SHA512:
6
- metadata.gz: f1bb34963c920fe7305cf887a950ac60747374fb00e5f39d1acc09acc9de32942b705dd6e15db22fa4a6dbb782c01bd70138d01b19fa9e2654b3ad1278ea0b62
7
- data.tar.gz: 9f8cefe36de1166f5a362960f620e464554ec8d323524c777d992cc5297a6b1edadbfbc4095943e3d6c6947baa3d12321f524a0050329261780317edb922a79a
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
@@ -1,3 +1,3 @@
1
1
  module RakeNotification
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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
- label = system_exit.success? ? SUCCESS_LABEL : FAILED_LABEL
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
@@ -1,4 +1,5 @@
1
1
  require 'rspec'
2
+ require 'rspec/mocks'
2
3
  require 'rspec/its'
3
4
  require 'rake'
4
5
  require 'rake_notification'
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.3
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-03-18 00:00:00.000000000 Z
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