lex-pagerduty 0.2.1

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 (32) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +16 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +53 -0
  6. data/CHANGELOG.md +12 -0
  7. data/CLAUDE.md +72 -0
  8. data/Dockerfile +6 -0
  9. data/Gemfile +12 -0
  10. data/Gemfile.lock +171 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +70 -0
  13. data/lex-pagerduty.gemspec +37 -0
  14. data/lib/legion/extensions/pagerduty/client.rb +51 -0
  15. data/lib/legion/extensions/pagerduty/helpers/client.rb +22 -0
  16. data/lib/legion/extensions/pagerduty/runners/abilities.rb +28 -0
  17. data/lib/legion/extensions/pagerduty/runners/escalation_policies.rb +58 -0
  18. data/lib/legion/extensions/pagerduty/runners/incidents.rb +98 -0
  19. data/lib/legion/extensions/pagerduty/runners/log_entries.rb +31 -0
  20. data/lib/legion/extensions/pagerduty/runners/maintenance_windows.rb +59 -0
  21. data/lib/legion/extensions/pagerduty/runners/notifications.rb +25 -0
  22. data/lib/legion/extensions/pagerduty/runners/on_calls.rb +29 -0
  23. data/lib/legion/extensions/pagerduty/runners/priorities.rb +24 -0
  24. data/lib/legion/extensions/pagerduty/runners/schedules.rb +71 -0
  25. data/lib/legion/extensions/pagerduty/runners/services.rb +82 -0
  26. data/lib/legion/extensions/pagerduty/runners/tags.rb +57 -0
  27. data/lib/legion/extensions/pagerduty/runners/teams.rb +58 -0
  28. data/lib/legion/extensions/pagerduty/runners/users.rb +78 -0
  29. data/lib/legion/extensions/pagerduty/runners/vendors.rb +29 -0
  30. data/lib/legion/extensions/pagerduty/version.rb +9 -0
  31. data/lib/legion/extensions/pagerduty.rb +27 -0
  32. metadata +188 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d9dd1c37daeb97465f00edc5e171ba4234a224128b97d9038ffc07eff739cb85
