stoplight 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97f3aac00bec5d8f4a86a709adacab7e81246b2c
4
- data.tar.gz: ed4f8f332e6111245ff0c6555b337bded9f417a7
3
+ metadata.gz: c744702c57c79bb96de6ba01eeb2c4adcc65eadd
4
+ data.tar.gz: face2e75b1ac458693f3d160a33d534dd1e0b226
5
5
  SHA512:
6
- metadata.gz: 43be4295193fbd9977303ddb15baf0d1ef3a4f04eeea57302d58e89d97ed3af2066b4c37294d335213f2b5841b987bf3b0e2a74eda00bff619e1504092ada523
7
- data.tar.gz: 5b8e1cfda7283a49082308f9f5d9f696ca2508066ddba7707240cc88e31e61f6f2d9611600c0468c68468eef0eb3851a16b1a1f1e85520c5618f043ddbe4fa62
6
+ metadata.gz: 258fd3aa57d2f49e4b049d98d83c899f80d47cdbd354436b854b56959aabd0e21f9d34e25fc607dc7d189dcdb8896e5b4cbdb6825f27435d3cd4e40654096179
7
+ data.tar.gz: 8369dc5c2f5355ed9936eea5d8999bdfa3965a891dbf62150dc1f748196aa46f87bec0e5201a473f5e72c6c0ef008e3f135cd8170bc5f72c1023784b862a62a7
data/README.md CHANGED
@@ -33,6 +33,7 @@ Check out [stoplight-admin][] for controlling your stoplights.
33
33
  - [HipChat](#hipchat)
34
34
  - [Honeybadger](#honeybadger)
35
35
  - [Logger](#logger)
36
+ - [Sentry](#sentry)
36
37
  - [Slack](#slack)
37
38
  - [Rails](#rails-1)
38
39
  - [Advanced usage](#advanced-usage)
@@ -356,6 +357,22 @@ Stoplight::Light.default_notifiers += [notifier]
356
357
  # => [#<Stoplight::Notifier::IO:...>, #<Stoplight::Notifier::Logger:...>]
357
358
  ```
358
359
 
360
+ #### Sentry
361
+
362
+ Make sure you have [the Sentry gem][] (`~> 1.2`) installed before configuring
363
+ Stoplight.
364
+
365
+ ``` rb
366
+ require 'sentry-raven'
367
+ # => true
368
+ configuration = Raven::Configuration.new
369
+ # => #<Raven::Configuration:...>
370
+ notifier = Stoplight::Notifier::Raven.new(configuration)
371
+ # => #<Stoplight::Notifier::Raven:...>
372
+ Stoplight::Light.default_notifiers += [notifier]
373
+ # => [#<Stoplight::Notifier::IO:...>, #<Stoplight::Notifier::Raven:...>]
374
+ ```
375
+
359
376
  #### Slack
360
377
 
361
378
  Make sure you have [the Slack gem][] (`~> 1.3`) installed before configuring
@@ -476,6 +493,7 @@ Stoplight is licensed under [the MIT License][].
476
493
  [the HipChat gem]: https://rubygems.org/gems/hipchat
477
494
  [the Honeybadger gem]: https://rubygems.org/gems/honeybadger
478
495
  [the Logger class]: http://ruby-doc.org/stdlib-2.2.3/libdoc/logger/rdoc/Logger.html
496
+ [the Sentry gem]: https://rubygems.org/gems/sentry-raven
479
497
  [the Slack gem]: https://rubygems.org/gems/slack-notifier
480
498
  [@camdez]: https://github.com/camdez
481
499
  [@tfausak]: https://github.com/tfausak
@@ -24,6 +24,7 @@ require 'stoplight/notifier/hip_chat'
24
24
  require 'stoplight/notifier/honeybadger'
25
25
  require 'stoplight/notifier/io'
26
26
  require 'stoplight/notifier/logger'
27
+ require 'stoplight/notifier/raven'
27
28
  require 'stoplight/notifier/slack'
28
29
 
29
30
  require 'stoplight/default'
@@ -15,7 +15,7 @@ module Stoplight
15
15
  # @param error [Exception]
16
16
  # @return (see #initialize)
17
17
  def self.from_error(error)
18
- new(error.class.name, error.message, Time.new)
18
+ new(error.class.name, error.message, Time.now)
19
19
  end
20
20
 
21
21
  # @param json [String]
@@ -8,11 +8,10 @@ module Stoplight
8
8
  failures, state = failures_and_state
9
9
  failure = failures.first
10
10
 
11
- case
12
- when state == State::LOCKED_GREEN then Color::GREEN
13
- when state == State::LOCKED_RED then Color::RED
14
- when failures.size < threshold then Color::GREEN
15
- when failure && Time.new - failure.time >= cool_off_time
11
+ if state == State::LOCKED_GREEN then Color::GREEN
12
+ elsif state == State::LOCKED_RED then Color::RED
13
+ elsif failures.size < threshold then Color::GREEN
14
+ elsif failure && Time.now - failure.time >= cool_off_time
16
15
  Color::YELLOW
17
16
  else Color::RED
18
17
  end
@@ -34,7 +34,8 @@ module Stoplight
34
34
  h = options.merge(
35
35
  api_key: api_key,
36
36
  error_message: message,
37
- backtrace: (error.backtrace if error))
37
+ backtrace: (error.backtrace if error)
38
+ )
38
39
  ::Honeybadger.notify(h)
39
40
  message
40
41
  end
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+
3
+ module Stoplight
4
+ module Notifier
5
+ # @see Base
6
+ class Raven < Base
7
+ DEFAULT_OPTIONS = {
8
+ extra: {}
9
+ }.freeze
10
+
11
+ # @return [::Raven::Configuration]
12
+ attr_reader :configuration
13
+ # @return [Proc]
14
+ attr_reader :formatter
15
+ # @return [Hash{Symbol => Object}]
16
+ attr_reader :options
17
+
18
+ # @param api_key [String]
19
+ # @param formatter [Proc, nil]
20
+ # @param options [Hash{Symbol => Object}]
21
+ # @option options [Hash] :extra
22
+ def initialize(configuration, formatter = nil, options = {})
23
+ @configuration = configuration
24
+ @formatter = formatter || Default::FORMATTER
25
+ @options = DEFAULT_OPTIONS.merge(options)
26
+ end
27
+
28
+ def notify(light, from_color, to_color, error)
29
+ message = formatter.call(light, from_color, to_color, error)
30
+
31
+ h = options.merge(
32
+ configuration: configuration,
33
+ backtrace: (error.backtrace if error)
34
+ )
35
+ ::Raven.capture_message(message, h)
36
+ message
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Stoplight
4
- VERSION = Gem::Version.new('2.0.0')
4
+ VERSION = Gem::Version.new('2.1.0')
5
5
  end
@@ -10,7 +10,8 @@ RSpec.describe Stoplight::Failure do
10
10
  let(:json) do
11
11
  JSON.generate(
12
12
  error: { class: error_class, message: error_message },
13
- time: time.strftime('%Y-%m-%dT%H:%M:%S.%N%:z'))
13
+ time: time.strftime('%Y-%m-%dT%H:%M:%S.%N%:z')
14
+ )
14
15
  end
15
16
 
16
17
  it 'is a class' do
@@ -51,14 +51,16 @@ RSpec.describe Stoplight::Light::Runnable do
51
51
  subject.data_store.record_failure(subject, failure)
52
52
  end
53
53
  other = Stoplight::Failure.new(
54
- error.class.name, error.message, Time.new - subject.cool_off_time)
54
+ error.class.name, error.message, Time.new - subject.cool_off_time
55
+ )
55
56
  subject.data_store.record_failure(subject, other)
56
57
  expect(subject.color).to eql(Stoplight::Color::YELLOW)
57
58
  end
58
59
 
59
60
  it 'is red when the least recent failure is old' do
60
61
  other = Stoplight::Failure.new(
61
- error.class.name, error.message, Time.new - subject.cool_off_time)
62
+ error.class.name, error.message, Time.new - subject.cool_off_time
63
+ )
62
64
  subject.data_store.record_failure(subject, other)
63
65
  (subject.threshold - 1).times do
64
66
  subject.data_store.record_failure(subject, failure)
@@ -200,7 +202,8 @@ RSpec.describe Stoplight::Light::Runnable do
200
202
  end
201
203
 
202
204
  other = Stoplight::Failure.new(
203
- error.class.name, error.message, time - subject.cool_off_time)
205
+ error.class.name, error.message, time - subject.cool_off_time
206
+ )
204
207
  subject.data_store.record_failure(subject, other)
205
208
  end
206
209
 
@@ -18,7 +18,8 @@ RSpec.describe Stoplight::Notifier::Honeybadger do
18
18
  describe '#formatter' do
19
19
  it 'is initially the default' do
20
20
  expect(described_class.new(nil).formatter).to eql(
21
- Stoplight::Default::FORMATTER)
21
+ Stoplight::Default::FORMATTER
22
+ )
22
23
  end
23
24
 
24
25
  it 'reads the formatter' do
@@ -30,13 +31,15 @@ RSpec.describe Stoplight::Notifier::Honeybadger do
30
31
  describe '#options' do
31
32
  it 'is initially the default' do
32
33
  expect(described_class.new(nil).options).to eql(
33
- Stoplight::Notifier::Honeybadger::DEFAULT_OPTIONS)
34
+ Stoplight::Notifier::Honeybadger::DEFAULT_OPTIONS
35
+ )
34
36
  end
35
37
 
36
38
  it 'reads the options' do
37
39
  options = { key: :value }
38
40
  expect(described_class.new(nil, nil, options).options).to eql(
39
- Stoplight::Notifier::Honeybadger::DEFAULT_OPTIONS.merge(options))
41
+ Stoplight::Notifier::Honeybadger::DEFAULT_OPTIONS.merge(options)
42
+ )
40
43
  end
41
44
  end
42
45
 
@@ -57,23 +60,29 @@ RSpec.describe Stoplight::Notifier::Honeybadger do
57
60
  error = nil
58
61
  message = notifier.formatter.call(light, from_color, to_color, error)
59
62
  expect(notifier.notify(light, from_color, to_color, error)).to eql(
60
- message)
63
+ message
64
+ )
61
65
  expect(Honeybadger).to have_received(:notify).with(
62
66
  hash_including(
63
67
  api_key: api_key,
64
- error_message: message))
68
+ error_message: message
69
+ )
70
+ )
65
71
  end
66
72
 
67
73
  it 'returns the message with an error' do
68
74
  error = ZeroDivisionError.new('divided by 0')
69
75
  message = notifier.formatter.call(light, from_color, to_color, error)
70
76
  expect(notifier.notify(light, from_color, to_color, error)).to eql(
71
- message)
77
+ message
78
+ )
72
79
  expect(Honeybadger).to have_received(:notify).with(
73
80
  hash_including(
74
81
  api_key: api_key,
75
82
  error_message: message,
76
- backtrace: error.backtrace))
83
+ backtrace: error.backtrace
84
+ )
85
+ )
77
86
  end
78
87
  end
79
88
  end
@@ -0,0 +1,90 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ # require 'sentry-raven'
6
+ module Raven
7
+ class Configuration
8
+ end
9
+ end
10
+
11
+ RSpec.describe Stoplight::Notifier::Raven do
12
+ it 'is a class' do
13
+ expect(described_class).to be_a(Class)
14
+ end
15
+
16
+ it 'is a subclass of Base' do
17
+ expect(described_class).to be < Stoplight::Notifier::Base
18
+ end
19
+
20
+ describe '#formatter' do
21
+ it 'is initially the default' do
22
+ expect(described_class.new(nil).formatter).to eql(
23
+ Stoplight::Default::FORMATTER
24
+ )
25
+ end
26
+
27
+ it 'reads the formatter' do
28
+ formatter = proc {}
29
+ expect(described_class.new(nil, formatter).formatter).to eql(formatter)
30
+ end
31
+ end
32
+
33
+ describe '#options' do
34
+ it 'is initially the default' do
35
+ expect(described_class.new(nil).options).to eql(
36
+ Stoplight::Notifier::Raven::DEFAULT_OPTIONS
37
+ )
38
+ end
39
+
40
+ it 'reads the options' do
41
+ options = { key: :value }
42
+ expect(described_class.new(nil, nil, options).options).to eql(
43
+ Stoplight::Notifier::Raven::DEFAULT_OPTIONS.merge(options)
44
+ )
45
+ end
46
+ end
47
+
48
+ describe '#notify' do
49
+ let(:light) { Stoplight::Light.new(name, &code) }
50
+ let(:name) { ('a'..'z').to_a.shuffle.join }
51
+ let(:code) { -> {} }
52
+ let(:from_color) { Stoplight::Color::GREEN }
53
+ let(:to_color) { Stoplight::Color::RED }
54
+ let(:notifier) { described_class.new(configuration) }
55
+ let(:configuration) { instance_double(::Raven::Configuration) }
56
+
57
+ before do
58
+ allow(::Raven).to receive(:capture_message)
59
+ end
60
+
61
+ it 'returns the message' do
62
+ error = nil
63
+ message = notifier.formatter.call(light, from_color, to_color, error)
64
+ expect(notifier.notify(light, from_color, to_color, error)).to eql(
65
+ message
66
+ )
67
+ expect(::Raven).to have_received(:capture_message).with(
68
+ message,
69
+ hash_including(
70
+ configuration: configuration
71
+ )
72
+ )
73
+ end
74
+
75
+ it 'returns the message with an error' do
76
+ error = ZeroDivisionError.new('divided by 0')
77
+ message = notifier.formatter.call(light, from_color, to_color, error)
78
+ expect(notifier.notify(light, from_color, to_color, error)).to eql(
79
+ message
80
+ )
81
+ expect(::Raven).to have_received(:capture_message).with(
82
+ message,
83
+ hash_including(
84
+ configuration: configuration,
85
+ backtrace: error.backtrace
86
+ )
87
+ )
88
+ end
89
+ end
90
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stoplight
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Desautels
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-04-26 00:00:00.000000000 Z
13
+ date: 2016-08-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: concurrent-ruby
@@ -110,6 +110,20 @@ dependencies:
110
110
  - - "~>"
111
111
  - !ruby/object:Gem::Version
112
112
  version: '2.5'
113
+ - !ruby/object:Gem::Dependency
114
+ name: sentry-raven
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '1.2'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '1.2'
113
127
  - !ruby/object:Gem::Dependency
114
128
  name: rake
115
129
  requirement: !ruby/object:Gem::Requirement
@@ -158,14 +172,14 @@ dependencies:
158
172
  requirements:
159
173
  - - "~>"
160
174
  - !ruby/object:Gem::Version
161
- version: 0.39.0
175
+ version: 0.40.0
162
176
  type: :development
163
177
  prerelease: false
164
178
  version_requirements: !ruby/object:Gem::Requirement
165
179
  requirements:
166
180
  - - "~>"
167
181
  - !ruby/object:Gem::Version
168
- version: 0.39.0
182
+ version: 0.40.0
169
183
  - !ruby/object:Gem::Dependency
170
184
  name: slack-notifier
171
185
  requirement: !ruby/object:Gem::Requirement
@@ -225,6 +239,7 @@ files:
225
239
  - lib/stoplight/notifier/honeybadger.rb
226
240
  - lib/stoplight/notifier/io.rb
227
241
  - lib/stoplight/notifier/logger.rb
242
+ - lib/stoplight/notifier/raven.rb
228
243
  - lib/stoplight/notifier/slack.rb
229
244
  - lib/stoplight/state.rb
230
245
  - lib/stoplight/version.rb
@@ -246,6 +261,7 @@ files:
246
261
  - spec/stoplight/notifier/honeybadger_spec.rb
247
262
  - spec/stoplight/notifier/io_spec.rb
248
263
  - spec/stoplight/notifier/logger_spec.rb
264
+ - spec/stoplight/notifier/raven_spec.rb
249
265
  - spec/stoplight/notifier/slack_spec.rb
250
266
  - spec/stoplight/notifier_spec.rb
251
267
  - spec/stoplight/state_spec.rb
@@ -271,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
287
  version: '0'
272
288
  requirements: []
273
289
  rubyforge_project:
274
- rubygems_version: 2.6.0
290
+ rubygems_version: 2.6.4
275
291
  signing_key:
276
292
  specification_version: 4
277
293
  summary: Traffic control for code.
@@ -294,6 +310,7 @@ test_files:
294
310
  - spec/stoplight/notifier/honeybadger_spec.rb
295
311
  - spec/stoplight/notifier/io_spec.rb
296
312
  - spec/stoplight/notifier/logger_spec.rb
313
+ - spec/stoplight/notifier/raven_spec.rb
297
314
  - spec/stoplight/notifier/slack_spec.rb
298
315
  - spec/stoplight/notifier_spec.rb
299
316
  - spec/stoplight/state_spec.rb