stoplight-sentry 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c1fac56cd801c5b8be0848bee64cbcbaa5976b6b3c05ab3621592130d412daa0
4
+ data.tar.gz: 45743013be1f9faaba15ac0370e827b14314d46a4cb1259e6f637605d00a1468
5
+ SHA512:
6
+ metadata.gz: 3877d10ea9d2001f23da0712ef822744476c1d51f8feffc2673a8a2cc95133905b86ee15660bbe5c9e891fe89ab3ea13e0a280ac50bec7794f6e4abf5650d138
7
+ data.tar.gz: d4fdaeaddcf2a50a44d5496de33adf374f526876c93ac00b2093d9f7c572b25214ffbbe27dfe8269a653ee768131c6171b4ff5ce131e217bdfa290d7cde9befa
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Tëma Bolshakov
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,58 @@
1
+ # Stoplight::Sentry
2
+
3
+ Sentry notifier for [Stoplight].
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'stoplight-sentry'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install stoplight-sentry
20
+
21
+ ## Usage
22
+
23
+ Make sure you have the [sentry-ruby] gem installed before configuring Stoplight.
24
+
25
+ ```ruby
26
+ require 'sentry-ruby'
27
+
28
+ notifier = Stoplight::Sentry::Notifier.new(Sentry)
29
+ # => #<Stoplight::Sentry::Notifier:...>
30
+ Stoplight::Light.default_notifiers += [notifier]
31
+ # => [#<Stoplight::Notifier::IO:...>, #<Stoplight::Sentry::Notifier:...>]
32
+ ```
33
+
34
+ you can configure notifier to add custom option to the notification:
35
+
36
+ ```ruby
37
+ notifier = Stoplight::Sentry::Notifier.new(Sentry, tags: {foo: 'bar'})
38
+ # => #<Stoplight::Sentry::Notifier:...>
39
+ Stoplight::Light.default_notifiers += [notifier]
40
+ # => [#<Stoplight::Notifier::IO:...>, #<Stoplight::Sentry::Notifier:...>]
41
+ ```
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bolshakov/stoplight-sentry.
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
56
+
57
+ [sentry-ruby]: https://github.com/getsentry/sentry-ruby
58
+ [Stoplight]: https://github.com/bolshakov/stoplight
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stoplight
4
+ module Sentry
5
+ # Usage:
6
+ #
7
+ # notifier = Stoplight::Sentry::Notifier.new(Sentry)
8
+ # Stoplight::Light.default_notifiers += [notifier]
9
+ #
10
+ class Notifier < ::Stoplight::Notifier::Base
11
+ # @!attribute sentry
12
+ # @return [::Sentry]
13
+ attr_reader :sentry
14
+
15
+ # @!attribute formatter
16
+ # @return [Proc]
17
+ attr_reader :formatter
18
+
19
+ # @!attribute options
20
+ # @return [Hash]
21
+ attr_reader :options
22
+
23
+ # @param sentry [::Sentry]
24
+ # @param formatter [Proc, nil] (Stoplight::Default::FORMATTER)
25
+ # @param options [Hash] custom options for the +Sentry#capture_message+ method
26
+ def initialize(sentry, formatter = nil, **options)
27
+ @sentry = sentry
28
+ @formatter = formatter || Stoplight::Default::FORMATTER
29
+ @options = options
30
+ end
31
+
32
+ # @param light [Stoplight::Light]
33
+ # @param from_color [String]
34
+ # @param to_color [String]
35
+ # @param error []StandardError]
36
+ # @return [String]
37
+ def notify(light, from_color, to_color, error)
38
+ formatter.(light, from_color, to_color, error).tap do |message|
39
+ options.merge(backtrace: error&.backtrace).then do |sentry_options|
40
+ sentry.capture_message(message, **sentry_options)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stoplight
4
+ module Sentry
5
+ VERSION = "0.1.0"
6
+ public_constant :VERSION
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sentry-ruby"
4
+ require "stoplight"
5
+ require_relative "sentry/version"
6
+ require_relative "sentry/notifier"
7
+
8
+ module Stoplight
9
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stoplight/sentry"
4
+
5
+ RSpec.configure do |config|
6
+ # Enable flags like --only-failures and --next-failure
7
+ config.example_status_persistence_file_path = ".rspec_status"
8
+
9
+ # Disable RSpec exposing methods globally on `Module` and `main`
10
+ config.disable_monkey_patching!
11
+
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ RSpec.describe Stoplight::Sentry::Notifier do
6
+ subject(:notify) { notifier.notify(light, from_color, to_color, error) }
7
+
8
+ let(:notifier) { described_class.new(sentry, formatter, **options) }
9
+ let(:sentry) { class_double(Sentry) }
10
+ let(:light) { instance_double(Stoplight::Light, name: "light-name") }
11
+ let(:from_color) { Stoplight::Color::GREEN }
12
+ let(:to_color) { Stoplight::Color::RED }
13
+ let(:error) { StandardError.new("something went wrong").tap { _1.set_backtrace(backtrace) } }
14
+ let(:backtrace) { ["foo", "bar"] }
15
+ let(:options) { {} }
16
+
17
+ context "when formatter is provided" do
18
+ let(:formatter) { instance_double(Proc) }
19
+ let(:message) { SecureRandom.uuid }
20
+
21
+ before do
22
+ expect(formatter).to receive(:call).with(light, from_color, to_color, error) { message }
23
+ end
24
+
25
+ it "notifies sentry" do
26
+ expect(sentry).to receive(:capture_message).with(message, backtrace: backtrace)
27
+
28
+ expect(notify).to eq(message)
29
+ end
30
+
31
+ context "with custom options" do
32
+ let(:options) { { tags: { foo: "bar" }} }
33
+
34
+ it "notifies sentry" do
35
+ expect(sentry).to receive(:capture_message).with(message, backtrace: backtrace, tags: { foo: "bar" })
36
+
37
+ expect(notify).to eq(message)
38
+ end
39
+ end
40
+ end
41
+
42
+ context "when formatter is not provided" do
43
+ let(:formatter) { nil }
44
+ let(:message) { "Switching light-name from green to red because StandardError something went wrong" }
45
+
46
+ it "notifies sentry" do
47
+ expect(sentry).to receive(:capture_message).with(message, backtrace: backtrace)
48
+
49
+ notify
50
+ end
51
+
52
+ context "with custom options" do
53
+ let(:options) { { tags: { foo: "bar" }} }
54
+
55
+ it "notifies sentry" do
56
+ expect(sentry).to receive(:capture_message).with(message, backtrace: backtrace, tags: { foo: "bar" })
57
+
58
+ expect(notify).to eq(message)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Stoplight::Sentry do
4
+ it "has a version number" do
5
+ expect(Stoplight::Sentry::VERSION).not_to be_nil
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stoplight-sentry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tëma Bolshakov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: stoplight
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sentry-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby_coding_standard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.0
55
+ description: Sentry notifier for Stoplight
56
+ email:
57
+ - either.free@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - README.md
64
+ - lib/stoplight/sentry.rb
65
+ - lib/stoplight/sentry/notifier.rb
66
+ - lib/stoplight/sentry/version.rb
67
+ - spec/spec_helper.rb
68
+ - spec/stoplight/sentry/notifier_spec.rb
69
+ - spec/stoplight/sentry_spec.rb
70
+ homepage: https://github.com/bolshakov/stoplight-sentry
71
+ licenses:
72
+ - MIT
73
+ metadata:
74
+ homepage_uri: https://github.com/bolshakov/stoplight-sentry
75
+ source_code_uri: https://github.com/bolshakov/stoplight-sentry
76
+ changelog_uri: https://github.com/bolshakov/stoplight-sentry/releases
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '2.7'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.3.7
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Sentry notifier for Stoplight
96
+ test_files:
97
+ - spec/spec_helper.rb
98
+ - spec/stoplight/sentry/notifier_spec.rb
99
+ - spec/stoplight/sentry_spec.rb