4
+ data.tar.gz: 3ea66c6a537731170c99765c08bf5381ddfa996c3a591b93479774846e97bb24
5
+ SHA512:
6
+ metadata.gz: 7dd1a597e15f12d9ab884c4b31cb79f0bd63d4774b01d624239420003156a0eaf73cab3638e3bbf019871c70996bd341d57c4140da386610a18ca80d9e08a234
7
+ data.tar.gz: 6d934d8b865984f0cbd8375c87866cfa328dce8bf572fb8efed00c2287a5e3fc93a76092c84f198de90e789413a5c746bda07a29a74b8294f750a1caf6050abd
@@ -0,0 +1,16 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+
7
+ jobs:
8
+ ci:
9
+ uses: LegionIO/.github/.github/workflows/ci.yml@main
10
+
11
+ release:
12
+ needs: ci
13
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
14
+ uses: LegionIO/.github/.github/workflows/release.yml@main
15
+ secrets:
16
+ rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Layout/LineLength:
7
+ Max: 160
8
+
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+
12
+ Layout/HashAlignment:
13
+ EnforcedHashRocketStyle: table
14
+ EnforcedColonStyle: table
15
+
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+
19
+ Metrics/ClassLength:
20
+ Max: 1500
21
+
22
+ Metrics/ModuleLength:
23
+ Max: 1500
24
+
25
+ Metrics/BlockLength:
26
+ Max: 40
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
30
+ Metrics/ParameterLists:
31
+ Max: 10
32
+
33
+ Metrics/AbcSize:
34
+ Max: 60
35
+
36
+ Metrics/CyclomaticComplexity:
37
+ Max: 15
38
+
39
+ Metrics/PerceivedComplexity:
40
+ Max: 17
41
+
42
+ Style/Documentation:
43
+ Enabled: false
44
+
45
+ Style/SymbolArray:
46
+ Enabled: true
47
+
48
+ Style/FrozenStringLiteralComment:
49
+ Enabled: true
50
+ EnforcedStyle: always
51
+
52
+ Naming/FileName:
53
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## [0.2.1] - 2026-03-22
4
+
5
+ ### Changed
6
+ - Add legion-cache, legion-crypt, legion-data, legion-json, legion-logging, legion-settings, legion-transport as runtime dependencies
7
+ - Update spec_helper with real sub-gem helper stubs
8
+
9
+ ## [0.2.0] - 2026-03-13
10
+
11
+ ### Added
12
+ - Initial release
data/CLAUDE.md ADDED
@@ -0,0 +1,72 @@
1
+ # lex-pagerduty: PagerDuty Integration for LegionIO
2
+
3
+ **Repository Level 3 Documentation**
4
+ - **Parent**: `/Users/miverso2/rubymine/legion/extensions-other/CLAUDE.md`
5
+ - **Grandparent**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
6
+
7
+ ## Purpose
8
+
9
+ Legion Extension that connects LegionIO to PagerDuty via the REST API v2. Provides runners for managing incidents, services, escalation policies, schedules, users, teams, on-calls, priorities, maintenance windows, log entries, notifications, tags, abilities, and vendors.
10
+
11
+ **GitHub**: https://github.com/LegionIO/lex-pagerduty
12
+ **License**: MIT
13
+ **Version**: 0.2.0
14
+
15
+ ## Architecture
16
+
17
+ ```
18
+ Legion::Extensions::Pagerduty
19
+ ├── Runners/
20
+ │ ├── Incidents # Incident lifecycle (create, ack, resolve, merge, snooze, notes, alerts)
21
+ │ ├── Services # Service CRUD + integrations
22
+ │ ├── EscalationPolicies # Escalation policy CRUD
23
+ │ ├── Schedules # Schedule CRUD + overrides + on-call users
24
+ │ ├── Users # User CRUD + contact methods + notification rules
25
+ │ ├── Teams # Team CRUD + member management
26
+ │ ├── OnCalls # On-call listing with schedule/policy filters
27
+ │ ├── Priorities # Priority listing
28
+ │ ├── MaintenanceWindows # Maintenance window CRUD
29
+ │ ├── LogEntries # Log entry queries
30
+ │ ├── Notifications # Notification listing
31
+ │ ├── Tags # Tag CRUD + entity assignment
32
+ │ ├── Abilities # Account ability queries
33
+ │ └── Vendors # Vendor listing
34
+ ├── Helpers/
35
+ │ └── Client # Faraday connection builder (PagerDuty REST API v2)
36
+ └── Client # Standalone client class (includes all runners)
37
+ ```
38
+
39
+ ## Key Files
40
+
41
+ | Path | Purpose |
42
+ |------|---------|
43
+ | `lib/legion/extensions/pagerduty.rb` | Entry point, loads all runners |
44
+ | `lib/legion/extensions/pagerduty/client.rb` | Standalone client (initialize with token:) |
45
+ | `lib/legion/extensions/pagerduty/helpers/client.rb` | Faraday builder for PagerDuty API |
46
+ | `lib/legion/extensions/pagerduty/runners/` | All runners |
47
+
48
+ ## API Authentication
49
+
50
+ PagerDuty uses token-based auth: `Authorization: Token token=YOUR_TOKEN`
51
+
52
+ Mutating incident operations require a `From` header with the user's email address.
53
+
54
+ ## Dependencies
55
+
56
+ | Gem | Purpose |
57
+ |-----|---------|
58
+ | `faraday` (>= 2.0) | HTTP client for PagerDuty REST API v2 |
59
+
60
+ ## Development
61
+
62
+ 37 specs total.
63
+
64
+ ```bash
65
+ bundle install
66
+ bundle exec rspec
67
+ bundle exec rubocop
68
+ ```
69
+
70
+ ---
71
+
72
+ **Maintained By**: Matthew Iverson (@Esity)
data/Dockerfile ADDED
@@ -0,0 +1,6 @@
1
+ FROM legionio/legion
2
+
3
+ COPY . /usr/src/app/lex-pagerduty
4
+
5
+ WORKDIR /usr/src/app/lex-pagerduty
6
+ RUN bundle install
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'rspec_junit_formatter'
10
+ gem 'rubocop'
11
+ gem 'simplecov'
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,171 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lex-pagerduty (0.2.1)
5
+ faraday (>= 2.0)
6
+ legion-cache (>= 1.3.11)
7
+ legion-crypt (>= 1.4.9)
8
+ legion-data (>= 1.4.17)
9
+ legion-json (>= 1.2.1)
10
+ legion-logging (>= 1.3.2)
11
+ legion-settings (>= 1.3.14)
12
+ legion-transport (>= 1.3.9)
13
+
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ specs:
17
+ addressable (2.8.9)
18
+ public_suffix (>= 2.0.2, < 8.0)
19
+ amq-protocol (2.5.1)
20
+ ast (2.4.3)
21
+ aws-eventstream (1.4.0)
22
+ aws-sigv4 (1.12.1)
23
+ aws-eventstream (~> 1, >= 1.0.2)
24
+ base64 (0.3.0)
25
+ bigdecimal (4.0.1)
26
+ bunny (2.24.0)
27
+ amq-protocol (~> 2.3)
28
+ sorted_set (~> 1, >= 1.0.2)
29
+ concurrent-ruby (1.3.6)
30
+ connection_pool (2.5.5)
31
+ dalli (5.0.2)
32
+ logger
33
+ diff-lcs (1.6.2)
34
+ docile (1.4.1)
35
+ ed25519 (1.4.0)
36
+ faraday (2.14.1)
37
+ faraday-net_http (>= 2.0, < 3.5)
38
+ json
39
+ logger
40
+ faraday-net_http (3.4.2)
41
+ net-http (~> 0.5)
42
+ json (2.19.1)
43
+ json-schema (6.2.0)
44
+ addressable (~> 2.8)
45
+ bigdecimal (>= 3.1, < 5)
46
+ json_pure (2.8.1)
47
+ jwt (3.1.2)
48
+ base64
49
+ language_server-protocol (3.17.0.5)
50
+ legion-cache (1.3.11)
51
+ connection_pool (>= 2.4)
52
+ dalli (>= 3.0)
53
+ legion-logging (>= 1.2.8)
54
+ legion-settings (>= 1.3.12)
55
+ redis (>= 5.0)
56
+ legion-crypt (1.4.9)
57
+ ed25519 (~> 1.3)
58
+ jwt (>= 2.7)
59
+ vault (>= 0.17)
60
+ legion-data (1.4.17)
61
+ legion-logging (>= 1.2.8)
62
+ legion-settings (>= 1.3.12)
63
+ sequel (>= 5.70)
64
+ sqlite3 (>= 2.0)
65
+ legion-json (1.2.1)
66
+ json_pure
67
+ multi_json
68
+ legion-logging (1.3.2)
69
+ logger
70
+ rainbow (~> 3)
71
+ legion-settings (1.3.14)
72
+ legion-json (>= 1.2.0)
73
+ legion-transport (1.3.9)
74
+ bunny (>= 2.23)
75
+ concurrent-ruby (>= 1.2)
76
+ legion-json (>= 1.2.0)
77
+ legion-settings (>= 1.3.12)
78
+ logger
79
+ lint_roller (1.1.0)
80
+ logger (1.7.0)
81
+ mcp (0.8.0)
82
+ json-schema (>= 4.1)
83
+ mini_portile2 (2.8.9)
84
+ multi_json (1.19.1)
85
+ net-http (0.9.1)
86
+ uri (>= 0.11.1)
87
+ net-http-persistent (4.0.8)
88
+ connection_pool (>= 2.2.4, < 4)
89
+ parallel (1.27.0)
90
+ parser (3.3.10.2)
91
+ ast (~> 2.4.1)
92
+ racc
93
+ prism (1.9.0)
94
+ public_suffix (7.0.5)
95
+ racc (1.8.1)
96
+ rainbow (3.1.1)
97
+ rake (13.3.1)
98
+ rbtree (0.4.6)
99
+ redis (5.4.1)
100
+ redis-client (>= 0.22.0)
101
+ redis-client (0.28.0)
102
+ connection_pool
103
+ regexp_parser (2.11.3)
104
+ rspec (3.13.2)
105
+ rspec-core (~> 3.13.0)
106
+ rspec-expectations (~> 3.13.0)
107
+ rspec-mocks (~> 3.13.0)
108
+ rspec-core (3.13.6)
109
+ rspec-support (~> 3.13.0)
110
+ rspec-expectations (3.13.5)
111
+ diff-lcs (>= 1.2.0, < 2.0)
112
+ rspec-support (~> 3.13.0)
113
+ rspec-mocks (3.13.8)
114
+ diff-lcs (>= 1.2.0, < 2.0)
115
+ rspec-support (~> 3.13.0)
116
+ rspec-support (3.13.7)
117
+ rspec_junit_formatter (0.6.0)
118
+ rspec-core (>= 2, < 4, != 2.12.0)
119
+ rubocop (1.85.1)
120
+ json (~> 2.3)
121
+ language_server-protocol (~> 3.17.0.2)
122
+ lint_roller (~> 1.1.0)
123
+ mcp (~> 0.6)
124
+ parallel (~> 1.10)
125
+ parser (>= 3.3.0.2)
126
+ rainbow (>= 2.2.2, < 4.0)
127
+ regexp_parser (>= 2.9.3, < 3.0)
128
+ rubocop-ast (>= 1.49.0, < 2.0)
129
+ ruby-progressbar (~> 1.7)
130
+ unicode-display_width (>= 2.4.0, < 4.0)
131
+ rubocop-ast (1.49.1)
132
+ parser (>= 3.3.7.2)
133
+ prism (~> 1.7)
134
+ ruby-progressbar (1.13.0)
135
+ sequel (5.102.0)
136
+ bigdecimal
137
+ simplecov (0.22.0)
138
+ docile (~> 1.1)
139
+ simplecov-html (~> 0.11)
140
+ simplecov_json_formatter (~> 0.1)
141
+ simplecov-html (0.13.2)
142
+ simplecov_json_formatter (0.1.4)
143
+ sorted_set (1.1.0)
144
+ rbtree
145
+ sqlite3 (2.9.2)
146
+ mini_portile2 (~> 2.8.0)
147
+ sqlite3 (2.9.2-arm64-darwin)
148
+ unicode-display_width (3.2.0)
149
+ unicode-emoji (~> 4.1)
150
+ unicode-emoji (4.2.0)
151
+ uri (1.1.1)
152
+ vault (0.20.0)
153
+ aws-sigv4
154
+ base64
155
+ connection_pool (~> 2.4)
156
+ net-http-persistent (~> 4.0, >= 4.0.2)
157
+
158
+ PLATFORMS
159
+ arm64-darwin-25
160
+ ruby
161
+
162
+ DEPENDENCIES
163
+ lex-pagerduty!
164
+ rake
165
+ rspec
166
+ rspec_junit_formatter
167
+ rubocop
168
+ simplecov
169
+
170
+ BUNDLED WITH
171
+ 2.6.9
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Esity
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # lex-pagerduty
2
+
3
+ PagerDuty integration for [LegionIO](https://github.com/LegionIO/LegionIO). Manage incidents, services, escalation policies, schedules, users, teams, on-calls, priorities, maintenance windows, log entries, notifications, tags, abilities, and vendors via the PagerDuty REST API v2.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install lex-pagerduty
9
+ ```
10
+
11
+ Or add to your Gemfile:
12
+
13
+ ```ruby
14
+ gem 'lex-pagerduty'
15
+ ```
16
+
17
+ ## Standalone Usage
18
+
19
+ ```ruby
20
+ require 'legion/extensions/pagerduty'
21
+
22
+ client = Legion::Extensions::Pagerduty::Client.new(token: 'your-api-token')
23
+
24
+ # Incidents
25
+ client.list_incidents(statuses: ['triggered', 'acknowledged'])
26
+ client.create_incident(title: 'Server down', service_id: 'PSVC123')
27
+ client.update_incident(id: 'PINC456', from: 'user@example.com', status: 'acknowledged')
28
+ client.snooze_incident(id: 'PINC456', from: 'user@example.com', duration: 3600)
29
+
30
+ # Services
31
+ client.list_services
32
+ client.create_service(name: 'My App', escalation_policy_id: 'PEP789')
33
+
34
+ # Schedules
35
+ client.list_schedules
36
+ client.list_on_call_users(id: 'PSCH123')
37
+
38
+ # Users & Teams
39
+ client.list_users(query: 'john')
40
+ client.add_member(team_id: 'PTEAM1', user_id: 'PUSER1')
41
+ ```
42
+
43
+ ## Runners
44
+
45
+ | Runner | Operations |
46
+ |--------|-----------|
47
+ | Incidents | List, create, get, update, merge, snooze, notes, alerts |
48
+ | Services | List, create, get, update, delete, integrations |
49
+ | EscalationPolicies | List, create, get, update, delete |
50
+ | Schedules | List, create, get, update, delete, overrides, on-call users |
51
+ | Users | List, create, get, update, delete, contact methods, notification rules |
52
+ | Teams | List, create, get, update, delete, add/remove members |
53
+ | OnCalls | List on-call entries |
54
+ | Priorities | List priorities |
55
+ | MaintenanceWindows | List, create, get, update, delete |
56
+ | LogEntries | List, get |
57
+ | Notifications | List |
58
+ | Tags | List, create, get, delete, assign/remove from entities |
59
+ | Abilities | List, test |
60
+ | Vendors | List, get |
61
+
62
+ ## Requirements
63
+
64
+ - Ruby >= 3.4
65
+ - PagerDuty account with API token
66
+ - [LegionIO](https://github.com/LegionIO/LegionIO) framework (optional — standalone Client works without it)
67
+
68
+ ## License
69
+
70
+ MIT
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/extensions/pagerduty/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lex-pagerduty'
7
+ spec.version = Legion::Extensions::Pagerduty::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'LEX Pagerduty'
12
+ spec.description = 'Connects LegionIO to PagerDuty'
13
+ spec.homepage = 'https://github.com/LegionIO/lex-pagerduty'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.4'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-pagerduty'
19
+ spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-pagerduty'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-pagerduty'
21
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-pagerduty/issues'
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'faraday', '>= 2.0'
30
+ spec.add_dependency 'legion-cache', '>= 1.3.11'
31
+ spec.add_dependency 'legion-crypt', '>= 1.4.9'
32
+ spec.add_dependency 'legion-data', '>= 1.4.17'
33
+ spec.add_dependency 'legion-json', '>= 1.2.1'
34
+ spec.add_dependency 'legion-logging', '>= 1.3.2'
35
+ spec.add_dependency 'legion-settings', '>= 1.3.14'
36
+ spec.add_dependency 'legion-transport', '>= 1.3.9'
37
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/pagerduty/helpers/client'
4
+ require 'legion/extensions/pagerduty/runners/incidents'
5
+ require 'legion/extensions/pagerduty/runners/services'
6
+ require 'legion/extensions/pagerduty/runners/escalation_policies'
7
+ require 'legion/extensions/pagerduty/runners/schedules'
8
+ require 'legion/extensions/pagerduty/runners/users'
9
+ require 'legion/extensions/pagerduty/runners/teams'
10
+ require 'legion/extensions/pagerduty/runners/on_calls'
11
+ require 'legion/extensions/pagerduty/runners/priorities'
12
+ require 'legion/extensions/pagerduty/runners/maintenance_windows'
13
+ require 'legion/extensions/pagerduty/runners/log_entries'
14
+ require 'legion/extensions/pagerduty/runners/notifications'
15
+ require 'legion/extensions/pagerduty/runners/tags'
16
+ require 'legion/extensions/pagerduty/runners/abilities'
17
+ require 'legion/extensions/pagerduty/runners/vendors'
18
+
19
+ module Legion
20
+ module Extensions
21
+ module Pagerduty
22
+ class Client
23
+ include Helpers::Client
24
+ include Runners::Incidents
25
+ include Runners::Services
26
+ include Runners::EscalationPolicies
27
+ include Runners::Schedules
28
+ include Runners::Users
29
+ include Runners::Teams
30
+ include Runners::OnCalls
31
+ include Runners::Priorities
32
+ include Runners::MaintenanceWindows
33
+ include Runners::LogEntries
34
+ include Runners::Notifications
35
+ include Runners::Tags
36
+ include Runners::Abilities
37
+ include Runners::Vendors
38
+
39
+ attr_reader :opts
40
+
41
+ def initialize(token: nil, api_url: 'https://api.pagerduty.com', **extra)
42
+ @opts = { token: token, api_url: api_url, **extra }
43
+ end
44
+
45
+ def connection(**override)
46
+ super(**@opts.merge(override))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Pagerduty
8
+ module Helpers
9
+ module Client
10
+ def connection(api_url: 'https://api.pagerduty.com', token: nil, **_opts)
11
+ Faraday.new(url: api_url) do |conn|
12
+ conn.request :json
13
+ conn.response :json, content_type: /\bjson$/
14
+ conn.headers['Content-Type'] = 'application/json'
15
+ conn.headers['Authorization'] = "Token token=#{token}" if token
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/pagerduty/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Pagerduty
8
+ module Runners
9
+ module Abilities
10
+ include Legion::Extensions::Pagerduty::Helpers::Client
11
+
12
+ def list_abilities(**)
13
+ response = connection(**).get('/abilities')
14
+ { result: response.body }
15
+ end
16
+
17
+ def test_ability(ability:, **)
18
+ response = connection(**).get("/abilities/#{ability}")
19
+ { result: response.status == 204 }
20
+ end
21
+
22
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
23
+ Legion::Extensions::Helpers.const_defined?(:Lex)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/pagerduty/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Pagerduty
8
+ module Runners
9
+ module EscalationPolicies
10
+ include Legion::Extensions::Pagerduty::Helpers::Client
11
+
12
+ def list_escalation_policies(query: nil, per_page: 25, page: 0, **)
13
+ params = { limit: per_page, offset: page * per_page }
14
+ params[:query] = query if query
15
+ response = connection(**).get('/escalation_policies', params)
16
+ { result: response.body }
17
+ end
18
+
19
+ def get_escalation_policy(id:, **)
20
+ response = connection(**).get("/escalation_policies/#{id}")
21
+ { result: response.body }
22
+ end
23
+
24
+ def create_escalation_policy(name:, escalation_rules:, description: nil, repeat_enabled: false,
25
+ num_loops: 0, **)
26
+ payload = {
27
+ escalation_policy: {
28
+ type: 'escalation_policy',
29
+ name: name,
30
+ escalation_rules: escalation_rules,
31
+ repeat_enabled: repeat_enabled,
32
+ num_loops: num_loops
33
+ }
34
+ }
35
+ payload[:escalation_policy][:description] = description if description
36
+ response = connection(**).post('/escalation_policies', payload)
37
+ { result: response.body }
38
+ end
39
+
40
+ def update_escalation_policy(id:, **opts)
41
+ payload = opts.slice(:name, :description, :escalation_rules, :repeat_enabled, :num_loops)
42
+ response = connection(**opts).put("/escalation_policies/#{id}",
43
+ { escalation_policy: { type: 'escalation_policy', **payload } })
44
+ { result: response.body }
45
+ end
46
+
47
+ def delete_escalation_policy(id:, **)
48
+ response = connection(**).delete("/escalation_policies/#{id}")
49
+ { result: response.status == 204 }
50
+ end
51
+
52
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
53
+ Legion::Extensions::Helpers.const_defined?(:Lex)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end