lita-pagerduty 0.2.0 → 1.0.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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/.rubocop.yml +6 -5
  4. data/README.md +11 -9
  5. data/Rakefile +4 -2
  6. data/lib/exceptions.rb +11 -0
  7. data/lib/lita-pagerduty.rb +7 -29
  8. data/lib/lita/commands/ack.rb +15 -0
  9. data/lib/lita/commands/ack_all.rb +21 -0
  10. data/lib/lita/commands/ack_mine.rb +26 -0
  11. data/lib/lita/commands/base.rb +75 -0
  12. data/lib/lita/commands/forget.rb +13 -0
  13. data/lib/lita/commands/identify.rb +13 -0
  14. data/lib/lita/commands/incident.rb +13 -0
  15. data/lib/lita/commands/incidents_all.rb +18 -0
  16. data/lib/lita/commands/incidents_mine.rb +23 -0
  17. data/lib/lita/commands/notes.rb +15 -0
  18. data/lib/lita/commands/on_call_list.rb +13 -0
  19. data/lib/lita/commands/on_call_lookup.rb +41 -0
  20. data/lib/lita/commands/pager_me.rb +48 -0
  21. data/lib/lita/commands/resolve.rb +15 -0
  22. data/lib/lita/commands/resolve_all.rb +21 -0
  23. data/lib/lita/commands/resolve_mine.rb +26 -0
  24. data/lib/lita/handlers/commands.yml +30 -0
  25. data/lib/lita/handlers/pagerduty.rb +57 -0
  26. data/lib/pagerduty.rb +94 -0
  27. data/lib/store.rb +20 -0
  28. data/lita-pagerduty.gemspec +1 -2
  29. data/locales/en.yml +2 -2
  30. data/spec/lita/handlers/ack_all_spec.rb +26 -0
  31. data/spec/lita/handlers/ack_id_spec.rb +23 -0
  32. data/spec/lita/handlers/ack_mine_spec.rb +38 -0
  33. data/spec/lita/handlers/forget_spec.rb +22 -0
  34. data/spec/lita/handlers/identify_email_spec.rb +22 -0
  35. data/spec/lita/handlers/incident_id_spec.rb +23 -0
  36. data/spec/lita/handlers/incidents_all_spec.rb +31 -0
  37. data/spec/lita/handlers/incidents_mine_spec.rb +35 -0
  38. data/spec/lita/handlers/notes_spec.rb +29 -0
  39. data/spec/lita/handlers/on_call_list_spec.rb +21 -0
  40. data/spec/lita/handlers/on_call_lookup_spec.rb +29 -0
  41. data/spec/lita/handlers/pager_me_spec.rb +56 -0
  42. data/spec/lita/handlers/resolve_all_spec.rb +26 -0
  43. data/spec/lita/handlers/resolve_id_spec.rb +21 -0
  44. data/spec/lita/handlers/resolve_mine_spec.rb +38 -0
  45. data/spec/pagerduty_spec.rb +106 -0
  46. data/spec/spec_helper.rb +3 -189
  47. data/templates/.gitkeep +0 -0
  48. metadata +57 -35
  49. data/lib/lita/handlers/pagerduty_ack.rb +0 -77
  50. data/lib/lita/handlers/pagerduty_incident.rb +0 -68
  51. data/lib/lita/handlers/pagerduty_note.rb +0 -50
  52. data/lib/lita/handlers/pagerduty_resolve.rb +0 -77
  53. data/lib/lita/handlers/pagerduty_utility.rb +0 -136
  54. data/lib/pagerduty_helper/incident.rb +0 -64
  55. data/lib/pagerduty_helper/regex.rb +0 -8
  56. data/lib/pagerduty_helper/utility.rb +0 -43
  57. data/spec/lita/handlers/pagerduty_ack_spec.rb +0 -95
  58. data/spec/lita/handlers/pagerduty_incident_spec.rb +0 -103
  59. data/spec/lita/handlers/pagerduty_note_spec.rb +0 -43
  60. data/spec/lita/handlers/pagerduty_resolve_spec.rb +0 -95
  61. data/spec/lita/handlers/pagerduty_utility_spec.rb +0 -59
