-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from contactually/feature/pagerduty
Adds support for pagerduty notifications
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# coding: utf-8 | ||
|
||
module Stoplight | ||
module Notifier | ||
# @see Base | ||
class Pagerduty < Base | ||
include Generic | ||
|
||
# @return [::Slack::Notifier] | ||
def pagerduty | ||
@object | ||
end | ||
|
||
private | ||
|
||
def put(message) | ||
pagerduty.trigger(message) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# coding: utf-8 | ||
|
||
require 'spec_helper' | ||
require 'pagerduty' | ||
|
||
RSpec.describe Stoplight::Notifier::Pagerduty do | ||
it_behaves_like 'a generic notifier' | ||
|
||
it 'is a class' do | ||
expect(described_class).to be_a(Class) | ||
end | ||
|
||
it 'is a subclass of Base' do | ||
expect(described_class).to be < Stoplight::Notifier::Base | ||
end | ||
|
||
describe '#pagerduty' do | ||
it 'reads Pagerduty client' do | ||
pagerduty = Pagerduty.new('WEBHOOK_URL') | ||
expect(described_class.new(pagerduty).pagerduty).to eql(pagerduty) | ||
end | ||
end | ||
|
||
describe '#notify' do | ||
let(:light) { Stoplight::Light.new(name, &code) } | ||
let(:name) { ('a'..'z').to_a.shuffle.join } | ||
let(:code) { -> {} } | ||
let(:from_color) { Stoplight::Color::GREEN } | ||
let(:to_color) { Stoplight::Color::RED } | ||
let(:notifier) { described_class.new(pagerduty) } | ||
let(:pagerduty) { double(Pagerduty).as_null_object } | ||
|
||
it 'pings Pagerduty' do | ||
error = nil | ||
message = notifier.formatter.call(light, from_color, to_color, error) | ||
expect(pagerduty).to receive(:trigger).with(message) | ||
notifier.notify(light, from_color, to_color, error) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters