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.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-pagerduty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Sigler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-23 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pagerduty-sdk
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -72,16 +86,16 @@ dependencies:
72
86
  requirements:
73
87
  - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: 3.0.0.beta2
89
+ version: '3.0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: 3.0.0.beta2
96
+ version: '3.0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: simplecov
98
+ name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: coveralls
112
+ name: simplecov
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -110,7 +124,7 @@ dependencies:
110
124
  version: '0'
111
125
  description: A Lita handler to interact with PagerDuty
112
126
  email:
113
- - me@esigler.com
127
+ - eric@pagerduty.com
114
128
  executables: []
115
129
  extensions: []
116
130
  extra_rdoc_files: []
@@ -118,15 +132,27 @@ files:
118
132
  - ".gitignore"
119
133
  - ".rubocop.yml"
120
134
  - ".travis.yml"
135
+ - CONTRIBUTING.md
121
136
  - Gemfile
122
137
  - LICENSE
123
138
  - README.md
124
139
  - Rakefile
125
140
  - lib/lita-pagerduty.rb
126
- - lib/lita/handlers/pagerduty.rb
141
+ - lib/lita/handlers/pagerduty_ack.rb
142
+ - lib/lita/handlers/pagerduty_incident.rb
143
+ - lib/lita/handlers/pagerduty_note.rb
144
+ - lib/lita/handlers/pagerduty_resolve.rb
145
+ - lib/lita/handlers/pagerduty_utility.rb
146
+ - lib/pagerduty_helper/incident.rb
147
+ - lib/pagerduty_helper/regex.rb
148
+ - lib/pagerduty_helper/utility.rb
127
149
  - lita-pagerduty.gemspec
128
150
  - locales/en.yml
129
- - spec/lita/handlers/pagerduty_spec.rb
151
+ - spec/lita/handlers/pagerduty_ack_spec.rb
152
+ - spec/lita/handlers/pagerduty_incident_spec.rb
153
+ - spec/lita/handlers/pagerduty_note_spec.rb
154
+ - spec/lita/handlers/pagerduty_resolve_spec.rb
155
+ - spec/lita/handlers/pagerduty_utility_spec.rb
130
156
  - spec/spec_helper.rb
131
157
  homepage: http://github.com/esigler/lita-pagerduty
132
158
  licenses:
@@ -149,10 +175,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
175
  version: '0'
150
176
  requirements: []
151
177
  rubyforge_project:
152
- rubygems_version: 2.2.1
178
+ rubygems_version: 2.2.3
153
179
  signing_key:
154
180
  specification_version: 4
155
181
  summary: A Lita handler to interact with PagerDuty
156
182
  test_files:
157
- - spec/lita/handlers/pagerduty_spec.rb
183
+ - spec/lita/handlers/pagerduty_ack_spec.rb
184
+ - spec/lita/handlers/pagerduty_incident_spec.rb
185
+ - spec/lita/handlers/pagerduty_note_spec.rb
186
+ - spec/lita/handlers/pagerduty_resolve_spec.rb
187
+ - spec/lita/handlers/pagerduty_utility_spec.rb
158
188
  - spec/spec_helper.rb