@@ -1,103 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lita::Handlers::PagerdutyIncident, lita_handler: true do
4
- include_context 'basic fixtures'
5
-
6
- it do
7
- is_expected.to route_command('pager incidents all').to(:incidents_all)
8
- is_expected.to route_command('pager incidents mine').to(:incidents_mine)
9
- is_expected.to route_command('pager incident ABC123').to(:incident)
10
- end
11
-
12
- describe '#incidents_all' do
13
- describe 'when there are open incidents' do
14
- it 'shows a list of incidents' do
15
- expect(Pagerduty).to receive(:new) { incidents }
16
- send_command('pager incidents all')
17
- expect(replies.last).to eq('ABC789: "Still broke", assigned to: '\
18
- 'bar@example.com, url: https://acme.pagerduty.com/incidents/ABC789')
19
- end
20
- end
21
-
22
- describe 'when there are no open incidents' do
23
- it 'shows a warning' do
24
- expect(Pagerduty).to receive(:new) { no_incidents }
25
- send_command('pager incidents all')
26
- expect(replies.last).to eq('No triggered, open, or acknowledged ' \
27
- 'incidents')
28
- end
29
- end
30
- end
31
-
32
- describe '#incidents_mine' do
33
- describe 'when there are open incidents for the user' do
34
- it 'shows a list of incidents' do
35
- bar = Lita::User.create(123, name: 'bar')
36
- expect(Pagerduty).to receive(:new) { incidents }
37
- send_command('pager identify bar@example.com', as: bar)
38
- send_command('pager incidents mine', as: bar)
39
- expect(replies.last).to eq('ABC789: "Still broke", assigned to: ' \
40
- 'bar@example.com, url: https://acme.pagerduty.com/incidents/ABC789')
41
- end
42
- end
43
-
44
- describe 'when there are no open incidents for the user' do
45
- it 'shows no incidents' do
46
- foo = Lita::User.create(123, name: 'foo')
47
- expect(Pagerduty).to receive(:new) { incidents }
48
- send_command('pager identify foo@example.com', as: foo)
49
- send_command('pager incidents mine', as: foo)
50
- expect(replies.last).to eq('You have no triggered, open, or ' \
51
- 'acknowledged incidents')
52
- end
53
- end
54
-
55
- describe 'when the user has not identified themselves' do
56
- it 'shows a warning' do
57
- send_command('pager incidents mine')
58
- expect(replies.last).to eq('You have not identified yourself (use ' \
59
- 'the help command for more info)')
60
- end
61
- end
62
- end
63
-
64
- describe '#incident' do
65
- describe 'when the incident exists' do
66
- it 'shows incident details' do
67
- expect(Pagerduty).to receive(:new) { new_incident }
68
- send_command('pager incident ABC123')
69
- expect(replies.last).to eq('ABC123: "something broke", ' \
70
- 'assigned to: foo@example.com, ' \
71
- 'url: https://acme.pagerduty.com/incidents/ABC123')
72
- end
73
- end
74
-
75
- describe 'when the incident does not exist' do
76
- it 'shows an error' do
77
- expect(Pagerduty).to receive(:new) { no_incident }
78
- send_command('pager incident ABC123')
79
- expect(replies.last).to eq('ABC123: Incident not found')
80
- end
81
- end
82
-
83
- describe 'when the incident id is longer than 6 characters' do
84
- it 'shows the incident details' do
85
- expect(Pagerduty).to receive(:new) { incident_with_long_id }
86
- send_command('pager incident ABC123456789')
87
- expect(replies.last).to eq('ABC123456789: "something broke", ' \
88
- 'assigned to: foo@example.com, ' \
89
- 'url: https://acme.pagerduty.com/incidents/ABC123456789')
90
- end
91
- end
92
-
93
- describe 'when the incident is not assigned to anyone' do
94
- it 'shows incident details with none user' do
95
- expect(Pagerduty).to receive(:new) { incident_without_assigned_user }
96
- send_command('pager incident ABC456')
97
- expect(replies.last).to eq('ABC456: "something broke", ' \
98
- 'assigned to: none, ' \
99
- 'url: https://acme.pagerduty.com/incidents/ABC456')
100
- end
101
- end
102
- end
103
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lita::Handlers::PagerdutyNote, lita_handler: true do
4
- include_context 'basic fixtures'
5
-
6
- it do
7
- is_expected.to route_command('pager notes ABC123').to(:notes)
8
- is_expected.to route_command('pager note ABC123 some text').to(:note)
9
- end
10
-
11
- describe '#notes' do
12
- describe 'when the incident has notes' do
13
- it 'shows incident notes' do
14
- expect(Pagerduty).to receive(:new) { incident_with_notes }
15
- send_command('pager notes ABC123')
16
- expect(replies.last).to eq('ABC123: Hi! (foo@example.com)')
17
- end
18
- end
19
-
20
- describe 'when the incident doesnt have notes' do
21
- it 'shows no notes' do
22
- expect(Pagerduty).to receive(:new) { new_incident }
23
- send_command('pager notes ABC123')
24
- expect(replies.last).to eq('ABC123: No notes')
25
- end
26
- end
27
-
28
- describe 'when the incident does not exist' do
29
- it 'shows an error' do
30
- expect(Pagerduty).to receive(:new) { no_incident }
31
- send_command('pager notes ABC123')
32
- expect(replies.last).to eq('ABC123: Incident not found')
33
- end
34
- end
35
- end
36
-
37
- describe '#note' do
38
- it 'shows a warning' do
39
- send_command('pager note ABC123 some text')
40
- expect(replies.last).to eq('Not implemented yet.')
41
- end
42
- end
43
- end
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lita::Handlers::PagerdutyResolve, lita_handler: true do
4
- include_context 'basic fixtures'
5
-
6
- it do
7
- is_expected.to route_command('pager resolve all').to(:resolve_all)
8
- is_expected.to route_command('pager resolve mine').to(:resolve_mine)
9
- is_expected.to route_command('pager resolve ABC123').to(:resolve)
10
- end
11
-
12
- describe '#resolve_all' do
13
- describe 'when there are resolvable incidents' do
14
- it 'shows them as resolved' do
15
- expect(Pagerduty).to receive(:new).twice { incidents }
16
- send_command('pager resolve all')
17
- expect(replies.last).to eq('Resolved: ABC789')
18
- end
19
- end
20
-
21
- describe 'when there are no resolvable incidents' do
22
- it 'shows a warning' do
23
- expect(Pagerduty).to receive(:new) { no_incidents }
24
- send_command('pager resolve all')
25
- expect(replies.last).to eq('No triggered, open, or acknowledged ' \
26
- 'incidents')
27
- end
28
- end
29
- end
30
-
31
- describe '#resolve_mine' do
32
- describe 'when there are resolvable incidents for the user' do
33
- it 'shows them as acknowledged' do
34
- bar = Lita::User.create(123, name: 'bar')
35
- expect(Pagerduty).to receive(:new).twice { incidents }
36
- send_command('pager identify bar@example.com', as: bar)
37
- send_command('pager resolve mine', as: bar)
38
- expect(replies.last).to eq('Resolved: ABC789')
39
- end
40
- end
41
-
42
- describe 'when there are no resolvable incidents for the user' do
43
- it 'shows a warning' do
44
- foo = Lita::User.create(123, name: 'foo')
45
- expect(Pagerduty).to receive(:new) { incidents }
46
- send_command('pager identify foo@example.com', as: foo)
47
- send_command('pager resolve mine', as: foo)
48
- expect(replies.last).to eq('You have no triggered, open, or ' \
49
- 'acknowledged incidents')
50
- end
51
- end
52
-
53
- describe 'when the user has not identified themselves' do
54
- it 'shows a warning' do
55
- send_command('pager resolve mine')
56
- expect(replies.last).to eq('You have not identified yourself (use ' \
57
- 'the help command for more info)')
58
- end
59
- end
60
- end
61
-
62
- describe '#resolve' do
63
- describe 'when the incident has not been resolved' do
64
- it 'shows the resolve' do
65
- expect(Pagerduty).to receive(:new) { new_incident }
66
- send_command('pager resolve ABC123')
67
- expect(replies.last).to eq('ABC123: Incident resolved')
68
- end
69
- end
70
-
71
- describe 'when the incident has already been resolved' do
72
- it 'shows the warning' do
73
- expect(Pagerduty).to receive(:new) { resolved_incident }
74
- send_command('pager resolve ABC123')
75
- expect(replies.last).to eq('ABC123: Incident already resolved')
76
- end
77
- end
78
-
79
- describe 'when the incident does not exist' do
80
- it 'shows an error' do
81
- expect(Pagerduty).to receive(:new) { no_incident }
82
- send_command('pager resolve ABC123')
83
- expect(replies.last).to eq('ABC123: Incident not found')
84
- end
85
- end
86
-
87
- describe 'when the incident cannot be resolved' do
88
- it 'shows an error' do
89
- expect(Pagerduty).to receive(:new) { unable_to_resolve_incident }
90
- send_command('pager resolve ABC123')
91
- expect(replies.last).to eq('ABC123: Unable to resolve incident')
92
- end
93
- end
94
- end
95
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lita::Handlers::PagerdutyUtility, lita_handler: true do
4
- include_context 'basic fixtures'
5
-
6
- it do
7
- is_expected.to route_command('pager oncall').to(:on_call_list)
8
- is_expected.to route_command('pager oncall ops').to(:on_call_lookup)
9
- is_expected.to route_command('pager identify foobar@example.com').to(:identify)
10
- is_expected.to route_command('pager forget').to(:forget)
11
- is_expected.to route_command('pager me ops 12m').to(:pager_me)
12
- end
13
-
14
- before do
15
- Lita.config.handlers.pagerduty.api_key = 'foo'
16
- Lita.config.handlers.pagerduty.subdomain = 'bar'
17
- end
18
-
19
- describe '#identify' do
20
- describe 'when that email is new' do
21
- it 'shows a successful identification' do
22
- foo = Lita::User.create(123, name: 'foo')
23
- send_command('pager identify foo@example.com', as: foo)
24
- expect(replies.last).to eq('You have now been identified.')
25
- end
26
- end
27
-
28
- # TODO: It'd be great to validate this against the existing
29
- # users on the PD account.
30
-
31
- describe 'when that email exists already' do
32
- it 'shows a warning' do
33
- baz = Lita::User.create(321, name: 'baz')
34
- send_command('pager identify baz@example.com', as: baz)
35
- send_command('pager identify baz@example.com', as: baz)
36
- expect(replies.last).to eq('You have already been identified!')
37
- end
38
- end
39
- end
40
-
41
- describe '#forget' do
42
- describe 'when that user is associated' do
43
- it 'shows a successful forget' do
44
- foo = Lita::User.create(123, name: 'foo')
45
- send_command('pager identify foo@example.com', as: foo)
46
- send_command('pager forget', as: foo)
47
- expect(replies.last).to eq('Your email has now been forgotten.')
48
- end
49
- end
50
-
51
- describe 'when that user is not associated' do
52
- it 'shows a warning' do
53
- foo = Lita::User.create(123, name: 'foo')
54
- send_command('pager forget', as: foo)
55
- expect(replies.last).to eq('No email on record for you.')
56
- end
57
- end
58
- end
59
- end