flipper-notifications 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rails-tests.yml +31 -0
- data/.github/workflows/ruby-tests.yml +31 -0
- data/.github/workflows/style-check.yml +30 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +9 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +49 -12
- data/flipper-notifications.gemspec +2 -2
- data/images/flipper-notifications.png +0 -0
- data/lib/flipper/notifications/configuration.rb +2 -0
- data/lib/flipper/notifications/event_serializer.rb +2 -0
- data/lib/flipper/notifications/feature_event.rb +2 -0
- data/lib/flipper/notifications/features_subscriber.rb +2 -0
- data/lib/flipper/notifications/jobs/webhook_notification_job.rb +2 -0
- data/lib/flipper/notifications/notifiers/webhook_notifier.rb +2 -0
- data/lib/flipper/notifications/railtie.rb +2 -0
- data/lib/flipper/notifications/version.rb +1 -1
- data/lib/flipper/notifications/webhooks/errors.rb +4 -0
- data/lib/flipper/notifications/webhooks/serializer.rb +2 -0
- data/lib/flipper/notifications/webhooks/slack.rb +2 -0
- data/lib/flipper/notifications/webhooks/webhook.rb +2 -0
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fac8c375a1f9e69c790e85c4bdb7d6baf53327e6fcd3db9cbafb69a69bc235ed
|
4
|
+
data.tar.gz: ae854c74b8a3e62e1c23701566fabbc3fef1d81e49be3d377e16855e312022a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a565d1fb16d6c66c3a5900e4e278088bbefc0c05639398928d87539eb60571e9bcc09c761fd0a6624785f8b5f9a19db73097a73696eff9a928d7da3eee827d2
|
7
|
+
data.tar.gz: 54bc9009ecf98dcdddd8b6c830b130041aee4a93f1dcb41178f8c6910672d8b05b3fe392eaa6c0ead2ecf5167a739abccedcc90012f333348b2f9b31d6150bcb
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Tests (Rails app)
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- '*'
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby_version:
|
17
|
+
- 3.1
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby_version }}
|
24
|
+
- name: Ruby version
|
25
|
+
run: ruby -v
|
26
|
+
- name: Install dependencies
|
27
|
+
working-directory: spec/rails/defaults
|
28
|
+
run: bundle install
|
29
|
+
- name: Run tests
|
30
|
+
working-directory: spec/rails/defaults
|
31
|
+
run: bin/rails test
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Tests (Ruby)
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- '*'
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby_version:
|
17
|
+
- 3.0
|
18
|
+
- 3.1
|
19
|
+
- 3.2
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v2
|
22
|
+
- name: Set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby_version }}
|
26
|
+
- name: Ruby version
|
27
|
+
run: ruby -v
|
28
|
+
- name: Install dependencies
|
29
|
+
run: bundle install
|
30
|
+
- name: Run tests
|
31
|
+
run: bundle exec rspec
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Style Check
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches:
|
13
|
+
- main
|
14
|
+
pull_request:
|
15
|
+
branches:
|
16
|
+
- '*'
|
17
|
+
|
18
|
+
jobs:
|
19
|
+
rubocop:
|
20
|
+
runs-on: ubuntu-latest
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- name: Set up Ruby
|
24
|
+
uses: ruby/setup-ruby@v1
|
25
|
+
with:
|
26
|
+
ruby-version: 3.1
|
27
|
+
- name: Install dependencies
|
28
|
+
run: bundle install
|
29
|
+
- name: Run Rubocop
|
30
|
+
run: bundle exec rubocop -D
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
AllCops:
|
2
2
|
NewCops: enable
|
3
3
|
SuggestExtensions: false
|
4
|
+
Exclude:
|
5
|
+
- "Gemfile"
|
6
|
+
- "flipper-notifications.gemspec"
|
7
|
+
- "Rakefile"
|
8
|
+
- "bin/*"
|
9
|
+
- "spec/rails/**/*"
|
10
|
+
|
11
|
+
Layout/EmptyLinesAroundClassBody:
|
12
|
+
EnforcedStyle: empty_lines_except_namespace
|
4
13
|
|
5
14
|
Layout/HashAlignment:
|
6
15
|
EnforcedColonStyle: table
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at
|
58
|
+
reported by contacting the project team at jlubrano@wrapbook.com. All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/wrapbook/flipper-notifications" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in flipper-notifications.gemspec
|
6
6
|
gemspec
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
Rails-compatible Slack notifications when [Flipper](https://github.com/jnunemaker/flipper)
|
4
4
|
flags are updated.
|
5
5
|
|
6
|
+
![FlipperNotification](images/flipper-notifications.png)
|
7
|
+
|
6
8
|
## Installation
|
7
9
|
|
8
10
|
Add this line to your application's Gemfile:
|
@@ -24,7 +26,7 @@ Or install it yourself as:
|
|
24
26
|
* Ruby 3
|
25
27
|
* ActiveSupport 7
|
26
28
|
|
27
|
-
This gem is designed to work within a Rails app.
|
29
|
+
This gem is designed to work within a Rails app. At the very least, you will
|
28
30
|
need `activesupport` since that library drives instrumentation from Flipper
|
29
31
|
itself.
|
30
32
|
|
@@ -53,12 +55,47 @@ end
|
|
53
55
|
|
54
56
|
### Implementing Your Own Webhooks
|
55
57
|
|
56
|
-
|
58
|
+
This gem provides an implementation to send notifications to Slack via an
|
59
|
+
[incoming webhook](https://api.slack.com/messaging/webhooks).
|
60
|
+
If you want to integrate with a service other than Slack, you may wish to
|
61
|
+
implement your own `Webhook` by following the pattern established by this gem.
|
62
|
+
If you implement your own `Webhook`, and you have a Rails app that uses `ActiveJob`,
|
63
|
+
you can use the `Flipper::Notifications::WebhookNotificationJob` provided by this
|
64
|
+
gem to send webhook requests asynchronously. The job also includes a sensible
|
65
|
+
retry strategy just in case the internet or your notification service is having a bad day.
|
66
|
+
|
67
|
+
Your `Webhook` can start by inheriting from `Flipper::Notifications::Webhook`.
|
68
|
+
The `Webhook` base class defines an initializer that takes one keyword argument, `url`.
|
69
|
+
You only need to implement an instance method named `notify`. The `notify` method
|
70
|
+
should take keyword arguments. Within the `notify` method you have access to
|
71
|
+
[HTTParty](https://github.com/jnunemaker/httparty) methods for sending requests.
|
72
|
+
In the end, your `Webhook` might look something like this:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
class MyWebhook < Flipper::Notifications::Webhook
|
76
|
+
|
77
|
+
def notify(foo:, bar:)
|
78
|
+
webhook_api_errors do
|
79
|
+
self.class.post(@url, body: { foo: foo, bar: bar }.to_json)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
The `webhook_api_errors` helper wraps common API errors as specific `Flipper::Notifications`
|
87
|
+
error types:
|
88
|
+
|
89
|
+
* `Flipper::Notifications::ClientError` - 4XX HTTP responses
|
90
|
+
* `Flipper::Notifications::ServerError` - 5XX HTTP responses
|
91
|
+
* `Flipper::Notifications::NetworkError` - Timeouts
|
57
92
|
|
58
93
|
### Implementing Your Own Notifiers
|
59
94
|
|
95
|
+
You may want to implement notifications without using the `Webhook` pattern
|
96
|
+
described above. If so, all you have to do is implement your own `Notifier`.
|
60
97
|
A `Notifier` is any object that responds to a `call` method with a keyword
|
61
|
-
argument named `event`.
|
98
|
+
argument named `event`. You can use a `lambda` as your notifier if you prefer.
|
62
99
|
Using a `lambda` can come in handy if you want to provide additional context
|
63
100
|
to your notifications.
|
64
101
|
|
@@ -68,41 +105,41 @@ Flipper::Notifications.configure do |config|
|
|
68
105
|
|
69
106
|
notifier = ->(event:) do
|
70
107
|
context = "#{Rails.env} (changed by: #{Current.user.email})"
|
71
|
-
WebhookNotificationJob.perform_later(webhook: webhook, event: event, context_markdown: context)
|
108
|
+
Flipper::Notifications::WebhookNotificationJob.perform_later(webhook: webhook, event: event, context_markdown: context)
|
72
109
|
end
|
73
110
|
|
74
111
|
config.notifiers = [notifier]
|
75
112
|
end
|
76
113
|
```
|
77
114
|
|
115
|
+
The `event` object will be a `Flipper::Notifications::FeatureEvent`.
|
116
|
+
|
78
117
|
## Development
|
79
118
|
|
80
119
|
After checking out the repo, run `bin/setup` to install dependencies.
|
81
|
-
Then, run `
|
120
|
+
Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an
|
82
121
|
interactive prompt that will allow you to experiment.
|
83
122
|
|
84
123
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
85
|
-
To release a new version, update the version number in `version.rb`,
|
86
|
-
and then run `bundle exec rake release`, which will create a git tag for the
|
87
|
-
version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
88
124
|
|
89
125
|
## Releasing
|
90
126
|
|
91
|
-
After merging in the new functionality to the main branch
|
127
|
+
After merging in the new functionality to the main branch, you can run the following
|
128
|
+
to push a new version of the gem to [rubygems.org](https://rubygems.org):
|
92
129
|
|
93
130
|
```
|
94
131
|
git checkout main
|
95
|
-
git pull
|
132
|
+
git pull
|
96
133
|
bundle exec rake version:bump:<major, minor, or patch>
|
97
134
|
bundle exec rubocop -a
|
98
|
-
git commit -a --amend
|
135
|
+
git commit -a --amend --no-edit
|
99
136
|
bundle exec rake release
|
100
137
|
```
|
101
138
|
|
102
139
|
## Contributing
|
103
140
|
|
104
141
|
Bug reports and pull requests are welcome on GitHub at
|
105
|
-
https://github.com/
|
142
|
+
https://github.com/wrapbook/flipper-notifications. This project is intended to
|
106
143
|
be a safe, welcoming space for collaboration, and contributors are expected to
|
107
144
|
adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
108
145
|
|
@@ -8,10 +8,10 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = "flipper-notifications"
|
9
9
|
spec.version = Flipper::Notifications::VERSION
|
10
10
|
spec.authors = ["Joel Lubrano"]
|
11
|
-
spec.email = ["
|
11
|
+
spec.email = ["jlubrano@wrapbook.com"]
|
12
12
|
|
13
13
|
spec.summary = %q{Rails-compatible Slack notifications for Flipper feature flags}
|
14
|
-
spec.homepage = "https://github.com/
|
14
|
+
spec.homepage = "https://github.com/wrapbook/flipper-notifications"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
Binary file
|
@@ -6,6 +6,7 @@ require_relative "feature_event"
|
|
6
6
|
module Flipper
|
7
7
|
module Notifications
|
8
8
|
class EventSerializer < ActiveJob::Serializers::ObjectSerializer
|
9
|
+
|
9
10
|
def serialize?(argument)
|
10
11
|
argument.is_a?(FeatureEvent)
|
11
12
|
end
|
@@ -20,6 +21,7 @@ module Flipper
|
|
20
21
|
def deserialize(hash)
|
21
22
|
FeatureEvent.new(**hash.symbolize_keys.slice(:feature_name, :operation))
|
22
23
|
end
|
24
|
+
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -6,6 +6,7 @@ require_relative "feature_event"
|
|
6
6
|
module Flipper
|
7
7
|
module Notifications
|
8
8
|
class FeaturesSubscriber
|
9
|
+
|
9
10
|
def call(*args)
|
10
11
|
return unless enabled?
|
11
12
|
|
@@ -18,6 +19,7 @@ module Flipper
|
|
18
19
|
def enabled?
|
19
20
|
Flipper::Notifications.configuration.enabled?
|
20
21
|
end
|
22
|
+
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -6,6 +6,7 @@ require "flipper/notifications/webhooks/errors"
|
|
6
6
|
module Flipper
|
7
7
|
module Notifications
|
8
8
|
class WebhookNotificationJob < ActiveJob::Base
|
9
|
+
|
9
10
|
# TODO: Pull queue from configuration?
|
10
11
|
# queue_as :low
|
11
12
|
|
@@ -17,6 +18,7 @@ module Flipper
|
|
17
18
|
def perform(webhook:, **webhook_args)
|
18
19
|
webhook.notify(**webhook_args)
|
19
20
|
end
|
21
|
+
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -6,6 +6,7 @@ module Flipper
|
|
6
6
|
module Notifications
|
7
7
|
module Notifiers
|
8
8
|
class WebhookNotifier
|
9
|
+
|
9
10
|
def initialize(webhook:)
|
10
11
|
@webhook = webhook
|
11
12
|
end
|
@@ -13,6 +14,7 @@ module Flipper
|
|
13
14
|
def call(event:)
|
14
15
|
WebhookNotificationJob.perform_later(webhook: @webhook, event: event)
|
15
16
|
end
|
17
|
+
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -7,6 +7,7 @@ require "flipper/notifications/notifiers/webhook_notifier"
|
|
7
7
|
module Flipper
|
8
8
|
module Notifications
|
9
9
|
class Railtie < Rails::Railtie
|
10
|
+
|
10
11
|
initializer "flipper-notifications.configure_rails_initialization" do
|
11
12
|
Flipper::Notifications.subscribe!
|
12
13
|
|
@@ -15,6 +16,7 @@ module Flipper
|
|
15
16
|
Webhooks::Serializer
|
16
17
|
]
|
17
18
|
end
|
19
|
+
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -4,6 +4,7 @@ module Flipper
|
|
4
4
|
module Notifications
|
5
5
|
module Webhooks
|
6
6
|
class ApiError < StandardError
|
7
|
+
|
7
8
|
def initialize(response)
|
8
9
|
@response = response
|
9
10
|
end
|
@@ -11,6 +12,7 @@ module Flipper
|
|
11
12
|
def message
|
12
13
|
"Webhook API call resulted in #{@response.code} response: #{@response.body}"
|
13
14
|
end
|
15
|
+
|
14
16
|
end
|
15
17
|
|
16
18
|
class ClientError < ApiError; end
|
@@ -18,6 +20,7 @@ module Flipper
|
|
18
20
|
class ServerError < ApiError; end
|
19
21
|
|
20
22
|
class NetworkError < ApiError
|
23
|
+
|
21
24
|
def initialize(cause)
|
22
25
|
@cause = cause
|
23
26
|
end
|
@@ -25,6 +28,7 @@ module Flipper
|
|
25
28
|
def message
|
26
29
|
"Webhook API call network error: #{cause.class.name} - #{cause.message}"
|
27
30
|
end
|
31
|
+
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
@@ -7,6 +7,7 @@ module Flipper
|
|
7
7
|
module Notifications
|
8
8
|
module Webhooks
|
9
9
|
class Serializer < ActiveJob::Serializers::ObjectSerializer
|
10
|
+
|
10
11
|
def serialize?(argument)
|
11
12
|
argument.is_a?(Webhook)
|
12
13
|
end
|
@@ -21,6 +22,7 @@ module Flipper
|
|
21
22
|
def deserialize(hash)
|
22
23
|
hash["class"].constantize.new(**hash["attributes"].deep_symbolize_keys)
|
23
24
|
end
|
25
|
+
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -7,6 +7,7 @@ module Flipper
|
|
7
7
|
module Notifications
|
8
8
|
module Webhooks
|
9
9
|
class Webhook
|
10
|
+
|
10
11
|
include HTTParty
|
11
12
|
|
12
13
|
default_timeout 5 # seconds
|
@@ -40,6 +41,7 @@ module Flipper
|
|
40
41
|
rescue Errno::ECONNRESET, Timeout::Error => e
|
41
42
|
raise NetworkError, e
|
42
43
|
end
|
44
|
+
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-notifications
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Lubrano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -180,11 +180,14 @@ dependencies:
|
|
180
180
|
version: '7.0'
|
181
181
|
description:
|
182
182
|
email:
|
183
|
-
-
|
183
|
+
- jlubrano@wrapbook.com
|
184
184
|
executables: []
|
185
185
|
extensions: []
|
186
186
|
extra_rdoc_files: []
|
187
187
|
files:
|
188
|
+
- ".github/workflows/rails-tests.yml"
|
189
|
+
- ".github/workflows/ruby-tests.yml"
|
190
|
+
- ".github/workflows/style-check.yml"
|
188
191
|
- ".gitignore"
|
189
192
|
- ".rspec"
|
190
193
|
- ".rubocop.yml"
|
@@ -198,6 +201,7 @@ files:
|
|
198
201
|
- bin/console
|
199
202
|
- bin/setup
|
200
203
|
- flipper-notifications.gemspec
|
204
|
+
- images/flipper-notifications.png
|
201
205
|
- lib/flipper/notifications.rb
|
202
206
|
- lib/flipper/notifications/configuration.rb
|
203
207
|
- lib/flipper/notifications/event_serializer.rb
|
@@ -212,13 +216,13 @@ files:
|
|
212
216
|
- lib/flipper/notifications/webhooks/serializer.rb
|
213
217
|
- lib/flipper/notifications/webhooks/slack.rb
|
214
218
|
- lib/flipper/notifications/webhooks/webhook.rb
|
215
|
-
homepage: https://github.com/
|
219
|
+
homepage: https://github.com/wrapbook/flipper-notifications
|
216
220
|
licenses:
|
217
221
|
- MIT
|
218
222
|
metadata:
|
219
|
-
homepage_uri: https://github.com/
|
220
|
-
source_code_uri: https://github.com/
|
221
|
-
changelog_uri: https://github.com/
|
223
|
+
homepage_uri: https://github.com/wrapbook/flipper-notifications
|
224
|
+
source_code_uri: https://github.com/wrapbook/flipper-notifications
|
225
|
+
changelog_uri: https://github.com/wrapbook/flipper-notifications/releases
|
222
226
|
post_install_message:
|
223
227
|
rdoc_options: []
|
224
228
|
require_paths:
|