@@ -1,401 +0,0 @@
1
- require 'lita'
2
- require 'pagerduty'
3
-
4
- module Lita
5
- module Handlers
6
- class Pagerduty < Handler
7
- route(
8
- /^who\'s\son\scall\?*$/,
9
- :whos_on_call,
10
- command: true,
11
- help: {
12
- 'who\'s on call?' =>
13
- 'Show everyone currently on call (not implemented yet)'
14
- }
15
- )
16
-
17
- route(
18
- /^pager\sincidents\sall$/,
19
- :incidents_all,
20
- command: true,
21
- help: {
22
- 'pager incidents all' => 'Show all open incidents'
23
- }
24
- )
25
-
26
- route(
27
- /^pager\sincidents\smine$/,
28
- :incidents_mine,
29
- command: true,
30
- help: {
31
- 'pager incidents mine' => 'Show all open incidents assigned to me'
32
- }
33
- )
34
-
35
- route(
36
- /^pager\sincident\s(\w+)$/,
37
- :incident,
38
- command: true,
39
- help: {
40
- 'pager incident 1234' => 'Show a specific incident'
41
- }
42
- )
43
-
44
- route(
45
- /^pager\snotes\s(\w+)$/,
46
- :notes,
47
- command: true,
48
- help: {
49
- 'pager notes 1234' => 'Show all notes for a specific incident'
50
- }
51
- )
52
-
53
- route(
54
- /^pager\snote\s(\w+)\s(.+)$/,
55
- :note,
56
- command: true,
57
- help: {
58
- 'pager note 1234 some text' =>
59
- 'Add a note to a specific incident (not implemented yet)'
60
- }
61
- )
62
-
63
- route(
64
- /^pager\sack\sall$/,
65
- :ack_all,
66
- command: true,
67
- help: {
68
- 'pager ack all' => 'Acknowledge all triggered incidents'
69
- }
70
- )
71
-
72
- route(
73
- /^pager\sack\smine$/,
74
- :ack_mine,
75
- command: true,
76
- help: {
77
- 'pager ack mine' =>
78
- 'Acknowledge all triggered incidents assigned to me'
79
- }
80
- )
81
-
82
- route(
83
- /^pager\sack\s(\w+)$/,
84
- :ack,
85
- command: true,
86
- help: {
87
- 'pager ack 1234' => 'Acknowledge a specific incident'
88
- }
89
- )
90
-
91
- route(
92
- /^pager\sresolve\sall$/,
93
- :resolve_all,
94
- command: true,
95
- help: {
96
- 'pager resolve all' => 'Resolve all triggered incidents'
97
- }
98
- )
99
-
100
- route(
101
- /^pager\sresolve\smine$/,
102
- :resolve_mine,
103
- command: true,
104
- help: {
105
- 'pager resolve mine' =>
106
- 'Resolve all triggered incidents assigned to me'
107
- }
108
- )
109
-
110
- route(
111
- /^pager\sresolve\s(\w+)$/,
112
- :resolve,
113
- command: true,
114
- help: {
115
- 'pager resolve 1234' => 'Resolve a specific incident'
116
- }
117
- )
118
-
119
- route(
120
- /^pager\sidentify\s(.+)$/,
121
- :identify,
122
- command: true,
123
- help: {
124
- 'pager identify <email address>' =>
125
- 'Associate your chat user with your email address'
126
- }
127
- )
128
-
129
- route(
130
- /^pager\sforget$/,
131
- :forget,
132
- command: true,
133
- help: {
134
- 'pager forget' => 'Remove your chat user / email association'
135
- }
136
- )
137
-
138
- def self.default_config(config)
139
- config.api_key = nil
140
- config.subdomain = nil
141
- end
142
-
143
- def whos_on_call(response)
144
- response.reply('Not implemented yet.')
145
- end
146
-
147
- def identify(response)
148
- email = response.matches[0][0]
149
- stored_email = redis.get("email_#{response.user.id}")
150
- if !stored_email
151
- redis.set("email_#{response.user.id}", email)
152
- response.reply('You have now been identified.')
153
- else
154
- response.reply('You have already been identified!')
155
- end
156
- end
157
-
158
- def forget(response)
159
- stored_email = redis.get("email_#{response.user.id}")
160
- if stored_email
161
- redis.del("email_#{response.user.id}")
162
- response.reply('Your email has now been forgotten.')
163
- else
164
- response.reply('No email on record for you.')
165
- end
166
- end
167
-
168
- def incidents_all(response)
169
- incidents = fetch_all_incidents
170
- if incidents.count > 0
171
- incidents.each do |incident|
172
- response.reply("#{incident.id}: " \
173
- "\"#{incident.trigger_summary_data.subject}\", " \
174
- "assigned to: #{incident.assigned_to_user.email}")
175
- end
176
- else
177
- response.reply('No triggered, open, or acknowledged incidents')
178
- end
179
- end
180
-
181
- def incidents_mine(response)
182
- email = redis.get("email_#{response.user.id}")
183
- if email
184
- incidents = fetch_my_incidents(email)
185
- if incidents.count > 0
186
- incidents.each do |incident|
187
- response.reply("#{incident.id}: " \
188
- "\"#{incident.trigger_summary_data.subject}\", " \
189
- "assigned to: #{incident.assigned_to_user.email}")
190
- end
191
- else
192
- response.reply('You have no triggered, open, or acknowledged ' \
193
- 'incidents')
194
- end
195
- else
196
- response.reply('You have not identified yourself (use the help ' \
197
- 'command for more info)')
198
- end
199
- end
200
-
201
- def incident(response)
202
- incident_id = response.matches[0][0]
203
- incident = fetch_incident(incident_id)
204
- if incident != 'No results'
205
- response.reply("#{incident_id}: " \
206
- "\"#{incident.trigger_summary_data.subject}\", " \
207
- "assigned to: #{incident.assigned_to_user.email}")
208
- else
209
- response.reply("#{incident_id}: Incident not found")
210
- end
211
- end
212
-
213
- def notes(response)
214
- incident_id = response.matches[0][0]
215
- incident = fetch_incident(incident_id)
216
- if incident != 'No results'
217
- if incident.notes.notes.count > 0
218
- incident.notes.notes.each do |note|
219
- response.reply("#{incident_id}: #{note.content} "\
220
- "(#{note.user.email})")
221
- end
222
- else
223
- response.reply("#{incident_id}: No notes")
224
- end
225
- else
226
- response.reply("#{incident_id}: Incident not found")
227
- end
228
- end
229
-
230
- def note(response)
231
- response.reply('Not implemented yet.')
232
- end
233
-
234
- def ack_all(response)
235
- incidents = fetch_all_incidents
236
- if incidents.count > 0
237
- completed = []
238
- incidents.each do |incident|
239
- result = acknowledge_incident(incident.id)
240
- if result == "#{incident.id}: Incident acknowledged"
241
- completed.push(incident.id)
242
- end
243
- response.reply("Acknowledged: #{completed.join(",")}")
244
- end
245
- else
246
- response.reply('No triggered, open, or acknowledged incidents')
247
- end
248
- end
249
-
250
- def ack_mine(response)
251
- email = redis.get("email_#{response.user.id}")
252
- if email
253
- incidents = fetch_my_incidents(email)
254
- if incidents.count > 0
255
- completed = []
256
- incidents.each do |incident|
257
- result = acknowledge_incident(incident.id)
258
- if result == "#{incident.id}: Incident acknowledged"
259
- completed.push(incident.id)
260
- end
261
- response.reply("Acknowledged: #{completed.join(",")}")
262
- end
263
- else
264
- response.reply('You have no triggered, open, or acknowledged ' \
265
- 'incidents')
266
- end
267
- else
268
- response.reply('You have not identified yourself (use the help ' \
269
- 'command for more info)')
270
- end
271
- end
272
-
273
- def ack(response)
274
- incident_id = response.matches[0][0]
275
- return if incident_id == 'all' || incident_id == 'mine'
276
- response.reply(acknowledge_incident(incident_id))
277
- end
278
-
279
- def resolve_all(response)
280
- incidents = fetch_all_incidents
281
- if incidents.count > 0
282
- completed = []
283
- incidents.each do |incident|
284
- result = resolve_incident(incident.id)
285
- if result == "#{incident.id}: Incident resolved"
286
- completed.push(incident.id)
287
- end
288
- response.reply("Resolved: #{completed.join(",")}")
289
- end
290
- else
291
- response.reply('No triggered, open, or acknowledged incidents')
292
- end
293
- end
294
-
295
- def resolve_mine(response)
296
- email = redis.get("email_#{response.user.id}")
297
- if email
298
- incidents = fetch_my_incidents(email)
299
- if incidents.count > 0
300
- completed = []
301
- incidents.each do |incident|
302
- result = resolve_incident(incident.id)
303
- if result == "#{incident.id}: Incident resolved"
304
- completed.push(incident.id)
305
- end
306
- response.reply("Resolved: #{completed.join(",")}")
307
- end
308
- else
309
- response.reply('You have no triggered, open, or acknowledged ' \
310
- 'incidents')
311
- end
312
- else
313
- response.reply('You have not identified yourself (use the help ' \
314
- 'command for more info)')
315
- end
316
- end
317
-
318
- def resolve(response)
319
- incident_id = response.matches[0][0]
320
- return if incident_id == 'all' || incident_id == 'mine'
321
- response.reply(resolve_incident(incident_id))
322
- end
323
-
324
- private
325
-
326
- def pd_client
327
- if Lita.config.handlers.pagerduty.api_key.nil? ||
328
- Lita.config.handlers.pagerduty.subdomain.nil?
329
- fail 'Bad config'
330
- end
331
-
332
- ::Pagerduty.new(token: Lita.config.handlers.pagerduty.api_key,
333
- subdomain: Lita.config.handlers.pagerduty.subdomain)
334
- end
335
-
336
- def fetch_all_incidents
337
- client = pd_client
338
- list = []
339
- # FIXME: Workaround on current PD Gem
340
- client.incidents.incidents.each do |incident|
341
- list.push(incident) if incident.status != 'resolved'
342
- end
343
- list
344
- end
345
-
346
- def fetch_my_incidents(email)
347
- # FIXME: Workaround
348
- incidents = fetch_all_incidents
349
- list = []
350
- incidents.each do |incident|
351
- list.push(incident) if incident.assigned_to_user.email == email
352
- end
353
- list
354
- end
355
-
356
- def fetch_incident(incident_id)
357
- client = pd_client
358
- client.get_incident(id: incident_id)
359
- end
360
-
361
- def acknowledge_incident(incident_id)
362
- incident = fetch_incident(incident_id)
363
- if incident != 'No results'
364
- if incident.status != 'acknowledged' &&
365
- incident.status != 'resolved'
366
- results = incident.acknowledge
367
- if results.key?('status') && results['status'] == 'acknowledged'
368
- "#{incident_id}: Incident acknowledged"
369
- else
370
- "#{incident_id}: Unable to acknowledge incident"
371
- end
372
- else
373
- "#{incident_id}: Incident already #{incident.status}"
374
- end
375
- else
376
- "#{incident_id}: Incident not found"
377
- end
378
- end
379
-
380
- def resolve_incident(incident_id)
381
- incident = fetch_incident(incident_id)
382
- if incident != 'No results'
383
- if incident.status != 'resolved'
384
- results = incident.resolve
385
- if results.key?('status') && results['status'] == 'resolved'
386
- "#{incident_id}: Incident resolved"
387
- else
388
- "#{incident_id}: Unable to resolve incident"
389
- end
390
- else
391
- "#{incident_id}: Incident already #{incident.status}"
392
- end
393
- else
394
- "#{incident_id}: Incident not found"
395
- end
396
- end
397
- end
398
-
399
- Lita.register_handler(Pagerduty)
400
- end
401
- end