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.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/.rubocop.yml +6 -5
- data/README.md +11 -9
- data/Rakefile +4 -2
- data/lib/exceptions.rb +11 -0
- data/lib/lita-pagerduty.rb +7 -29
- data/lib/lita/commands/ack.rb +15 -0
- data/lib/lita/commands/ack_all.rb +21 -0
- data/lib/lita/commands/ack_mine.rb +26 -0
- data/lib/lita/commands/base.rb +75 -0
- data/lib/lita/commands/forget.rb +13 -0
- data/lib/lita/commands/identify.rb +13 -0
- data/lib/lita/commands/incident.rb +13 -0
- data/lib/lita/commands/incidents_all.rb +18 -0
- data/lib/lita/commands/incidents_mine.rb +23 -0
- data/lib/lita/commands/notes.rb +15 -0
- data/lib/lita/commands/on_call_list.rb +13 -0
- data/lib/lita/commands/on_call_lookup.rb +41 -0
- data/lib/lita/commands/pager_me.rb +48 -0
- data/lib/lita/commands/resolve.rb +15 -0
- data/lib/lita/commands/resolve_all.rb +21 -0
- data/lib/lita/commands/resolve_mine.rb +26 -0
- data/lib/lita/handlers/commands.yml +30 -0
- data/lib/lita/handlers/pagerduty.rb +57 -0
- data/lib/pagerduty.rb +94 -0
- data/lib/store.rb +20 -0
- data/lita-pagerduty.gemspec +1 -2
- data/locales/en.yml +2 -2
- data/spec/lita/handlers/ack_all_spec.rb +26 -0
- data/spec/lita/handlers/ack_id_spec.rb +23 -0
- data/spec/lita/handlers/ack_mine_spec.rb +38 -0
- data/spec/lita/handlers/forget_spec.rb +22 -0
- data/spec/lita/handlers/identify_email_spec.rb +22 -0
- data/spec/lita/handlers/incident_id_spec.rb +23 -0
- data/spec/lita/handlers/incidents_all_spec.rb +31 -0
- data/spec/lita/handlers/incidents_mine_spec.rb +35 -0
- data/spec/lita/handlers/notes_spec.rb +29 -0
- data/spec/lita/handlers/on_call_list_spec.rb +21 -0
- data/spec/lita/handlers/on_call_lookup_spec.rb +29 -0
- data/spec/lita/handlers/pager_me_spec.rb +56 -0
- data/spec/lita/handlers/resolve_all_spec.rb +26 -0
- data/spec/lita/handlers/resolve_id_spec.rb +21 -0
- data/spec/lita/handlers/resolve_mine_spec.rb +38 -0
- data/spec/pagerduty_spec.rb +106 -0
- data/spec/spec_helper.rb +3 -189
- data/templates/.gitkeep +0 -0
- metadata +57 -35
- data/lib/lita/handlers/pagerduty_ack.rb +0 -77
- data/lib/lita/handlers/pagerduty_incident.rb +0 -68
- data/lib/lita/handlers/pagerduty_note.rb +0 -50
- data/lib/lita/handlers/pagerduty_resolve.rb +0 -77
- data/lib/lita/handlers/pagerduty_utility.rb +0 -136
- data/lib/pagerduty_helper/incident.rb +0 -64
- data/lib/pagerduty_helper/regex.rb +0 -8
- data/lib/pagerduty_helper/utility.rb +0 -43
- data/spec/lita/handlers/pagerduty_ack_spec.rb +0 -95
- data/spec/lita/handlers/pagerduty_incident_spec.rb +0 -103
- data/spec/lita/handlers/pagerduty_note_spec.rb +0 -43
- data/spec/lita/handlers/pagerduty_resolve_spec.rb +0 -95
- data/spec/lita/handlers/pagerduty_utility_spec.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fa275bada173401c6fdac456b713176375ae8f5
|
4
|
+
data.tar.gz: 410ca4278874a6cd332f9e134d982a3f7830c80a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af72dc0772235f9202fc14ebabe43594a56bd2782a4e432b92424e2984383d083cf77e9aa84dd2d561f7716d8a63f7d34e96df9f93877baa9f6ba51beb548727
|
7
|
+
data.tar.gz: f65a55fb1c4802f2ec3420b0e3af35ee4ed24bd779849f6107f53826fbface9241d2b7b6f0b46807c190bf11f2cd39d2709939b52ca50a2659dc0298bec223ee
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--color
|
1
|
+
--color
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -19,15 +19,24 @@ gem "lita-pagerduty"
|
|
19
19
|
|
20
20
|
## Configuration
|
21
21
|
|
22
|
+
Create a PagerDuty api Key(v1 legacy) You will need to give it FullAccess to update incidents
|
23
|
+
|
22
24
|
Add the following variables to your Lita config file:
|
23
25
|
|
24
26
|
``` ruby
|
25
|
-
config.handlers.pagerduty.api_key
|
26
|
-
config.handlers.pagerduty.
|
27
|
+
config.handlers.pagerduty.api_key = ''
|
28
|
+
config.handlers.pagerduty.email = ''
|
27
29
|
```
|
28
30
|
|
29
31
|
## Usage
|
30
32
|
|
33
|
+
### Misc
|
34
|
+
|
35
|
+
```
|
36
|
+
pager identify <email address> - Associate your chat user with your email address
|
37
|
+
pager forget - Remove your chat user / email association
|
38
|
+
```
|
39
|
+
|
31
40
|
### Specific incidents
|
32
41
|
|
33
42
|
```
|
@@ -65,13 +74,6 @@ pager oncall - List available schedules
|
|
65
74
|
pager oncall <schedule> - Show who is on call for the given schedule
|
66
75
|
```
|
67
76
|
|
68
|
-
### Misc
|
69
|
-
|
70
|
-
```
|
71
|
-
pager identify <email address> - Associate your chat user with your email address
|
72
|
-
pager forget - Remove your chat user / email association
|
73
|
-
```
|
74
|
-
|
75
77
|
## License
|
76
78
|
|
77
79
|
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
CHANGED
@@ -3,6 +3,8 @@ require 'rspec/core/rake_task'
|
|
3
3
|
require 'rubocop/rake_task'
|
4
4
|
|
5
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
|
-
RuboCop::RakeTask.new(:rubocop)
|
6
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
7
|
+
t.options = ['./lib']
|
8
|
+
end
|
7
9
|
|
8
|
-
task default: [
|
10
|
+
task default: %i[spec rubocop]
|
data/lib/exceptions.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module Exceptions
|
2
|
+
class SchedulesEmptyList < StandardError; end
|
3
|
+
class IncidentsEmptyList < StandardError; end
|
4
|
+
class UsersEmptyList < StandardError; end
|
5
|
+
class NotesEmptyList < StandardError; end
|
6
|
+
class IncidentManageUnsuccess < StandardError; end
|
7
|
+
class OverrideUnsuccess < StandardError; end
|
8
|
+
class IncidentNotFound < StandardError; end
|
9
|
+
class UserNotIdentified < StandardError; end
|
10
|
+
class NoOncallUser < StandardError; end
|
11
|
+
end
|
data/lib/lita-pagerduty.rb
CHANGED
@@ -1,37 +1,15 @@
|
|
1
1
|
require 'lita'
|
2
|
+
require 'exceptions'
|
3
|
+
require 'pagerduty'
|
4
|
+
require 'store'
|
5
|
+
require 'lita/handlers/pagerduty'
|
6
|
+
require 'lita/commands/base'
|
7
|
+
Dir[File.join(__dir__, 'lita', 'commands', '*.rb')].each { |file| require file }
|
2
8
|
|
3
9
|
Lita.load_locales Dir[File.expand_path(
|
4
10
|
File.join('..', '..', 'locales', '*.yml'), __FILE__
|
5
11
|
)]
|
6
12
|
|
7
|
-
|
8
|
-
|
9
|
-
require 'pagerduty_helper/incident'
|
10
|
-
require 'pagerduty_helper/regex'
|
11
|
-
require 'pagerduty_helper/utility'
|
12
|
-
|
13
|
-
require 'lita/handlers/pagerduty_ack'
|
14
|
-
require 'lita/handlers/pagerduty_incident'
|
15
|
-
require 'lita/handlers/pagerduty_note'
|
16
|
-
require 'lita/handlers/pagerduty_resolve'
|
17
|
-
require 'lita/handlers/pagerduty_utility'
|
18
|
-
|
19
|
-
Lita::Handlers::PagerdutyAck.template_root File.expand_path(
|
20
|
-
File.join('..', '..', 'templates'), __FILE__
|
21
|
-
)
|
22
|
-
|
23
|
-
Lita::Handlers::PagerdutyIncident.template_root File.expand_path(
|
24
|
-
File.join('..', '..', 'templates'), __FILE__
|
25
|
-
)
|
26
|
-
|
27
|
-
Lita::Handlers::PagerdutyNote.template_root File.expand_path(
|
28
|
-
File.join('..', '..', 'templates'), __FILE__
|
29
|
-
)
|
30
|
-
|
31
|
-
Lita::Handlers::PagerdutyResolve.template_root File.expand_path(
|
32
|
-
File.join('..', '..', 'templates'), __FILE__
|
33
|
-
)
|
34
|
-
|
35
|
-
Lita::Handlers::PagerdutyUtility.template_root File.expand_path(
|
13
|
+
Lita::Handlers::Pagerduty.template_root File.expand_path(
|
36
14
|
File.join('..', '..', 'templates'), __FILE__
|
37
15
|
)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Commands
|
2
|
+
class Ack
|
3
|
+
include Base
|
4
|
+
|
5
|
+
def call
|
6
|
+
incident_id = message.match_data['incident_id']
|
7
|
+
return if incident_id =~ /\A(all|mine)\z/i
|
8
|
+
|
9
|
+
pagerduty.manage_incidents(:acknowledge, [incident_id])
|
10
|
+
response message: 'all.acknowledged', params: { list: incident_id.to_s }
|
11
|
+
rescue Exceptions::IncidentManageUnsuccess
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Commands
|
2
|
+
class AckAll
|
3
|
+
include Base
|
4
|
+
|
5
|
+
def call
|
6
|
+
ids = pagerduty.get_incidents(query_params).map { |i| i[:id] }
|
7
|
+
pagerduty.manage_incidents(:acknowledge, ids)
|
8
|
+
response message: 'all.acknowledged', params: { list: ids.join(', ') }
|
9
|
+
rescue Exceptions::IncidentsEmptyList
|
10
|
+
response message: 'incident.none'
|
11
|
+
rescue Exceptions::IncidentManageUnsuccess
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def query_params
|
18
|
+
{ statuses: %w[triggered acknowledged] }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Commands
|
2
|
+
class AckMine
|
3
|
+
include Base
|
4
|
+
|
5
|
+
def call
|
6
|
+
ids = pagerduty.get_incidents(query_params).map { |i| i[:id] }
|
7
|
+
pagerduty.manage_incidents(:acknowledge, ids)
|
8
|
+
response message: 'all.acknowledged', params: { list: ids.join(', ') }
|
9
|
+
rescue Exceptions::UserNotIdentified
|
10
|
+
response message: 'incident.none_mine'
|
11
|
+
rescue Exceptions::IncidentsEmptyList
|
12
|
+
response message: 'incident.none_mine'
|
13
|
+
rescue Exceptions::IncidentManageUnsuccess
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def query_params
|
20
|
+
{
|
21
|
+
statuses: %w[triggered acknowledged],
|
22
|
+
'user_ids[]' => current_user[:id]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Commands
|
2
|
+
module Base
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
extend ClassMethods
|
6
|
+
attr_reader :message
|
7
|
+
attr_reader :data
|
8
|
+
attr_reader :pagerduty
|
9
|
+
attr_reader :store
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def call(message, pagerduty, store)
|
15
|
+
new(message, pagerduty, store).tap(&:call).data
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(message, pagerduty, store)
|
20
|
+
@message = message
|
21
|
+
@pagerduty = pagerduty
|
22
|
+
@store = store
|
23
|
+
@data = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def response(obj)
|
27
|
+
@data = obj
|
28
|
+
end
|
29
|
+
|
30
|
+
def format_notes(notes, incident_id)
|
31
|
+
notes.map { |note| format_note(note, incident_id) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def format_note(note, incident_id)
|
35
|
+
{
|
36
|
+
message: 'note.show',
|
37
|
+
params: {
|
38
|
+
id: incident_id,
|
39
|
+
content: note[:content],
|
40
|
+
user: note[:user][:summary]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def format_incidents(incidents)
|
46
|
+
incidents.map { |incident| format_incident(incident) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def format_incident(incident)
|
50
|
+
assignee = (incident.fetch(:assignments, []).first || {})
|
51
|
+
.fetch(:assignee, {})
|
52
|
+
.fetch(:summary, 'none')
|
53
|
+
{
|
54
|
+
message: 'incident.info',
|
55
|
+
params: {
|
56
|
+
id: incident[:id], subject: incident[:title],
|
57
|
+
assigned: assignee.inspect, url: incident[:html_url]
|
58
|
+
}
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def current_user
|
63
|
+
@current_user ||= pagerduty.get_users(query: store.get_user(message))
|
64
|
+
.first
|
65
|
+
end
|
66
|
+
|
67
|
+
def pagerduty
|
68
|
+
@pagerduty ||= ::Pagerduty.new(http, config.api_key, config.email)
|
69
|
+
end
|
70
|
+
|
71
|
+
def store
|
72
|
+
@store ||= Store.new(redis)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Commands
|
2
|
+
class Identify
|
3
|
+
include Base
|
4
|
+
|
5
|
+
def call
|
6
|
+
store.get_user message
|
7
|
+
response message: 'identify.already'
|
8
|
+
rescue Exceptions::UserNotIdentified
|
9
|
+
store.remember_user message
|
10
|
+
response message: 'identify.complete'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Commands
|
2
|
+
class Incident
|
3
|
+
include Base
|
4
|
+
|
5
|
+
def call
|
6
|
+
incident_id = message.match_data['incident_id']
|
7
|
+
incident = pagerduty.get_incident(incident_id)
|
8
|
+
response format_incidents([incident])
|
9
|
+
rescue Exceptions::IncidentNotFound
|
10
|
+
response message: 'incident.not_found', params: { id: incident_id }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Commands
|
2
|
+
class IncidentsAll
|
3
|
+
include Base
|
4
|
+
|
5
|
+
def call
|
6
|
+
incidents = pagerduty.get_incidents(query_params)
|
7
|
+
response format_incidents(incidents)
|
8
|
+
rescue Exceptions::IncidentsEmptyList
|
9
|
+
response message: 'incident.none'
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def query_params
|
15
|
+
{ statuses: %w[triggered acknowledged] }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Commands
|
2
|
+
class IncidentsMine
|
3
|
+
include Base
|
4
|
+
|
5
|
+
def call
|
6
|
+
incidents = pagerduty.get_incidents(query_params)
|
7
|
+
response format_incidents(incidents)
|
8
|
+
rescue Exceptions::IncidentsEmptyList
|
9
|
+
response message: 'incident.none'
|
10
|
+
rescue Exceptions::UserNotIdentified
|
11
|
+
response message: 'incident.none_mine'
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def query_params
|
17
|
+
{
|
18
|
+
statuses: %w[triggered acknowledged],
|
19
|
+
'user_ids[]' => current_user[:id]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Commands
|
2
|
+
class Notes
|
3
|
+
include Base
|
4
|
+
|
5
|
+
def call
|
6
|
+
incident_id = message.match_data['incident_id']
|
7
|
+
notes = pagerduty.get_notes_by_incident_id(incident_id)
|
8
|
+
response format_notes(notes, incident_id)
|
9
|
+
rescue Exceptions::IncidentNotFound
|
10
|
+
response message: 'incident.not_found', params: { id: incident_id }
|
11
|
+
rescue Exceptions::NotesEmptyList
|
12
|
+
response "#{incident_id}: No notes"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Commands
|
2
|
+
class OnCallList
|
3
|
+
include Base
|
4
|
+
|
5
|
+
def call
|
6
|
+
schedules = pagerduty.get_schedules.map { |i| i[:name] }.join("\n")
|
7
|
+
response message: 'on_call_list.response',
|
8
|
+
params: { schedules: schedules }
|
9
|
+
rescue Exceptions::SchedulesEmptyList
|
10
|
+
response message: 'on_call_list.no_schedules_found'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Commands
|
2
|
+
class OnCallLookup
|
3
|
+
include Base
|
4
|
+
|
5
|
+
def call
|
6
|
+
response message: 'on_call_lookup.response', params: success_params
|
7
|
+
rescue Exceptions::SchedulesEmptyList
|
8
|
+
response message: 'on_call_lookup.no_matching_schedule',
|
9
|
+
params: { schedule_name: schedule_name }
|
10
|
+
rescue Exceptions::NoOncallUser
|
11
|
+
response message: 'on_call_lookup.no_one_on_call',
|
12
|
+
params: { schedule_name: schedule_name }
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def schedule
|
18
|
+
@schedule ||= pagerduty.get_schedules(query: schedule_name).first
|
19
|
+
end
|
20
|
+
|
21
|
+
def schedule_name
|
22
|
+
@schedule_name ||= message.match_data[1].strip
|
23
|
+
end
|
24
|
+
|
25
|
+
def oncall_user_params
|
26
|
+
{ 'schedule_ids[]' => schedule[:id], 'include[]' => 'users' }
|
27
|
+
end
|
28
|
+
|
29
|
+
def success_params
|
30
|
+
{
|
31
|
+
name: user[:summary],
|
32
|
+
email: user[:email],
|
33
|
+
schedule_name: schedule[:name]
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def user
|
38
|
+
@user ||= pagerduty.get_oncall_user oncall_user_params
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|