lita-pagerduty 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -5
- data/.travis.yml +1 -1
- data/CONTRIBUTING.md +9 -0
- data/LICENSE +1 -1
- data/README.md +19 -16
- data/Rakefile +5 -3
- data/lib/lita/handlers/pagerduty_ack.rb +73 -0
- data/lib/lita/handlers/pagerduty_incident.rb +68 -0
- data/lib/lita/handlers/pagerduty_note.rb +48 -0
- data/lib/lita/handlers/pagerduty_resolve.rb +73 -0
- data/lib/lita/handlers/pagerduty_utility.rb +108 -0
- data/lib/lita-pagerduty.rb +17 -1
- data/lib/pagerduty_helper/incident.rb +61 -0
- data/lib/pagerduty_helper/regex.rb +8 -0
- data/lib/pagerduty_helper/utility.rb +29 -0
- data/lita-pagerduty.gemspec +21 -20
- data/locales/en.yml +80 -0
- data/spec/lita/handlers/pagerduty_ack_spec.rb +95 -0
- data/spec/lita/handlers/pagerduty_incident_spec.rb +82 -0
- data/spec/lita/handlers/pagerduty_note_spec.rb +43 -0
- data/spec/lita/handlers/pagerduty_resolve_spec.rb +95 -0
- data/spec/lita/handlers/pagerduty_utility_spec.rb +58 -0
- data/spec/spec_helper.rb +149 -0
- metadata +43 -13
- data/lib/lita/handlers/pagerduty.rb +0 -401
- data/spec/lita/handlers/pagerduty_spec.rb +0 -457
@@ -1,457 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'pagerduty'
|
3
|
-
|
4
|
-
describe Lita::Handlers::Pagerduty, lita_handler: true do
|
5
|
-
let(:no_incident) do
|
6
|
-
client = double
|
7
|
-
expect(client).to receive(:get_incident) { 'No results' }
|
8
|
-
client
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:no_incidents) do
|
12
|
-
client = double
|
13
|
-
expect(client).to receive(:incidents) do
|
14
|
-
double(
|
15
|
-
incidents: []
|
16
|
-
)
|
17
|
-
end
|
18
|
-
client
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:incidents) do
|
22
|
-
client = double
|
23
|
-
expect(client).to receive(:incidents) do
|
24
|
-
double(
|
25
|
-
incidents: [
|
26
|
-
double(
|
27
|
-
id: 'ABC123',
|
28
|
-
status: 'resolved',
|
29
|
-
trigger_summary_data: double(subject: 'something broke'),
|
30
|
-
assigned_to_user: double(email: 'foo@example.com')
|
31
|
-
),
|
32
|
-
double(
|
33
|
-
id: 'ABC789',
|
34
|
-
status: 'triggered',
|
35
|
-
trigger_summary_data: double(subject: 'Still broke'),
|
36
|
-
assigned_to_user: double(email: 'bar@example.com')
|
37
|
-
)
|
38
|
-
]
|
39
|
-
)
|
40
|
-
end
|
41
|
-
allow(client).to receive(:get_incident) do
|
42
|
-
double(
|
43
|
-
status: 'triggered',
|
44
|
-
trigger_summary_data: double(subject: 'Still broke'),
|
45
|
-
assigned_to_user: double(email: 'bar@example.com'),
|
46
|
-
acknowledge: { 'id' => 'ABC789', 'status' => 'acknowledged' },
|
47
|
-
resolve: { 'id' => 'ABC789', 'status' => 'resolved' },
|
48
|
-
notes: double(notes: [])
|
49
|
-
)
|
50
|
-
end
|
51
|
-
client
|
52
|
-
end
|
53
|
-
|
54
|
-
let(:new_incident) do
|
55
|
-
client = double
|
56
|
-
expect(client).to receive(:get_incident) do
|
57
|
-
double(
|
58
|
-
status: 'triggered',
|
59
|
-
trigger_summary_data: double(subject: 'something broke'),
|
60
|
-
assigned_to_user: double(email: 'foo@example.com'),
|
61
|
-
acknowledge: { 'id' => 'ABC123', 'status' => 'acknowledged' },
|
62
|
-
resolve: { 'id' => 'ABC123', 'status' => 'resolved' },
|
63
|
-
notes: double(notes: [])
|
64
|
-
)
|
65
|
-
end
|
66
|
-
client
|
67
|
-
end
|
68
|
-
|
69
|
-
let(:acknowledged_incident) do
|
70
|
-
client = double
|
71
|
-
expect(client).to receive(:get_incident) do
|
72
|
-
double(
|
73
|
-
status: 'acknowledged',
|
74
|
-
trigger_summary_data: double(subject: 'something broke'),
|
75
|
-
assigned_to_user: double(email: 'foo@example.com'),
|
76
|
-
acknowledge: { 'error' =>
|
77
|
-
{ 'message' => 'Incident Already Acknowledged', 'code' => 1002 }
|
78
|
-
},
|
79
|
-
resolve: { 'id' => 'ABC123', 'status' => 'resolved' },
|
80
|
-
notes: double(notes: [])
|
81
|
-
)
|
82
|
-
end
|
83
|
-
client
|
84
|
-
end
|
85
|
-
|
86
|
-
let(:resolved_incident) do
|
87
|
-
client = double
|
88
|
-
expect(client).to receive(:get_incident) do
|
89
|
-
double(
|
90
|
-
status: 'resolved',
|
91
|
-
trigger_summary_data: double(subject: 'something broke'),
|
92
|
-
assigned_to_user: double(email: 'foo@example.com'),
|
93
|
-
notes: double(notes: [])
|
94
|
-
)
|
95
|
-
end
|
96
|
-
client
|
97
|
-
end
|
98
|
-
|
99
|
-
let(:incident_with_notes) do
|
100
|
-
client = double
|
101
|
-
expect(client).to receive(:get_incident) do
|
102
|
-
double(
|
103
|
-
status: 'resolved',
|
104
|
-
trigger_summary_data: double(subject: 'something broke'),
|
105
|
-
assigned_to_user: double(email: 'foo@example.com'),
|
106
|
-
notes: double(
|
107
|
-
notes: [double(content: 'Hi!',
|
108
|
-
user: double(email: 'foo@example.com'))]
|
109
|
-
)
|
110
|
-
)
|
111
|
-
end
|
112
|
-
client
|
113
|
-
end
|
114
|
-
|
115
|
-
it { routes_command('who\'s on call').to(:whos_on_call) }
|
116
|
-
it { routes_command('who\'s on call?').to(:whos_on_call) }
|
117
|
-
it { routes_command('pager identify foobar@example.com').to(:identify) }
|
118
|
-
it { routes_command('pager forget').to(:forget) }
|
119
|
-
it { routes_command('pager incidents all').to(:incidents_all) }
|
120
|
-
it { routes_command('pager incidents mine').to(:incidents_mine) }
|
121
|
-
it { routes_command('pager incident ABC123').to(:incident) }
|
122
|
-
it { routes_command('pager notes ABC123').to(:notes) }
|
123
|
-
it { routes_command('pager note ABC123 some text').to(:note) }
|
124
|
-
it { routes_command('pager ack all').to(:ack_all) }
|
125
|
-
it { routes_command('pager ack mine').to(:ack_mine) }
|
126
|
-
it { routes_command('pager ack ABC123').to(:ack) }
|
127
|
-
it { routes_command('pager resolve all').to(:resolve_all) }
|
128
|
-
it { routes_command('pager resolve mine').to(:resolve_mine) }
|
129
|
-
it { routes_command('pager resolve ABC123').to(:resolve) }
|
130
|
-
|
131
|
-
describe '.default_config' do
|
132
|
-
it 'sets api_key to nil' do
|
133
|
-
expect(Lita.config.handlers.pagerduty.api_key).to be_nil
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'sets subdomain to nil' do
|
137
|
-
expect(Lita.config.handlers.pagerduty.subdomain).to be_nil
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe 'without valid config' do
|
142
|
-
it 'should error out on any command' do
|
143
|
-
expect { send_command('pager ack ABC123') }.to raise_error('Bad config')
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe 'with valid config' do
|
148
|
-
before do
|
149
|
-
Lita.config.handlers.pagerduty.api_key = 'foo'
|
150
|
-
Lita.config.handlers.pagerduty.subdomain = 'bar'
|
151
|
-
end
|
152
|
-
|
153
|
-
describe '#whos_on_call' do
|
154
|
-
it 'shows a warning' do
|
155
|
-
send_command("who's on call?")
|
156
|
-
expect(replies.last).to eq('Not implemented yet.')
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe '#identify' do
|
161
|
-
describe 'when that email is new' do
|
162
|
-
it 'shows a successful identification' do
|
163
|
-
foo = Lita::User.create(123, name: 'foo')
|
164
|
-
send_command('pager identify foo@example.com', as: foo)
|
165
|
-
expect(replies.last).to eq('You have now been identified.')
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# TODO: It'd be great to validate this against the existing
|
170
|
-
# users on the PD account.
|
171
|
-
|
172
|
-
describe 'when that email exists already' do
|
173
|
-
it 'shows a warning' do
|
174
|
-
baz = Lita::User.create(321, name: 'baz')
|
175
|
-
send_command('pager identify baz@example.com', as: baz)
|
176
|
-
send_command('pager identify baz@example.com', as: baz)
|
177
|
-
expect(replies.last).to eq('You have already been identified!')
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe '#forget' do
|
183
|
-
describe 'when that user is associated' do
|
184
|
-
it 'shows a successful forget' do
|
185
|
-
foo = Lita::User.create(123, name: 'foo')
|
186
|
-
send_command('pager identify foo@example.com', as: foo)
|
187
|
-
send_command('pager forget', as: foo)
|
188
|
-
expect(replies.last).to eq('Your email has now been forgotten.')
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
describe 'when that user is not associated' do
|
193
|
-
it 'shows a warning' do
|
194
|
-
foo = Lita::User.create(123, name: 'foo')
|
195
|
-
send_command('pager forget', as: foo)
|
196
|
-
expect(replies.last).to eq('No email on record for you.')
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
describe '#incidents_all' do
|
202
|
-
describe 'when there are open incidents' do
|
203
|
-
it 'shows a list of incidents' do
|
204
|
-
expect(Pagerduty).to receive(:new) { incidents }
|
205
|
-
send_command('pager incidents all')
|
206
|
-
expect(replies.last).to eq('ABC789: "Still broke", assigned to: '\
|
207
|
-
'bar@example.com')
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
describe 'when there are no open incidents' do
|
212
|
-
it 'shows a warning' do
|
213
|
-
expect(Pagerduty).to receive(:new) { no_incidents }
|
214
|
-
send_command('pager incidents all')
|
215
|
-
expect(replies.last).to eq('No triggered, open, or acknowledged ' \
|
216
|
-
'incidents')
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
describe '#incidents_mine' do
|
222
|
-
describe 'when there are open incidents for the user' do
|
223
|
-
it 'shows a list of incidents' do
|
224
|
-
bar = Lita::User.create(123, name: 'bar')
|
225
|
-
expect(Pagerduty).to receive(:new) { incidents }
|
226
|
-
send_command('pager identify bar@example.com', as: bar)
|
227
|
-
send_command('pager incidents mine', as: bar)
|
228
|
-
expect(replies.last).to eq('ABC789: "Still broke", assigned to: ' \
|
229
|
-
'bar@example.com')
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
describe 'when there are no open incidents for the user' do
|
234
|
-
it 'shows no incidents' do
|
235
|
-
foo = Lita::User.create(123, name: 'foo')
|
236
|
-
expect(Pagerduty).to receive(:new) { incidents }
|
237
|
-
send_command('pager identify foo@example.com', as: foo)
|
238
|
-
send_command('pager incidents mine', as: foo)
|
239
|
-
expect(replies.last).to eq('You have no triggered, open, or ' \
|
240
|
-
'acknowledged incidents')
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
describe 'when the user has not identified themselves' do
|
245
|
-
it 'shows a warning' do
|
246
|
-
send_command('pager incidents mine')
|
247
|
-
expect(replies.last).to eq('You have not identified yourself (use ' \
|
248
|
-
'the help command for more info)')
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
describe '#incident' do
|
254
|
-
describe 'when the incident exists' do
|
255
|
-
it 'shows incident details' do
|
256
|
-
expect(Pagerduty).to receive(:new) { new_incident }
|
257
|
-
send_command('pager incident ABC123')
|
258
|
-
expect(replies.last).to eq('ABC123: "something broke", ' \
|
259
|
-
'assigned to: foo@example.com')
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
describe 'when the incident does not exist' do
|
264
|
-
it 'shows an error' do
|
265
|
-
expect(Pagerduty).to receive(:new) { no_incident }
|
266
|
-
send_command('pager incident ABC123')
|
267
|
-
expect(replies.last).to eq('ABC123: Incident not found')
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
describe '#notes' do
|
273
|
-
describe 'when the incident has notes' do
|
274
|
-
it 'shows incident notes' do
|
275
|
-
expect(Pagerduty).to receive(:new) { incident_with_notes }
|
276
|
-
send_command('pager notes ABC123')
|
277
|
-
expect(replies.last).to eq('ABC123: Hi! (foo@example.com)')
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
describe 'when the incident doesnt have notes' do
|
282
|
-
it 'shows no notes' do
|
283
|
-
expect(Pagerduty).to receive(:new) { new_incident }
|
284
|
-
send_command('pager notes ABC123')
|
285
|
-
expect(replies.last).to eq('ABC123: No notes')
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
describe 'when the incident does not exist' do
|
290
|
-
it 'shows an error' do
|
291
|
-
expect(Pagerduty).to receive(:new) { no_incident }
|
292
|
-
send_command('pager notes ABC123')
|
293
|
-
expect(replies.last).to eq('ABC123: Incident not found')
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
describe '#note' do
|
299
|
-
it 'shows a warning' do
|
300
|
-
send_command('pager note ABC123 some text')
|
301
|
-
expect(replies.last).to eq('Not implemented yet.')
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
describe '#ack_all' do
|
306
|
-
describe 'when there are acknowledgable incidents' do
|
307
|
-
it 'shows them as acknowledged' do
|
308
|
-
expect(Pagerduty).to receive(:new).twice { incidents }
|
309
|
-
send_command('pager ack all')
|
310
|
-
expect(replies.last).to eq('Acknowledged: ABC789')
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
describe 'when there are no acknowledgable incidents' do
|
315
|
-
it 'shows a warning' do
|
316
|
-
expect(Pagerduty).to receive(:new) { no_incidents }
|
317
|
-
send_command('pager ack all')
|
318
|
-
expect(replies.last).to eq('No triggered, open, or acknowledged ' \
|
319
|
-
'incidents')
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
describe '#ack_mine' do
|
325
|
-
describe 'when there are acknowledgable incidents for the user' do
|
326
|
-
it 'shows them as acknowledged' do
|
327
|
-
bar = Lita::User.create(123, name: 'bar')
|
328
|
-
expect(Pagerduty).to receive(:new).twice { incidents }
|
329
|
-
send_command('pager identify bar@example.com', as: bar)
|
330
|
-
send_command('pager ack mine', as: bar)
|
331
|
-
expect(replies.last).to eq('Acknowledged: ABC789')
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
describe 'when there are no acknowledgable incidents for the user' do
|
336
|
-
it 'shows a warning' do
|
337
|
-
foo = Lita::User.create(123, name: 'foo')
|
338
|
-
expect(Pagerduty).to receive(:new) { incidents }
|
339
|
-
send_command('pager identify foo@example.com', as: foo)
|
340
|
-
send_command('pager ack mine', as: foo)
|
341
|
-
expect(replies.last).to eq('You have no triggered, open, or ' \
|
342
|
-
'acknowledged incidents')
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
describe 'when the user has not identified themselves' do
|
347
|
-
it 'shows a warning' do
|
348
|
-
send_command('pager ack mine')
|
349
|
-
expect(replies.last).to eq('You have not identified yourself (use ' \
|
350
|
-
'the help command for more info)')
|
351
|
-
end
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
describe '#ack' do
|
356
|
-
describe 'when the incident has not been acknowledged' do
|
357
|
-
it 'shows the acknowledgement' do
|
358
|
-
expect(Pagerduty).to receive(:new) { new_incident }
|
359
|
-
send_command('pager ack ABC123')
|
360
|
-
expect(replies.last).to eq('ABC123: Incident acknowledged')
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
describe 'when the incident has already been acknowledged' do
|
365
|
-
it 'shows the warning' do
|
366
|
-
expect(Pagerduty).to receive(:new) { acknowledged_incident }
|
367
|
-
send_command('pager ack ABC123')
|
368
|
-
expect(replies.last).to eq('ABC123: Incident already acknowledged')
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
describe 'when the incident does not exist' do
|
373
|
-
it 'shows an error' do
|
374
|
-
expect(Pagerduty).to receive(:new) { no_incident }
|
375
|
-
send_command('pager ack ABC123')
|
376
|
-
expect(replies.last).to eq('ABC123: Incident not found')
|
377
|
-
end
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
describe '#resolve_all' do
|
382
|
-
describe 'when there are resolvable incidents' do
|
383
|
-
it 'shows them as resolved' do
|
384
|
-
expect(Pagerduty).to receive(:new).twice { incidents }
|
385
|
-
send_command('pager resolve all')
|
386
|
-
expect(replies.last).to eq('Resolved: ABC789')
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
describe 'when there are no resolvable incidents' do
|
391
|
-
it 'shows a warning' do
|
392
|
-
expect(Pagerduty).to receive(:new) { no_incidents }
|
393
|
-
send_command('pager resolve all')
|
394
|
-
expect(replies.last).to eq('No triggered, open, or acknowledged ' \
|
395
|
-
'incidents')
|
396
|
-
end
|
397
|
-
end
|
398
|
-
end
|
399
|
-
|
400
|
-
describe '#resolve_mine' do
|
401
|
-
describe 'when there are resolvable incidents for the user' do
|
402
|
-
it 'shows them as acknowledged' do
|
403
|
-
bar = Lita::User.create(123, name: 'bar')
|
404
|
-
expect(Pagerduty).to receive(:new).twice { incidents }
|
405
|
-
send_command('pager identify bar@example.com', as: bar)
|
406
|
-
send_command('pager resolve mine', as: bar)
|
407
|
-
expect(replies.last).to eq('Resolved: ABC789')
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
describe 'when there are no resolvable incidents for the user' do
|
412
|
-
it 'shows a warning' do
|
413
|
-
foo = Lita::User.create(123, name: 'foo')
|
414
|
-
expect(Pagerduty).to receive(:new) { incidents }
|
415
|
-
send_command('pager identify foo@example.com', as: foo)
|
416
|
-
send_command('pager resolve mine', as: foo)
|
417
|
-
expect(replies.last).to eq('You have no triggered, open, or ' \
|
418
|
-
'acknowledged incidents')
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
describe 'when the user has not identified themselves' do
|
423
|
-
it 'shows a warning' do
|
424
|
-
send_command('pager resolve mine')
|
425
|
-
expect(replies.last).to eq('You have not identified yourself (use ' \
|
426
|
-
'the help command for more info)')
|
427
|
-
end
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|
431
|
-
describe '#resolve' do
|
432
|
-
describe 'when the incident has not been resolved' do
|
433
|
-
it 'shows the resolve' do
|
434
|
-
expect(Pagerduty).to receive(:new) { new_incident }
|
435
|
-
send_command('pager resolve ABC123')
|
436
|
-
expect(replies.last).to eq('ABC123: Incident resolved')
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
describe 'when the incident has already been resolved' do
|
441
|
-
it 'shows the warning' do
|
442
|
-
expect(Pagerduty).to receive(:new) { resolved_incident }
|
443
|
-
send_command('pager resolve ABC123')
|
444
|
-
expect(replies.last).to eq('ABC123: Incident already resolved')
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
describe 'when the incident does not exist' do
|
449
|
-
it 'shows an error' do
|
450
|
-
expect(Pagerduty).to receive(:new) { no_incident }
|
451
|
-
send_command('pager resolve ABC123')
|
452
|
-
expect(replies.last).to eq('ABC123: Incident not found')
|
453
|
-
end
|
454
|
-
end
|
455
|
-
end
|
456
|
-
end
|
457
|
-
end
|