bender-bot 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/bender/bot.rb +38 -14
  4. data/lib/bender/main.rb +2 -2
  5. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c283ea7083ad833690d22b910550e2ea8c611011
4
- data.tar.gz: 9b621bcb3cf8ac33b63ca2e2f3e9a213708b5cc4
3
+ metadata.gz: c92f8f176538d8e81ca22f3c7b032981c91ea7ce
4
+ data.tar.gz: 85a6f7a33ce6945786dea6918378db2527619299
5
5
  SHA512:
6
- metadata.gz: 1eff378cba2f9b35d3bedda415a8d488c8a18d2a72e74e2de3ecbd2c270e53cdccf6acc48aeb4ea0a6f4e0ef4595f360c7a59b76e388438f84515eea2ad77b6a
7
- data.tar.gz: acfb05cfdc199ce95a640d970c6da58f49ac244ff640527edbe9b375cf282e88af1fb055e6629a420981fac6423017fe02ae028dc81c699339336fa489126e54
6
+ metadata.gz: 05d9d101c52c63e2dda43964cdcbc470c73b323eb99f5d7b8d93c92dd67fe35a98f4a6260a2d2d1ef29b2601007a84c5050247f4af30ab6148c3444586336003
7
+ data.tar.gz: 9a6bc3702182bcd3e3a31a028fbc284b91dd3cbbce7bc7c54f15c7961a865b89db7ddc79fb3032a8b14c64fa10502e6438f91dc90a5c04400d67520cc7d0d0c3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.5.0
@@ -15,11 +15,12 @@ Bot = Robut # alias
15
15
 
16
16
 
17
17
  module Bot
18
- def self.run! options
18
+ def self.run! options, logger
19
19
  hipchat = HipChat::Client.new(options.hipchat_token)
20
20
  BenderBot.class_variable_set :@@hipchat, hipchat
21
21
  BenderBot.class_variable_set :@@rooms, hipchat.rooms
22
22
  BenderBot.class_variable_set :@@options, options
23
+ BenderBot.class_variable_set :@@logger, logger
23
24
  Bot::Plugin.plugins = [ BenderBot ]
24
25
  conn = Bot::Connection.new
25
26
  conn.store['users'] ||= {}
@@ -109,13 +110,21 @@ class BenderBot
109
110
 
110
111
  when /^\s*\/whoami\s*$/
111
112
  u = user_where name: sender
112
- m = '<b>%{nick}</b>: %{name} (<a href="mailto:%{email}">%{email}</a>)' % u
113
- reply_html m, :purple
113
+ if u
114
+ m = '<b>%{nick}</b>: %{name} (<a href="mailto:%{email}">%{email}</a>)' % u
115
+ reply_html m, :purple
116
+ else
117
+ reply_html "Couldn't find the associated user in JIRA", :red
118
+ end
114
119
 
115
120
  when /^\s*\/lookup\s+(.+)\s*$/
116
121
  u = user_where(name: $1) || user_where(nick: $1)
117
- m = '<b>%{nick}</b>: %{name} (<a href="mailto:%{email}">%{email}</a>)' % u
118
- reply_html m, :purple
122
+ if u
123
+ m = '<b>%{nick}</b>: %{name} (<a href="mailto:%{email}">%{email}</a>)' % u
124
+ reply_html m, :purple
125
+ else
126
+ reply_html "Couldn't find the associated user in JIRA", :red
127
+ end
119
128
 
120
129
  # /inc help - This help text
121
130
  when /^\s*(\?inc|\/inc\s+help)\s*$/
@@ -272,7 +281,9 @@ class BenderBot
272
281
  comment = $2
273
282
  user = user_where name: sender
274
283
 
275
- if incident
284
+ if !user
285
+ reply_html "Couldn't find the associated user in JIRA", :red
286
+ elsif incident
276
287
  reply_html *comment_on_incident(incident, comment, user)
277
288
  else
278
289
  reply_html 'Sorry, no such incident!', :red
@@ -292,25 +303,38 @@ class BenderBot
292
303
 
293
304
  private
294
305
 
306
+ def log ; @@logger end
307
+
295
308
  def options ; @@options end
296
309
 
297
- def user_where fields, threshold=0.8
310
+ def user_where fields, threshold=0.85
298
311
  field, value = fields.to_a.shift
299
312
  suggested_user = store['users'].values.sort_by do |u|
300
313
  compare value, u[field]
301
314
  end.last
302
315
 
303
316
  distance = compare value, suggested_user[field]
304
- return distance < threshold ? nil : suggested_user
317
+
318
+ user = distance < threshold ? nil : suggested_user
319
+
320
+ log.trace \
321
+ action: 'user_where',
322
+ fields: fields,
323
+ threshold: threshold,
324
+ field: field,
325
+ value: value,
326
+ suggested_user: suggested_user,
327
+ distance: distance,
328
+ user: user
329
+
330
+ return user
305
331
  end
306
332
 
307
333
 
308
334
  def compare name1, name2
309
- n1 = name1.gsub /\W/, ''
310
- n2 = name2.gsub /\W/, ''
311
- d1 = JARO.getDistance n1.downcase, n2.downcase
312
- d2 = JARO.getDistance n1, n2
313
- return d1 + d2 / 2.0
335
+ n1 = name1.gsub(/\W/, '').downcase
336
+ n2 = name2.gsub(/\W/, '').downcase
337
+ JARO.getDistance n1, n2
314
338
  end
315
339
 
316
340
 
@@ -446,7 +470,7 @@ private
446
470
 
447
471
  def allowed?
448
472
  user = user_where name: @sender
449
- store['group'].include? user[:name]
473
+ user && store['group'].include?(user[:name])
450
474
  end
451
475
 
452
476
  end
@@ -168,7 +168,7 @@ module Bender
168
168
  config.logger = log
169
169
  end
170
170
 
171
- Bot.run! options
171
+ Bot.run! options, log
172
172
  end
173
173
 
174
174
 
@@ -189,7 +189,7 @@ module Bender
189
189
 
190
190
  @open = nil unless defined? @open
191
191
 
192
- log.info \
192
+ log.trace \
193
193
  primary_room_name: bot.store['primary_room_name'],
194
194
  primary_room_topic: bot.store['primary_room_topic'],
195
195
  new_room_name: new_room['name'],
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bender-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Clemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.6.0
61
+ version: 0.6.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.6.0
68
+ version: 0.6.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hipchat
71
71
  requirement: !ruby/object:Gem::Requirement