lita-envy 0.1.3 → 0.1.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 +6 -0
- data/lib/lita/handlers/envy.rb +20 -8
- data/lita-envy.gemspec +3 -3
- data/spec/lita/handlers/envy_spec.rb +40 -36
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25e7123d1dcedb17ef798f0a8de34d821f1222c8
|
4
|
+
data.tar.gz: 634e009f649a0f27359f0bb14a2ed470c9883d30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ff8c2852f565d0bd49d7d86c0fb4932e1de81e7c1a26020915529fecb495a2e9a92e5b808a91b2bdcf61944fa9874b306870e0885d5d0703f13b6fe85a0b803
|
7
|
+
data.tar.gz: a60fd300627ebb64594baa252deceed6f649f05ba0e6fe18bf70fe251fb8b63bae85f7d019882dfbfb705df06780bf971a789cb06b3dbe225d6ae4c006df1502
|
data/README.md
CHANGED
data/lib/lita/handlers/envy.rb
CHANGED
@@ -8,11 +8,17 @@ module Lita
|
|
8
8
|
route /\Aforget ([A-Za-z0-9_]+)\Z/, :forget_environment, help: { "forget [ENV ID]" => "Forget environment"}, command: true
|
9
9
|
route /\Awrestle ([A-Za-z0-9_]+) from (.*)\Z/, :claim_used_environment, help: { "wrestle [ENV ID] from [USER]" => "Mark environment as in use by you, even though it is currently in use by another user"}, command: true
|
10
10
|
|
11
|
+
config :namespace, :required => true do
|
12
|
+
validate do |value|
|
13
|
+
"can only contain lowercase letters, numbers and underscores" unless value.match(/\A[a-z0-9_]+\Z/)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
11
17
|
def claim_environment(response)
|
12
18
|
env_id = response.matches.first.first
|
13
|
-
current_user = redis.hget(
|
19
|
+
current_user = redis.hget(key(env_id), 'user')
|
14
20
|
if current_user.nil? || current_user.empty?
|
15
|
-
redis.hset(
|
21
|
+
redis.hset(key(env_id), 'user', response.user.name)
|
16
22
|
response.reply('ok')
|
17
23
|
elsif current_user == response.user.name
|
18
24
|
response.reply("Hmm, you are already using #{env_id}")
|
@@ -23,9 +29,9 @@ module Lita
|
|
23
29
|
|
24
30
|
def release_environment(response)
|
25
31
|
env_id = response.matches.first.first
|
26
|
-
current_user = redis.hget(
|
32
|
+
current_user = redis.hget(key(env_id), 'user')
|
27
33
|
if current_user == response.user.name
|
28
|
-
redis.hset(
|
34
|
+
redis.hset(key(env_id), 'user', nil)
|
29
35
|
response.reply('ok')
|
30
36
|
elsif current_user.nil? || current_user.empty?
|
31
37
|
response.reply("Hmm, you are not currently using #{env_id}")
|
@@ -49,13 +55,13 @@ module Lita
|
|
49
55
|
|
50
56
|
def forget_environment(response)
|
51
57
|
env_id = response.matches.first.first
|
52
|
-
current_user = redis.hget(
|
58
|
+
current_user = redis.hget(key(env_id), 'user')
|
53
59
|
if current_user == response.user.name
|
54
60
|
response.reply("Hmm, you are currently using #{env_id}")
|
55
61
|
elsif current_user.nil?
|
56
62
|
response.reply("Hmm, I do not know about #{env_id}")
|
57
63
|
elsif current_user.empty?
|
58
|
-
redis.del(
|
64
|
+
redis.del(key(env_id))
|
59
65
|
response.reply('ok')
|
60
66
|
else
|
61
67
|
response.reply("Hmm, #{env_id} is currently in use by #{current_user}")
|
@@ -64,9 +70,9 @@ module Lita
|
|
64
70
|
|
65
71
|
def claim_used_environment(response)
|
66
72
|
env_id, specified_user = response.matches.first
|
67
|
-
current_user = redis.hget(
|
73
|
+
current_user = redis.hget(key(env_id), 'user')
|
68
74
|
if specified_user == current_user
|
69
|
-
redis.hset(
|
75
|
+
redis.hset(key(env_id), 'user', response.user.name)
|
70
76
|
response.reply('ok')
|
71
77
|
elsif current_user.nil? or current_user.empty?
|
72
78
|
response.reply("Hmm, #{env_id} is not currently in use")
|
@@ -77,6 +83,12 @@ module Lita
|
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
86
|
+
private
|
87
|
+
|
88
|
+
def key(env_id)
|
89
|
+
['environments', config.namespace, env_id].join(':')
|
90
|
+
end
|
91
|
+
|
80
92
|
Lita.register_handler(self)
|
81
93
|
end
|
82
94
|
end
|
data/lita-envy.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-envy"
|
3
|
-
spec.version = "0.1.
|
3
|
+
spec.version = "0.1.4"
|
4
4
|
spec.authors = ["Ingo Weiss"]
|
5
|
-
spec.email = ["ingo
|
6
|
-
spec.description = "
|
5
|
+
spec.email = ["ingo@ingoweiss.com"]
|
6
|
+
spec.description = "Helps with management of environment ussage. Adds commands for claiming and releasing environments"
|
7
7
|
spec.summary = "Record and retrieve information about environment usage"
|
8
8
|
spec.homepage = "https://github.com/ingoweiss/lita-envy"
|
9
9
|
spec.license = "MIT"
|
@@ -2,6 +2,10 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Lita::Handlers::Envy, lita_handler: true do
|
4
4
|
|
5
|
+
before(:each) do
|
6
|
+
allow(subject.config).to receive(:namespace).and_return('my_project')
|
7
|
+
end
|
8
|
+
|
5
9
|
describe 'Routing' do
|
6
10
|
|
7
11
|
it { is_expected.to route_command("claim ENV123").to(:claim_environment) }
|
@@ -17,13 +21,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
17
21
|
context "when environment is available" do
|
18
22
|
|
19
23
|
before(:each) do
|
20
|
-
subject.redis.hset('environments:ENV123', 'user', '')
|
24
|
+
subject.redis.hset('environments:my_project:ENV123', 'user', '')
|
21
25
|
end
|
22
26
|
|
23
27
|
it "should mark environment as in use by user" do
|
24
28
|
carl = Lita::User.create(123, name: "Carl")
|
25
29
|
send_command('claim ENV123', :as => carl)
|
26
|
-
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
|
30
|
+
expect(subject.redis.hget('environments:my_project:ENV123', 'user')).to eq("Carl")
|
27
31
|
end
|
28
32
|
|
29
33
|
it "should reply with confirmation" do
|
@@ -36,13 +40,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
36
40
|
context "when environment is unknown to bot" do
|
37
41
|
|
38
42
|
before(:each) do
|
39
|
-
subject.redis.del('environments:ENV123')
|
43
|
+
subject.redis.del('environments:my_project:ENV123')
|
40
44
|
end
|
41
45
|
|
42
46
|
it "should mark environment as in use by user" do
|
43
47
|
carl = Lita::User.create(123, name: "Carl")
|
44
48
|
send_command('claim ENV123', :as => carl)
|
45
|
-
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
|
49
|
+
expect(subject.redis.hget('environments:my_project:ENV123', 'user')).to eq("Carl")
|
46
50
|
end
|
47
51
|
|
48
52
|
it "should reply with confirmation" do
|
@@ -55,17 +59,17 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
55
59
|
context "when environment is in use by another user" do
|
56
60
|
|
57
61
|
before(:each) do
|
58
|
-
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
62
|
+
subject.redis.hset('environments:my_project:ENV123', 'user', 'Alicia')
|
59
63
|
end
|
60
64
|
|
61
65
|
it "should leave the environment untouched" do
|
62
66
|
carl = Lita::User.create(123, name: "Carl")
|
63
67
|
send_command('claim ENV123', :as => carl)
|
64
|
-
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Alicia")
|
68
|
+
expect(subject.redis.hget('environments:my_project:ENV123', 'user')).to eq("Alicia")
|
65
69
|
end
|
66
70
|
|
67
71
|
it "should reply with notification" do
|
68
|
-
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
72
|
+
subject.redis.hset('environments:my_project:ENV123', 'user', 'Alicia')
|
69
73
|
carl = Lita::User.create(123, name: "Carl")
|
70
74
|
send_command('claim ENV123', :as => carl)
|
71
75
|
expect(replies.first).to eq("Hmm, ENV123 is currently in use by Alicia")
|
@@ -76,17 +80,17 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
76
80
|
context "when environment is already in use by user" do
|
77
81
|
|
78
82
|
before(:each) do
|
79
|
-
subject.redis.hset('environments:ENV123', 'user', 'Carl')
|
83
|
+
subject.redis.hset('environments:my_project:ENV123', 'user', 'Carl')
|
80
84
|
end
|
81
85
|
|
82
86
|
it "should leave the environment untouched" do
|
83
87
|
carl = Lita::User.create(123, name: "Carl")
|
84
88
|
send_command('claim ENV123', :as => carl)
|
85
|
-
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
|
89
|
+
expect(subject.redis.hget('environments:my_project:ENV123', 'user')).to eq("Carl")
|
86
90
|
end
|
87
91
|
|
88
92
|
it "should reply with notification" do
|
89
|
-
subject.redis.hset('environments:ENV123', 'user', 'Carl')
|
93
|
+
subject.redis.hset('environments:my_project:ENV123', 'user', 'Carl')
|
90
94
|
carl = Lita::User.create(123, name: "Carl")
|
91
95
|
send_command('claim ENV123', :as => carl)
|
92
96
|
expect(replies.first).to eq("Hmm, you are already using ENV123")
|
@@ -101,13 +105,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
101
105
|
context "when environment is in use by user" do
|
102
106
|
|
103
107
|
before(:each) do
|
104
|
-
subject.redis.hset('environments:ENV234', 'user', 'Alicia')
|
108
|
+
subject.redis.hset('environments:my_project:ENV234', 'user', 'Alicia')
|
105
109
|
end
|
106
110
|
|
107
111
|
it "should mark environment as available" do
|
108
112
|
alicia = Lita::User.create(123, name: "Alicia")
|
109
113
|
send_command('release ENV234', :as => alicia)
|
110
|
-
expect(subject.redis.hget('environments:ENV234', 'user')).to be_empty
|
114
|
+
expect(subject.redis.hget('environments:my_project:ENV234', 'user')).to be_empty
|
111
115
|
end
|
112
116
|
|
113
117
|
it "should reply with confirmation" do
|
@@ -121,13 +125,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
121
125
|
context "when environment is in use by another user" do
|
122
126
|
|
123
127
|
before(:each) do
|
124
|
-
subject.redis.hset('environments:ENV234', 'user', 'Carl')
|
128
|
+
subject.redis.hset('environments:my_project:ENV234', 'user', 'Carl')
|
125
129
|
end
|
126
130
|
|
127
131
|
it "should leave the environment untouched" do
|
128
132
|
alicia = Lita::User.create(123, name: "Alicia")
|
129
133
|
send_command('release ENV234', :as => alicia)
|
130
|
-
expect(subject.redis.hget('environments:ENV234', 'user')).to eq('Carl')
|
134
|
+
expect(subject.redis.hget('environments:my_project:ENV234', 'user')).to eq('Carl')
|
131
135
|
end
|
132
136
|
|
133
137
|
it "should reply with notification" do
|
@@ -141,13 +145,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
141
145
|
context "when environment is not in use" do
|
142
146
|
|
143
147
|
before(:each) do
|
144
|
-
subject.redis.hset('environments:ENV234', 'user', '')
|
148
|
+
subject.redis.hset('environments:my_project:ENV234', 'user', '')
|
145
149
|
end
|
146
150
|
|
147
151
|
it "should leave the environment untouched" do
|
148
152
|
alicia = Lita::User.create(123, name: "Alicia")
|
149
153
|
send_command('release ENV234', :as => alicia)
|
150
|
-
expect(subject.redis.hget('environments:ENV234', 'user')).to eq('')
|
154
|
+
expect(subject.redis.hget('environments:my_project:ENV234', 'user')).to eq('')
|
151
155
|
end
|
152
156
|
|
153
157
|
it "should reply with notification" do
|
@@ -161,13 +165,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
161
165
|
context "when environment is unknown to bot" do
|
162
166
|
|
163
167
|
before(:each) do
|
164
|
-
subject.redis.del('environments:ENV234')
|
168
|
+
subject.redis.del('environments:my_project:ENV234')
|
165
169
|
end
|
166
170
|
|
167
171
|
it "should leave the environment untouched" do
|
168
172
|
alicia = Lita::User.create(123, name: "Alicia")
|
169
173
|
send_command('release ENV234', :as => alicia)
|
170
|
-
expect(subject.redis.hget('environments:ENV234', 'user')).to be_nil
|
174
|
+
expect(subject.redis.hget('environments:my_project:ENV234', 'user')).to be_nil
|
171
175
|
end
|
172
176
|
|
173
177
|
it "should reply with notification" do
|
@@ -183,9 +187,9 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
183
187
|
describe 'User listing environments' do
|
184
188
|
|
185
189
|
it "should list environments" do
|
186
|
-
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
187
|
-
subject.redis.hset('environments:ENV234', 'user', 'Carl')
|
188
|
-
subject.redis.hset('environments:ENV345', 'user', '')
|
190
|
+
subject.redis.hset('environments:my_project:ENV123', 'user', 'Alicia')
|
191
|
+
subject.redis.hset('environments:my_project:ENV234', 'user', 'Carl')
|
192
|
+
subject.redis.hset('environments:my_project:ENV345', 'user', '')
|
189
193
|
send_command('envs')
|
190
194
|
expect(replies.first.split("\n")).to eq([
|
191
195
|
"ENV123 (Alicia)",
|
@@ -201,12 +205,12 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
201
205
|
context "when environment is available" do
|
202
206
|
|
203
207
|
before(:each) do
|
204
|
-
subject.redis.hset('environments:ENV345', 'user', '')
|
208
|
+
subject.redis.hset('environments:my_project:ENV345', 'user', '')
|
205
209
|
end
|
206
210
|
|
207
211
|
it "should forgetironments" do
|
208
212
|
send_command('forget ENV345')
|
209
|
-
expect(subject.redis.keys).to_not include('environments:ENV345')
|
213
|
+
expect(subject.redis.keys).to_not include('environments:my_project:ENV345')
|
210
214
|
end
|
211
215
|
|
212
216
|
it "should confirm" do
|
@@ -219,7 +223,7 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
219
223
|
context "when environment is unknown to bot" do
|
220
224
|
|
221
225
|
before(:each) do
|
222
|
-
subject.redis.del('environments:ENV345')
|
226
|
+
subject.redis.del('environments:my_project:ENV345')
|
223
227
|
end
|
224
228
|
|
225
229
|
it "should reply with notification" do
|
@@ -232,13 +236,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
232
236
|
context "when environment is in use by another user" do
|
233
237
|
|
234
238
|
before(:each) do
|
235
|
-
subject.redis.hset('environments:ENV345', 'user', 'Carl')
|
239
|
+
subject.redis.hset('environments:my_project:ENV345', 'user', 'Carl')
|
236
240
|
end
|
237
241
|
|
238
242
|
it "should leave the environment untouched" do
|
239
243
|
alicia = Lita::User.create(123, name: "Alicia")
|
240
244
|
send_command('forget ENV345', :as => alicia)
|
241
|
-
expect(subject.redis.hget('environments:ENV345', 'user')).to eq('Carl')
|
245
|
+
expect(subject.redis.hget('environments:my_project:ENV345', 'user')).to eq('Carl')
|
242
246
|
end
|
243
247
|
|
244
248
|
it "should reply with notification" do
|
@@ -251,13 +255,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
251
255
|
context "when environment is in use by user" do
|
252
256
|
|
253
257
|
before(:each) do
|
254
|
-
subject.redis.hset('environments:ENV345', 'user', 'Alicia')
|
258
|
+
subject.redis.hset('environments:my_project:ENV345', 'user', 'Alicia')
|
255
259
|
end
|
256
260
|
|
257
261
|
it "should leave the environment untouched" do
|
258
262
|
alicia = Lita::User.create(123, name: "Alicia")
|
259
263
|
send_command('forget ENV345', :as => alicia)
|
260
|
-
expect(subject.redis.hget('environments:ENV345', 'user')).to eq('Alicia')
|
264
|
+
expect(subject.redis.hget('environments:my_project:ENV345', 'user')).to eq('Alicia')
|
261
265
|
end
|
262
266
|
|
263
267
|
it "should reply with notification" do
|
@@ -275,13 +279,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
275
279
|
context "when environment is currently in use by specified user" do
|
276
280
|
|
277
281
|
before(:each) do
|
278
|
-
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
282
|
+
subject.redis.hset('environments:my_project:ENV123', 'user', 'Alicia')
|
279
283
|
end
|
280
284
|
|
281
285
|
it "should mark environment as in use" do
|
282
286
|
carl = Lita::User.create(123, name: "Carl")
|
283
287
|
send_command('wrestle ENV123 from Alicia', :as => carl)
|
284
|
-
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
|
288
|
+
expect(subject.redis.hget('environments:my_project:ENV123', 'user')).to eq("Carl")
|
285
289
|
end
|
286
290
|
|
287
291
|
it "should reply with confirmation" do
|
@@ -294,13 +298,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
294
298
|
context "when environment is currently in use by a user other than the specified one" do
|
295
299
|
|
296
300
|
before(:each) do
|
297
|
-
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
301
|
+
subject.redis.hset('environments:my_project:ENV123', 'user', 'Alicia')
|
298
302
|
end
|
299
303
|
|
300
304
|
it "should leave the environment untouched" do
|
301
305
|
carl = Lita::User.create(123, name: "Carl")
|
302
306
|
send_command('wrestle ENV123 from Ben', :as => carl)
|
303
|
-
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Alicia")
|
307
|
+
expect(subject.redis.hget('environments:my_project:ENV123', 'user')).to eq("Alicia")
|
304
308
|
end
|
305
309
|
|
306
310
|
it "should reply with notification" do
|
@@ -313,13 +317,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
313
317
|
context "when environment is not currently in use" do
|
314
318
|
|
315
319
|
before(:each) do
|
316
|
-
subject.redis.hset('environments:ENV123', 'user', nil)
|
320
|
+
subject.redis.hset('environments:my_project:ENV123', 'user', nil)
|
317
321
|
end
|
318
322
|
|
319
323
|
it "should leave the environment untouched" do
|
320
324
|
carl = Lita::User.create(123, name: "Carl")
|
321
325
|
send_command('wrestle ENV123 from Ben', :as => carl)
|
322
|
-
expect(subject.redis.hget('environments:ENV123', 'user')).to be_empty
|
326
|
+
expect(subject.redis.hget('environments:my_project:ENV123', 'user')).to be_empty
|
323
327
|
end
|
324
328
|
|
325
329
|
it "should reply with notification" do
|
@@ -332,13 +336,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
332
336
|
context "when environment is already marked as in use by requesting user" do
|
333
337
|
|
334
338
|
before(:each) do
|
335
|
-
subject.redis.hset('environments:ENV123', 'user', 'Carl')
|
339
|
+
subject.redis.hset('environments:my_project:ENV123', 'user', 'Carl')
|
336
340
|
end
|
337
341
|
|
338
342
|
it "should leave the environment untouched" do
|
339
343
|
carl = Lita::User.create(123, name: "Carl")
|
340
344
|
send_command('wrestle ENV123 from Ben', :as => carl)
|
341
|
-
expect(subject.redis.hget('environments:ENV123', 'user')).to eq('Carl')
|
345
|
+
expect(subject.redis.hget('environments:my_project:ENV123', 'user')).to eq('Carl')
|
342
346
|
end
|
343
347
|
|
344
348
|
it "should reply with notification" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-envy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ingo Weiss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -136,9 +136,10 @@ dependencies:
|
|
136
136
|
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
description:
|
139
|
+
description: Helps with management of environment ussage. Adds commands for claiming
|
140
|
+
and releasing environments
|
140
141
|
email:
|
141
|
-
- ingo
|
142
|
+
- ingo@ingoweiss.com
|
142
143
|
executables: []
|
143
144
|
extensions: []
|
144
145
|
extra_rdoc_files: []
|