lita-enhance 0.9.2 → 0.9.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bab760c36e5ebb11ec2c0773f6de3c1096fc1582
4
- data.tar.gz: 4139bbccc64e710503d0aec21d2b8b13ba0f87bb
3
+ metadata.gz: 856a763659c54a676c1516beac9bd6e3f6bfcc9b
4
+ data.tar.gz: 6254798d459f7209b75c0513cff2f3eb29d30a3f
5
5
  SHA512:
6
- metadata.gz: 5cdec5118bd90e90fa50427da94bd33e243bd76db7cbb067ec755928b094cce0bc5fa745129b2b92139d356935e6336c4fde8644f0971205d2397d3afb727b67
7
- data.tar.gz: ae27a421db43c6cd1134297942257e154670c508ce79a477ba23b305d366e80c6102b652ec3a794ad0e25bbba16a620d206fdf042315112a4e36691e0d802f25
6
+ metadata.gz: da9f0f937afced190dbba4e7625215646bb1f87a75a1778fb6459fe8acb10cfa909b94dc44da0823a20ec4ba1e5cb51c6cd4f6677acd616bd9fdabf02261552f
7
+ data.tar.gz: a51619607f7538fcb21f08f54b40f61b28f7caabef17feb5f1431c321cdcd4eee011e03b5d6717608cd3eec91b2bf2be73f4f404462aa26c27f8f3e3ebcdc4ea
data/README.md CHANGED
@@ -31,7 +31,7 @@ Machine details are obtained by indexing database of machine assets. Right now o
31
31
 
32
32
  ```
33
33
  you> enhance lvl:2 old-box01
34
- lita> ¿old-box01 (us-east-1)?
34
+ lita> ?old-box01 (us-east-1)?
35
35
  ```
36
36
 
