lita-who_has 0.2.0 → 0.3.0
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/.rubocop.yml +7 -1
- data/README.md +11 -2
- data/lib/lita-who_has.rb +2 -0
- data/lib/lita/handlers/who_has.rb +43 -8
- data/lib/utils/lita_who_has/persistence.rb +37 -0
- data/lita-who_has.gemspec +1 -1
- data/locales/en.yml +6 -0
- data/spec/lita/handlers/{envy_spec.rb → who_has_spec.rb} +114 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c99be336dde9c2950bd9d3ad523818b1a14cfbba
|
4
|
+
data.tar.gz: 28bae1cdaba8e069113355ce4187589cc164c5a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bde6f282575f4eaf20a29b9c9eb7e48659f184e6d62b8a7eeb09df63bb7d114179e12b1bebbb26b01c1b747962cf0de4478579c0952a893c6a0c849f2ddfd493
|
7
|
+
data.tar.gz: 0faa35bd1e21722f520bf8afd232612d65a5ed2a156e981aa41ec08e7cef41311f8183584b73f97df7065f8a95ba3d415a4520f58b9bc55d9fae89e8ee4fbc9a
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# lita-who_has
|
2
2
|
|
3
3
|
[](https://travis-ci.org/knuedge/lita-who_has)
|
4
|
-
[](https://coveralls.io/github/knuedge/lita-who_has)
|
5
5
|
|
6
|
-
|
6
|
+
Still using (and need to keep track of) physical things? This plugin helps record and retrieve information about those things.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -26,6 +26,15 @@ config.handlers.who_has.namespace = 'my_project'
|
|
26
26
|
@bot release thing1
|
27
27
|
@bot forget thing1
|
28
28
|
@bot claimables
|
29
|
+
@bot claim thing2
|
29
30
|
@bot claimables thing.*
|
31
|
+
# => thing2 (user)
|
30
32
|
@bot wrestle thing2 from Jon Doe
|
33
|
+
@bot describe thing2 location the moon
|
34
|
+
@bot describe thing2
|
35
|
+
# => Here's what I know about thing2
|
36
|
+
# => {
|
37
|
+
# "in use by": "user",
|
38
|
+
# "location": "the moon"
|
39
|
+
# }
|
31
40
|
```
|
data/lib/lita-who_has.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'lita'
|
2
3
|
|
3
4
|
Lita.load_locales Dir[File.expand_path(
|
4
5
|
File.join('..', '..', 'locales', '*.yml'), __FILE__
|
5
6
|
)]
|
6
7
|
|
8
|
+
require 'utils/lita_who_has/persistence'
|
7
9
|
require 'lita/handlers/who_has'
|
8
10
|
|
9
11
|
Lita::Handlers::WhoHas.template_root File.expand_path(
|
@@ -2,6 +2,8 @@ module Lita
|
|
2
2
|
module Handlers
|
3
3
|
# The main handler for the WhoHas plugin
|
4
4
|
class WhoHas < Handler
|
5
|
+
include Utils::LitaWhoHas::Persistence
|
6
|
+
|
5
7
|
route(
|
6
8
|
/\Aclaim ([A-Za-z0-9_]+)\Z/,
|
7
9
|
:claim_thing,
|
@@ -30,6 +32,16 @@ module Lita
|
|
30
32
|
command: true
|
31
33
|
)
|
32
34
|
|
35
|
+
route(
|
36
|
+
/\Adescribe ([A-Za-z0-9_]+)(\s+([A-Za-z0-9_]+)\s+(.+))?\Z/,
|
37
|
+
:describe_thing,
|
38
|
+
help: {
|
39
|
+
'describe [THING ID]' => 'Report on any details for thing',
|
40
|
+
'describe [THING ID] [KEY] [VALUE]' => 'Describe the KEY attribute as VALUE for a thing'
|
41
|
+
},
|
42
|
+
command: true
|
43
|
+
)
|
44
|
+
|
33
45
|
route(
|
34
46
|
/\Awrestle ([A-Za-z0-9_]+) from (.*)\Z/,
|
35
47
|
:claim_used_thing,
|
@@ -166,14 +178,37 @@ module Lita
|
|
166
178
|
end
|
167
179
|
end
|
168
180
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
181
|
+
def describe_thing(response)
|
182
|
+
thing_id, _, attribute, value = response.matches.first
|
183
|
+
owner = current_user(thing_id)
|
184
|
+
case owner
|
185
|
+
when nil
|
186
|
+
response.reply t(
|
187
|
+
'describe_thing.failure.thing_unknown',
|
188
|
+
thing_id: thing_id
|
189
|
+
)
|
190
|
+
when '', response.user.name
|
191
|
+
if attribute && value
|
192
|
+
describe(thing_id, attribute, value)
|
193
|
+
response.reply t(
|
194
|
+
'describe_thing.success', key: attribute, thing_id: thing_id
|
195
|
+
)
|
196
|
+
else
|
197
|
+
response.reply t('describe_thing.description', thing_id: thing_id)
|
198
|
+
response.reply('/code ' + full_description_json(thing_id))
|
199
|
+
end
|
200
|
+
else
|
201
|
+
if attribute && value
|
202
|
+
response.reply t(
|
203
|
+
'describe_thing.failure.thing_in_use_by_other_user',
|
204
|
+
thing_id: thing_id,
|
205
|
+
user: owner
|
206
|
+
)
|
207
|
+
else
|
208
|
+
response.reply t('describe_thing.description', thing_id: thing_id)
|
209
|
+
response.reply('/code ' + full_description_json(thing_id))
|
210
|
+
end
|
211
|
+
end
|
177
212
|
end
|
178
213
|
|
179
214
|
Lita.register_handler(self)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Utils
|
2
|
+
module LitaWhoHas
|
3
|
+
# Utility methods for working with Lita's Redis
|
4
|
+
module Persistence
|
5
|
+
private
|
6
|
+
|
7
|
+
def key(thing_id)
|
8
|
+
['whohas_things', config.namespace, thing_id].join(':')
|
9
|
+
end
|
10
|
+
|
11
|
+
def description(thing_id)
|
12
|
+
value = redis.hget(key(thing_id), 'description')
|
13
|
+
value && !value.empty? ? JSON.parse(value) : {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def describe(thing_id, dkey, dvalue)
|
17
|
+
new_desc = description(thing_id).merge(dkey => dvalue)
|
18
|
+
redis.hset(key(thing_id), 'description', new_desc.to_json)
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_user(thing_id)
|
22
|
+
redis.hget(key(thing_id), 'user')
|
23
|
+
end
|
24
|
+
|
25
|
+
def full_description_json(thing_id)
|
26
|
+
owner = current_user(thing_id)
|
27
|
+
JSON.pretty_generate(
|
28
|
+
if owner && !owner.empty?
|
29
|
+
{ 'in use by' => owner }
|
30
|
+
else
|
31
|
+
{}
|
32
|
+
end.merge(description(thing_id))
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lita-who_has.gemspec
CHANGED
data/locales/en.yml
CHANGED
@@ -29,3 +29,9 @@ en:
|
|
29
29
|
list_things:
|
30
30
|
failure:
|
31
31
|
no_things: "Hmm, I'm not tracking anything that matches your query"
|
32
|
+
describe_thing:
|
33
|
+
success: Description '%{key}' set for %{thing_id}
|
34
|
+
failure:
|
35
|
+
thing_unknown: "Hmm, I do not know about %{thing_id}"
|
36
|
+
thing_in_use_by_other_user: "I can't change the description for %{thing_id} while it's in use by %{user}"
|
37
|
+
description: "Here's what I know about %{thing_id}"
|
@@ -11,6 +11,8 @@ describe Lita::Handlers::WhoHas, lita_handler: true do
|
|
11
11
|
it { is_expected.to route_command('claimables').to(:list_things) }
|
12
12
|
it { is_expected.to route_command('forget ENV123').to(:forget_thing) }
|
13
13
|
it { is_expected.to route_command('wrestle ENV123 from Alicia').to(:claim_used_thing) }
|
14
|
+
it { is_expected.to route_command('describe ENV123').to(:describe_thing) }
|
15
|
+
it { is_expected.to route_command('describe ENV123 key value').to(:describe_thing) }
|
14
16
|
end
|
15
17
|
|
16
18
|
describe 'User claiming thing' do
|
@@ -333,4 +335,116 @@ describe Lita::Handlers::WhoHas, lita_handler: true do
|
|
333
335
|
end
|
334
336
|
end
|
335
337
|
end
|
338
|
+
|
339
|
+
describe 'User describing a thing' do
|
340
|
+
context 'when thing is currently in use by specified user' do
|
341
|
+
before(:each) do
|
342
|
+
subject.redis.hset('whohas_things:my_project:ENV123', 'user', 'Alicia')
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'adds a description key' do
|
346
|
+
alicia = Lita::User.create(123, name: 'Alicia')
|
347
|
+
send_command('describe ENV123 location the moon', as: alicia)
|
348
|
+
expect(subject.redis.hget('whohas_things:my_project:ENV123', 'description'))
|
349
|
+
.to eq({ 'location' => 'the moon' }.to_json)
|
350
|
+
expect(replies.first).to eq('Description \'location\' set for ENV123')
|
351
|
+
end
|
352
|
+
|
353
|
+
it 'allows retrieving a description' do
|
354
|
+
alicia = Lita::User.create(123, name: 'Alicia')
|
355
|
+
subject.redis.hset(
|
356
|
+
'whohas_things:my_project:ENV123',
|
357
|
+
'description',
|
358
|
+
{ 'location' => 'the moon' }.to_json
|
359
|
+
)
|
360
|
+
send_command('describe ENV123', as: alicia)
|
361
|
+
expect(replies.first).to eq('Here\'s what I know about ENV123')
|
362
|
+
expect(replies.last).to eq(
|
363
|
+
'/code ' + JSON.pretty_generate(
|
364
|
+
'in use by' => 'Alicia',
|
365
|
+
'location' => 'the moon'
|
366
|
+
)
|
367
|
+
)
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context 'when thing is available' do
|
372
|
+
before(:each) do
|
373
|
+
subject.redis.hset('whohas_things:my_project:ENV345', 'user', '')
|
374
|
+
end
|
375
|
+
|
376
|
+
it 'adds a description key' do
|
377
|
+
alicia = Lita::User.create(123, name: 'Alicia')
|
378
|
+
send_command('describe ENV345 location mars', as: alicia)
|
379
|
+
expect(subject.redis.hget('whohas_things:my_project:ENV345', 'description'))
|
380
|
+
.to eq({ 'location' => 'mars' }.to_json)
|
381
|
+
expect(replies.first).to eq('Description \'location\' set for ENV345')
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'allows retrieving a description' do
|
385
|
+
alicia = Lita::User.create(123, name: 'Alicia')
|
386
|
+
subject.redis.hset(
|
387
|
+
'whohas_things:my_project:ENV345',
|
388
|
+
'description',
|
389
|
+
{ 'location' => 'mars' }.to_json
|
390
|
+
)
|
391
|
+
send_command('describe ENV345', as: alicia)
|
392
|
+
expect(replies.first).to eq('Here\'s what I know about ENV345')
|
393
|
+
expect(replies.last).to eq(
|
394
|
+
'/code ' + JSON.pretty_generate(
|
395
|
+
'location' => 'mars'
|
396
|
+
)
|
397
|
+
)
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
context 'when thing is unknown to bot' do
|
402
|
+
before(:each) do
|
403
|
+
subject.redis.del('whohas_things:my_project:ENV123')
|
404
|
+
end
|
405
|
+
|
406
|
+
it 'replies with a notification' do
|
407
|
+
alicia = Lita::User.create(123, name: 'Alicia')
|
408
|
+
send_command('describe ENV123', as: alicia)
|
409
|
+
expect(replies.first).to eq('Hmm, I do not know about ENV123')
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
context 'when thing is in use by another user' do
|
414
|
+
before(:each) do
|
415
|
+
subject.redis.hset('whohas_things:my_project:ENV234', 'user', 'Carl')
|
416
|
+
end
|
417
|
+
|
418
|
+
it 'leaves the thing untouched' do
|
419
|
+
alicia = Lita::User.create(123, name: 'Alicia')
|
420
|
+
send_command('describe ENV234 disposition sunny', as: alicia)
|
421
|
+
expect(subject.redis.hget('whohas_things:my_project:ENV234', 'user')).to eq('Carl')
|
422
|
+
end
|
423
|
+
|
424
|
+
it 'replies with a notification' do
|
425
|
+
alicia = Lita::User.create(123, name: 'Alicia')
|
426
|
+
send_command('describe ENV234 disposition sunny', as: alicia)
|
427
|
+
expect(replies.first).to eq(
|
428
|
+
'I can\'t change the description for ENV234 while it\'s in use by Carl'
|
429
|
+
)
|
430
|
+
end
|
431
|
+
|
432
|
+
it 'allows retrieving a description' do
|
433
|
+
alicia = Lita::User.create(123, name: 'Alicia')
|
434
|
+
subject.redis.hset(
|
435
|
+
'whohas_things:my_project:ENV234',
|
436
|
+
'description',
|
437
|
+
{ 'disposition' => 'cloudy' }.to_json
|
438
|
+
)
|
439
|
+
send_command('describe ENV234', as: alicia)
|
440
|
+
expect(replies.first).to eq('Here\'s what I know about ENV234')
|
441
|
+
expect(replies.last).to eq(
|
442
|
+
'/code ' + JSON.pretty_generate(
|
443
|
+
'in use by' => 'Carl',
|
444
|
+
'disposition' => 'cloudy'
|
445
|
+
)
|
446
|
+
)
|
447
|
+
end
|
448
|
+
end
|
449
|
+
end
|
336
450
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-who_has
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Gnagy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -179,9 +179,10 @@ files:
|
|
179
179
|
- Rakefile
|
180
180
|
- lib/lita-who_has.rb
|
181
181
|
- lib/lita/handlers/who_has.rb
|
182
|
+
- lib/utils/lita_who_has/persistence.rb
|
182
183
|
- lita-who_has.gemspec
|
183
184
|
- locales/en.yml
|
184
|
-
- spec/lita/handlers/
|
185
|
+
- spec/lita/handlers/who_has_spec.rb
|
185
186
|
- spec/spec_helper.rb
|
186
187
|
- templates/.gitkeep
|
187
188
|
homepage: https://github.com/knuedge/lita-who_has
|
@@ -205,10 +206,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
206
|
version: '0'
|
206
207
|
requirements: []
|
207
208
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.
|
209
|
+
rubygems_version: 2.6.8
|
209
210
|
signing_key:
|
210
211
|
specification_version: 4
|
211
212
|
summary: Record and retrieve information about things
|
212
213
|
test_files:
|
213
|
-
- spec/lita/handlers/
|
214
|
+
- spec/lita/handlers/who_has_spec.rb
|
214
215
|
- spec/spec_helper.rb
|