37
37
  [And for fun](https://www.youtube.com/watch?v=Vxq9yj2pVWk), you can implicitly enhance previously enhanced text by just sending ```enhance```. The string to enhance is retained separately in each room that the enhance string was sent.
@@ -70,9 +70,9 @@ module Lita
70
70
  after(0) do
71
71
  begin
72
72
  lock_and_refresh_index
73
- response.reply(success(t 'refresh.success'))
73
+ response.reply(render_template('success', message: (t 'refresh.success')))
74
74
  rescue => e
75
- response.reply(failed(t 'refresh.failed'))
75
+ response.reply(render_template('failed', message: (t 'refresh.failed')))
76
76
  log.info { "#{e.message}\n#{e.backtrace.join("\n")}" }
77
77
  end
78
78
  end
@@ -97,26 +97,26 @@ module Lita
97
97
  end
98
98
 
99
99
  unless blurry_string
100
- response.reply(failed(t 'enhance.message_required'))
100
+ response.reply(render_template('failed', message: (t 'enhance.message_required')))
101
101
  return
102
102
  end
103
103
 
104
104
  level = session.last_level + 1 unless level
105
105
 
106
106
  if level > max_level
107
- response.reply(failed(t 'enhance.level_too_high', max_level: max_level))
107
+ response.reply(render_template('failed', message: (t 'enhance.level_too_high', max_level: max_level)))
108
108
  return
109
109
  elsif level < 1
110
- response.reply(failed(t 'enhance.level_too_low', max_level: max_level))
110
+ response.reply(render_template('failed', message: (t 'enhance.level_too_low', max_level: max_level)))
111
111
  return
112
112
  end
113
113
 
114
114
  enhanced_message = session.enhance!(blurry_string, level)
115
115
 
116
116
  if enhanced_message != blurry_string
117
- response.reply(render_template('enhance', message: enhanced_message))
117
+ response.reply(render_template('mono', message: enhanced_message))
118
118
  else
119
- response.reply(no_change(t 'enhance.nothing_to_enhance'))
119
+ response.reply(render_template('no_change', message: (t 'enhance.nothing_to_enhance')))
120
120
  end
121
121
  end
122
122
 
@@ -132,68 +132,28 @@ module Lita
132
132
  end
133
133
 
134
134
  private
135
- # This mutex must be obtained to refresh the index
136
- REFRESH_MUTEX = Mutex.new unless defined?(REFRESH_MUTEX)
137
135
 
138
- # This mutex must be obtains to update the index with new data, or to use the index to enhance some text
139
- INDEX_MUTEX = Mutex.new unless defined?(INDEX_MUTEX)
136
+ # This mutex must be obtained to refresh the index
137
+ REFRESH_MUTEX ||= Mutex.new
140
138
 
141
- def lock_and_refresh_index
142
- REFRESH_MUTEX.synchronize do
143
- @@chef_indexer.refresh
144
- end
145
- end
146
-
147
- def last_message_key(response)
148
- response.message.source.room || response.message.source.user.id
149
- end
150
-
151
- def max_level
152
- @@enhancers.map {|x| x.max_level }.max
153
- end
154
-
155
- def adapter
156
- if Lita.respond_to?(:config)
157
- Lita.config.robot.adapter
158
- elsif robot.respond_to?(:config)
159
- robot.config.robot.adapter
160
- else
161
- :unknown
162
- end
163
- end
139
+ # This mutex must be obtains to update the index with new data, or to use the index to enhance some text
140
+ INDEX_MUTEX ||= Mutex.new
164
141
 
165
- # Calls out that this message was successful via adapter specific messaging
166
- def success(message)
167
- case adapter
168
- when :hipchat
169
- "(successful) #{message}"
170
- else
171
- message
172
- end
142
+ def lock_and_refresh_index
143
+ REFRESH_MUTEX.synchronize do
144
+ @@chef_indexer.refresh
173
145
  end
146
+ end
174
147
 
175
- # Calls out that the action failed via adapter specific messaging
176
- def failed(message)
177
- case adapter
178
- when :hipchat
179
- "(failed) #{message}"
180
- else
181
- message
182
- end
183
- end
148
+ def last_message_key(response)
149
+ response.message.source.room || response.message.source.user.id
150
+ end
184
151
 
185
- # Calls out that action resulted in no change via adapter specific messaging
186
- def no_change(message)
187
- case adapter
188
- when :hipchat
189
- "(nothingtodohere) #{message}"
190
- else
191
- message
192
- end
193
- end
152
+ def max_level
153
+ @@enhancers.map {|x| x.max_level }.max
154
+ end
194
155
  end
195
156
 
196
-
197
157
  Lita.register_handler(Enhance)
198
158
  end
199
159
  end
@@ -7,7 +7,7 @@ module Lita
7
7
  @@subclasses = []
8
8
 
9
9
  @@current = %w(* *)
10
- @@old = %w(¿ ?)
10
+ @@old = %w(? ?)
11
11
 
12
12
  def self.all
13
13
  @@subclasses.select! {|x| x.weakref_alive? }
data/lita-enhance.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-enhance"
3
- spec.version = "0.9.2"
3
+ spec.version = "0.9.3"
4
4
  spec.authors = ["Doug Barth"]
5
5
  spec.email = ["doug@pagerduty.com"]
6
6
  spec.description = %q{A Lita handler that enhances text by replacing opaque machine identifiers with that machine's hostname}
@@ -10,7 +10,7 @@ RSpec.shared_examples 'an enhancer' do
10
10
  node = nodes.first
11
11
  node.last_seen_at = Time.now - 24 * 60 * 60
12
12
 
13
- expect(enhancer.render(node, 1)).to eq('¿box01?')
14
- expect(enhancer.render(node, 2)).to eq('¿box01 (us-west-2b)?')
13
+ expect(enhancer.render(node, 1)).to eq('?box01?')
14
+ expect(enhancer.render(node, 2)).to eq('?box01 (us-west-2b)?')
15
15
  end
16
16
  end
@@ -3,18 +3,20 @@ require "spec_helper"
3
3
  describe Lita::Handlers::Enhance, lita_handler: true do
4
4
  include_context 'indexed'
5
5
 
6
+ before { allow(described_class).to receive(:new).and_return(subject) }
7
+
6
8
  # Make sure that we are indexing into the same Redis namespace that the handler uses.
7
9
  let(:redis) { subject.redis }
8
10
 
9
- let(:alice) { Lita::User.create("2", name: "Alice") }
11
+ let(:alice) { Lita::User.create('2', name: 'Alice') }
10
12
 
11
- it { routes_command('refresh enhance').to(:refresh) }
12
- it { routes_command('enhance stats').to(:stats) }
13
+ it { is_expected.to route_command('refresh enhance').to(:refresh) }
14
+ it { is_expected.to route_command('enhance stats').to(:stats) }
13
15
 
14
- it { routes_command('enhance 127.0.0.1').to(:enhance) }
15
- it { routes_command("enhance lvl:1 blah\nblah").to(:enhance) }
16
- it { routes_command("enhance").to(:enhance) }
17
- it { routes_command("enhance lvl:2").to(:enhance) }
16
+ it { is_expected.to route_command('enhance 127.0.0.1').to(:enhance) }
17
+ it { is_expected.to route_command("enhance lvl:1 blah\nblah").to(:enhance) }
18
+ it { is_expected.to route_command('enhance').to(:enhance) }
19
+ it { is_expected.to route_command('enhance lvl:2').to(:enhance) }
18
20
 
19
21
  it 'should show stats about itself' do
20
22
  send_command('enhance stats')
@@ -103,18 +105,40 @@ describe Lita::Handlers::Enhance, lita_handler: true do
103
105
 
104
106
  describe 'under Slack' do
105
107
  before do
106
- robot.config.robot.adapter = :slack
108
+ allow_any_instance_of(Lita::TemplateResolver).to receive(:adapter_name).and_return(:slack)
109
+ end
110
+
111
+ it 'should mark success using an emoji' do
112
+ expect(subject).to receive(:lock_and_refresh_index)
113
+
114
+ send_command('refresh enhance')
115
+
116
+ # Give the timer a chance to run
117
+ sleep(0.5)
118
+
119
+ expect(replies).to include('Will refresh enhance index...')
120
+ expect(replies).to include(':heavy_check_mark: Refreshed enhance index')
121
+ end
122
+
123
+ it 'mark failure using an emoji' do
124
+ send_command('enhance')
125
+ expect(replies).to include(':heavy_multiplication_x: I need a string to enhance')
107
126
  end
108
127
 
109
- it 'should format the response with a code block' do
128
+ it 'should use backticks to render mono text' do
110
129
  send_command('enhance 54.214.188.37')
111
130
  expect(replies).to include('```*box01*```')
112
131
  end
132
+
133
+ it 'should use emoji to call out when nothing was found to enhance' do
134
+ send_command('enhance bubbles')
135
+ expect(replies).to include(':heavy_minus_sign: I could not find anything to enhance')
136
+ end
113
137
  end
114
138
 
115
139
  describe 'under HipChat' do
116
140
  before do
117
- robot.config.robot.adapter = :hipchat
141
+ allow_any_instance_of(Lita::TemplateResolver).to receive(:adapter_name).and_return(:hipchat)
118
142
  end
119
143
 
120
144
  it 'should mark success using an emoji' do
data/spec/spec_helper.rb CHANGED
@@ -62,3 +62,5 @@ RSpec.shared_context 'indexed' do
62
62
  end
63
63
  end
64
64
  end
65
+
66
+ Lita.version_3_compatibility_mode = false
File without changes
@@ -0,0 +1 @@
1
+ (failed) <%= @message %>
@@ -0,0 +1 @@
1
+ :heavy_multiplication_x: <%= @message %>
@@ -0,0 +1 @@
1
+ <%= @message %>
File without changes
File without changes
@@ -0,0 +1 @@
1
+ <%= @message %>
@@ -0,0 +1 @@
1
+ (nothingtodohere) <%= @message %>
@@ -0,0 +1 @@
1
+ :heavy_minus_sign: <%= @message %>
@@ -0,0 +1 @@
1
+ <%= @message %>
@@ -0,0 +1 @@
1
+ (successful) <%= @message %>
@@ -0,0 +1 @@
1
+ :heavy_check_mark: <%= @message %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-enhance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Barth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -123,9 +123,18 @@ files:
123
123
  - spec/lita/handlers/enhance/session_spec.rb
124
124
  - spec/lita/handlers/enhance_spec.rb
125
125
  - spec/spec_helper.rb
126
- - templates/enhance.erb
127
- - templates/enhance.hipchat.erb
128
- - templates/enhance.slack.erb
126
+ - templates/failed.erb
127
+ - templates/failed.hipchat.erb
128
+ - templates/failed.slack.erb
129
+ - templates/mono.erb
130
+ - templates/mono.hipchat.erb
131
+ - templates/mono.slack.erb
132
+ - templates/no_change.erb
133
+ - templates/no_change.hipchat.erb
134
+ - templates/no_change.slack.erb
135
+ - templates/success.erb
136
+ - templates/success.hipchat.erb
137
+ - templates/success.slack.erb
129
138
  homepage: https://github.com/PagerDuty/lita-enhance
130
139
  licenses:
131
140
  - MIT