pheme 5.3.3 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1682f45cc6381c623808a02e81ec990267fb4cae120cd201d7308d1cdd04ae58
4
- data.tar.gz: 3479b1a218f9210a0dbb79f03bbed0938f60610cc6586f44de4e521b4e4a054f
3
+ metadata.gz: 5c1f36f4d154e2fbd0ef4c5ff2c883e73568ac9ff6f7db10d555eba44f571241
4
+ data.tar.gz: e07dea65651b220d142bda320ae759d2bafc2a4c88ca480f353755ad7d7e08df
5
5
  SHA512:
6
- metadata.gz: 9a70cdc3830479b6d971a7fa8610719d8da84cccbcd11c3f053250684051c6ce23239e5210fdfe1cb8225011a2c8820ffe7ac4f4f04fd46328840be8eb57cea8
7
- data.tar.gz: c7451b4b7f28b9d2f0046c7ba35867471a50369e2042b8b52f25c65cac4f19aeed82a0189f477be60b2a9c2de918e85ef5013324c7bff90628cf8e034edeec38
6
+ metadata.gz: 790ad3e1a93632eafa4f591c49dc51999becc8746abe433c6f972cfc07c0d17cc07e8402b75b74e6368006bb48633c1ad9d10dc1f190e1bb1965c7fd0295dc50
7
+ data.tar.gz: 790646a9e3f3a14695f3f6cba9d9954eaf09e1579da1b8bb49a9e70fb42b58b20d19114eb2f3669cd53716830add50e1a53fb0ab0b7d766df020a8a5cf1b865e
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: Default
3
+
4
+ on:
5
+ push:
6
+
7
+ concurrency:
8
+ group: ${{ github.workflow }}-${{ github.ref }}
9
+ cancel-in-progress: true
10
+
11
+ jobs:
12
+ build_and_publish:
13
+ name: Build and Publish
14
+ uses: wealthsimple/public-github-workflows/.github/workflows/ruby-gem-build.yaml@main
15
+ secrets: inherit
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2024-06-14 14:59:19 UTC using RuboCop version 1.64.1.
3
+ # on 2024-07-04 21:40:31 UTC using RuboCop version 1.64.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -19,20 +19,19 @@ RSpec/NoExpectationExample:
19
19
  - 'spec/logger_spec.rb'
20
20
  - 'spec/queue_poller_spec.rb'
21
21
 
22
- # Offense count: 9
22
+ # Offense count: 8
23
23
  # Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
24
24
  # Include: **/*_spec.rb
25
25
  RSpec/SpecFilePathFormat:
26
26
  Exclude:
27
27
  - 'spec/configuration_spec.rb'
28
+ - 'spec/error_reporting_spec.rb'
28
29
  - 'spec/logger_spec.rb'
29
30
  - 'spec/message_handler_spec.rb'
30
31
  - 'spec/message_type/aws_event_spec.rb'
31
32
  - 'spec/message_type/sns_message_spec.rb'
32
33
  - 'spec/queue_poller_spec.rb'
33
- - 'spec/rollbar_spec.rb'
34
34
  - 'spec/topic_publisher_spec.rb'
35
- - 'spec/version_spec.rb'
36
35
 
37
36
  # Offense count: 2
38
37
  # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
data/CHANGELOG.md CHANGED
@@ -1,9 +1,20 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## Unreleased
8
+
9
+ ## 6.0.0 - 2024-07-04
10
+ ### Changed
11
+ - **breaking changes** Removed support for Rollbar configuration. `config.rollbar` is no longer supported.
12
+ - Added support for passing `error_reporting_func` as a config option.
13
+
14
+ ## 5.3.4 - 2024-06-14
15
+ ### Changed
16
+ - Updated dependencies
17
+
7
18
  ## 5.3.3 - 2024-06-14
8
19
  ### Changed
9
20
  - Updated dependencies
@@ -169,7 +180,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
169
180
  ### Changed
170
181
  - Updated dependencies
171
182
 
172
- ### 5.0.4 - 2022-04-01
183
+ ## 5.0.4 - 2022-04-01
173
184
  ### Changed
174
185
  - Updated workflows
175
186
 
@@ -246,17 +257,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
246
257
  - Migrate CI from CircleCI to GitHub Actions
247
258
 
248
259
  ## 4.0.3 - 2021-03-08
260
+ ### Changed
249
261
  - Update documentation to include instructions on directly publishing to SQS
250
262
 
251
263
  ## 4.0.2 - 2020-12-17
264
+ ### Changed
252
265
  - Bump local dev version, rubocop fixes, add backstage catalog file + sonarqube project settings
253
266
 
254
267
  ## 4.0.1 - 2020-03-23
255
- ### Fixes
268
+ ### Fixed
256
269
  - Fixes 4.0.0. Instead of expecting message attributes in the message from `poll`, retrieves them from the right place.
257
270
 
258
271
  ## 4.0.0 - 2020-03-18
259
- ### Breaking Changes
272
+ ### Changed
260
273
  - Add the ability for SQS to receive message attributes
261
274
  - `handle` function of `QueuePoller` now takes a third parameter `message_attributes`
262
275
  - blocks or `MessageHandler`s passed to `QueuePoller` can use this `message_attributes`
@@ -302,6 +315,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
302
315
  ## 2.0.1 - 2019-01-03
303
316
  ### Changed
304
317
  - add internal gem spec to test standard gem behavior, reduces unnecessary copy and pasting
318
+
305
319
  ### Fixed
306
320
  - namespace for the VERSION constant was incorrectly set to Ws::Ws
307
321
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pheme (5.3.3)
4
+ pheme (6.0.0)
5
5
  activesupport (>= 4)
6
6
  aws-sdk-sns (~> 1.1)
7
7
  aws-sdk-sqs (~> 1.3)
@@ -63,13 +63,16 @@ GEM
63
63
  minitest (5.23.1)
64
64
  mutex_m (0.2.0)
65
65
  parallel (1.25.1)
66
+ parse_a_changelog (1.3.0)
67
+ treetop (~> 1.6)
66
68
  parser (3.3.3.0)
67
69
  ast (~> 2.4.1)
68
70
  racc
71
+ polyglot (0.3.5)
69
72
  process_executer (1.1.0)
70
73
  public_suffix (5.0.5)
71
74
  racc (1.8.0)
72
- rack (3.1.3)
75
+ rack (3.1.6)
73
76
  rainbow (3.1.1)
74
77
  rake (13.2.1)
75
78
  rchardet (1.8.0)
@@ -149,6 +152,8 @@ GEM
149
152
  rubocop-rails (~> 2.23.1)
150
153
  strscan (3.1.0)
151
154
  thor (1.3.1)
155
+ treetop (1.6.12)
156
+ polyglot (~> 0.3)
152
157
  tzinfo (2.0.6)
153
158
  concurrent-ruby (~> 1.0)
154
159
  unicode-display_width (2.5.0)
@@ -167,6 +172,7 @@ DEPENDENCIES
167
172
  bundler
168
173
  bundler-audit
169
174
  git
175
+ parse_a_changelog
170
176
  pheme!
171
177
  rake
172
178
  rspec
data/README.md CHANGED
@@ -34,6 +34,13 @@ Pheme.configure do |config|
34
34
  config.sqs_client = AWS_SQS_CLIENT
35
35
  config.sns_client = AWS_SNS_CLIENT
36
36
  config.logger = Logger.new(STDOUT) # Optionally replace with your app logger, e.g. `Rails.logger`
37
+
38
+ # Internal wealthsimple error handler
39
+ config.error_reporting_func = Ws::Railway::ErrorReporting.capture_exception
40
+ # Sentry
41
+ config.error_reporting_func = Sentry.capture_exception
42
+ # Rollbar
43
+ config.error_reporting_func = Rollbar.error
37
44
  end
38
45
  ```
39
46
 
@@ -17,9 +17,10 @@ module Pheme
17
17
 
18
18
  class Configuration
19
19
  ATTRIBUTES = %i[sns_client sqs_client logger].freeze
20
- OPTIONAL_ATTRIBUTES = %i[rollbar].freeze
20
+ OPTIONAL_ATTRIBUTES = %i[error_reporting_func].freeze
21
+ DEPRECATED_ATTRIBUTES = %i[rollbar].freeze
21
22
 
22
- attr_accessor(*ATTRIBUTES, *OPTIONAL_ATTRIBUTES)
23
+ attr_accessor(*ATTRIBUTES, *OPTIONAL_ATTRIBUTES, *DEPRECATED_ATTRIBUTES)
23
24
 
24
25
  def initialize
25
26
  @logger ||= Logger.new($stdout) # rubocop:disable Lint/DisjunctiveAssignmentInConstructor
@@ -32,6 +33,10 @@ module Pheme
32
33
  end
33
34
  raise "sns_client must be a Aws::SNS::Client" unless sns_client.is_a?(Aws::SNS::Client)
34
35
  raise "sns_client must be a Aws::SQS::Client" unless sqs_client.is_a?(Aws::SQS::Client)
36
+
37
+ if respond_to?(:rollbar)
38
+ @logger.warn("config.rollbar is deprecated. Please use config.error_reporting_func instead.")
39
+ end
35
40
  end
36
41
  end
37
42
  end
@@ -0,0 +1,7 @@
1
+ module Pheme
2
+ def self.capture_exception(exception, message, data = {})
3
+ return if configuration.error_reporting_func.nil?
4
+
5
+ configuration.error_reporting_func.call(exception, message, data)
6
+ end
7
+ end
@@ -69,7 +69,7 @@ module Pheme
69
69
  throw :stop_polling
70
70
  rescue StandardError => e
71
71
  Pheme.logger.error(e)
72
- Pheme.rollbar(e, "#{self.class} failed to process message", { message: content })
72
+ Pheme.capture_exception(e, "#{self.class} failed to process message", { message: content })
73
73
  end
74
74
  end
75
75
  log_polling_end(time_start)
data/lib/pheme/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pheme
2
- VERSION = '5.3.3'.freeze
2
+ VERSION = '6.0.0'.freeze
3
3
  end
data/lib/pheme.rb CHANGED
@@ -8,7 +8,7 @@ require 'smarter_csv'
8
8
  require 'pheme/version'
9
9
  require 'pheme/configuration'
10
10
  require 'pheme/logger'
11
- require 'pheme/rollbar'
11
+ require 'pheme/error_reporting'
12
12
  require 'pheme/topic_publisher'
13
13
  require 'pheme/message_handler'
14
14
  require 'pheme/queue_poller'
data/pheme.gemspec CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
 
31
31
  s.add_development_dependency 'bundler'
32
32
  s.add_development_dependency 'git'
33
+ s.add_development_dependency "parse_a_changelog"
33
34
  s.add_development_dependency 'rake'
34
35
  s.add_development_dependency 'rspec'
35
36
  s.add_development_dependency 'rspec-collection_matchers'
@@ -49,6 +49,26 @@ describe Pheme do
49
49
  expect { subject }.not_to raise_error
50
50
  end
51
51
  end
52
+
53
+ context 'deprecated attributes' do
54
+ let(:sns_client) { instance_double(Aws::SNS::Client) }
55
+ let(:sqs_client) { instance_double(Aws::SQS::Client) }
56
+
57
+ before do
58
+ allow(sns_client).to receive(:is_a?).with(Aws::SNS::Client).and_return(true)
59
+ allow(sqs_client).to receive(:is_a?).with(Aws::SQS::Client).and_return(true)
60
+
61
+ configuration.sns_client = sns_client
62
+ configuration.sqs_client = sqs_client
63
+ configuration.rollbar = double
64
+ end
65
+
66
+ it "warns if passed a deprecated config attribute" do
67
+ expect(configuration.logger).to receive(:warn).with("config.rollbar is deprecated. Please use config.error_reporting_func instead.")
68
+
69
+ expect { subject }.not_to raise_error
70
+ end
71
+ end
52
72
  end
53
73
  end
54
74
  end
@@ -0,0 +1,22 @@
1
+ RSpec.describe Pheme do
2
+ let(:error_reporting_func) { double }
3
+
4
+ describe '.capture_exception' do
5
+ subject { described_class.capture_exception(exception, message, data) }
6
+
7
+ let(:exception) { StandardError }
8
+ let(:message) { 'Unable to poll for messages' }
9
+ let(:data) { { sqs_url: 'arn::foo::bar' } }
10
+
11
+ before do
12
+ described_class.configure do |config|
13
+ config.error_reporting_func = error_reporting_func
14
+ end
15
+ end
16
+
17
+ it 'sends error message to configured error_reporter' do
18
+ expect(error_reporting_func).to receive(:call).with(exception, message, data)
19
+ subject
20
+ end
21
+ end
22
+ end
data/spec/version_spec.rb CHANGED
@@ -1,35 +1,87 @@
1
1
  require 'git'
2
+ require 'parse_a_changelog'
2
3
 
3
- describe Pheme do
4
+ RSpec.describe 'a published gem' do # rubocop:disable RSpec/DescribeClass
4
5
  def get_version(git, branch = 'HEAD')
5
6
  git.grep('VERSION = ', 'lib/*/version.rb', { object: branch }).
6
7
  map { |_sha, matches| matches.first[1] }.
7
- filter_map { |version_string| parse_version(version_string) }.
8
+ filter_map { |str| parse_version(str) }.
8
9
  first
10
+ rescue Git::GitExecuteError
11
+ # Catches failures for branch name being master
12
+ nil
9
13
  end
10
14
 
11
15
  def parse_version(string)
12
16
  string.match(/VERSION = ['"](.*)['"]/)[1]
13
17
  end
14
18
 
19
+ def main_branch
20
+ @main_branch ||=
21
+ if git.branches['origin/main']
22
+ 'origin/main'
23
+ elsif git.branches['origin/master']
24
+ 'origin/master'
25
+ else
26
+ raise StandardError,
27
+ <<~ERROR
28
+ Couldn't determine main branch.
29
+ Does 'origin/main' or 'origin/master' need to be fetched?
30
+ ERROR
31
+ end
32
+ end
33
+
34
+ def needs_version_bump?
35
+ base = git.merge_base(main_branch, 'HEAD').first&.sha
36
+ base ||= main_branch
37
+ git.diff(base, 'HEAD').any? { |diff|
38
+ not_gemfile?(diff) && not_dotfile?(diff) && not_docs?(diff) && not_spec?(diff)
39
+ }
40
+ end
41
+
42
+ def not_gemfile?(diff)
43
+ ['Gemfile', 'Gemfile.lock'].exclude?(diff.path)
44
+ end
45
+
46
+ def not_docs?(diff)
47
+ !diff.path.end_with?('.md')
48
+ end
49
+
50
+ def not_spec?(diff)
51
+ !diff.path.start_with?('spec/')
52
+ end
53
+
54
+ def not_dotfile?(diff)
55
+ # Ignore dotfiles, like .gitignore and CI files like .github/...
56
+ !diff.path.start_with?('.')
57
+ end
58
+
59
+ let(:git) { Git.open('.') }
60
+ let(:head_version) { get_version(git, 'HEAD') }
61
+
15
62
  it 'has a version number' do
16
- git = Git.open('.')
17
- head_version = get_version(git, 'HEAD')
18
63
  expect(head_version).not_to be_nil
19
64
  end
20
65
 
21
- it 'has a bumped version' do
22
- git = Git.open('.')
23
- main_version = get_version(git, 'origin/main')
66
+ it 'has a bumped version committed' do
67
+ main_version = get_version(git, main_branch)
24
68
  skip('first time publishing, no need to compare versions') if main_version.nil?
25
69
 
26
- is_main_branch = git.current_branch == 'main'
70
+ is_main_branch = git.current_branch == main_branch
27
71
  skip('already on main branch, no need to compare versions') if is_main_branch
28
72
 
29
- head_version = get_version(git, 'HEAD')
30
- puts "head_version " + head_version
31
- raise 'no version.rb file found on the current branch' if head_version.nil?
73
+ skip('Diff only contains non-code changes, no need to bump version') unless needs_version_bump?
32
74
 
33
75
  expect(Gem::Version.new(head_version)).to be > Gem::Version.new(main_version)
34
76
  end
77
+
78
+ it 'has a CHANGELOG.md file' do
79
+ expect(File).to exist('CHANGELOG.md')
80
+ end
81
+
82
+ it 'has changelog entry for current version' do
83
+ parser = ParseAChangelog.parse('CHANGELOG.md')
84
+ versions = parser.elements[2].elements.map { |element| element.elements[1].text_value }
85
+ expect(versions.first).to include(head_version)
86
+ end
35
87
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pheme
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.3
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Graham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-14 00:00:00.000000000 Z
11
+ date: 2024-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: parse_a_changelog
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rake
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -215,7 +229,7 @@ extra_rdoc_files: []
215
229
  files:
216
230
  - ".github/CODEOWNERS"
217
231
  - ".github/PULL_REQUEST_TEMPLATE.md"
218
- - ".github/workflows/main.yml"
232
+ - ".github/workflows/default.yaml"
219
233
  - ".github/workflows/stale.yml"
220
234
  - ".gitignore"
221
235
  - ".rspec"
@@ -233,23 +247,23 @@ files:
233
247
  - lib/pheme.rb
234
248
  - lib/pheme/compression.rb
235
249
  - lib/pheme/configuration.rb
250
+ - lib/pheme/error_reporting.rb
236
251
  - lib/pheme/logger.rb
237
252
  - lib/pheme/message_handler.rb
238
253
  - lib/pheme/message_type/aws_event.rb
239
254
  - lib/pheme/message_type/sns_message.rb
240
255
  - lib/pheme/queue_poller.rb
241
- - lib/pheme/rollbar.rb
242
256
  - lib/pheme/topic_publisher.rb
243
257
  - lib/pheme/version.rb
244
258
  - pheme.gemspec
245
259
  - sonar-project.properties
246
260
  - spec/configuration_spec.rb
261
+ - spec/error_reporting_spec.rb
247
262
  - spec/logger_spec.rb
248
263
  - spec/message_handler_spec.rb
249
264
  - spec/message_type/aws_event_spec.rb
250
265
  - spec/message_type/sns_message_spec.rb
251
266
  - spec/queue_poller_spec.rb
252
- - spec/rollbar_spec.rb
253
267
  - spec/spec_helper.rb
254
268
  - spec/support/example_aws_event_queue_poller.rb
255
269
  - spec/support/example_message_handler.rb
@@ -1,58 +0,0 @@
1
- ---
2
- name: Pipeline
3
- on:
4
- push:
5
- concurrency:
6
- group: ${{ github.workflow }}-${{ github.ref }}
7
- cancel-in-progress: true
8
-
9
- jobs:
10
- build:
11
- name: Build
12
- runs-on: ubuntu-22.04
13
- strategy:
14
- matrix:
15
- ruby-version: [3.1.4, 3.2.3, 3.3.0]
16
- steps:
17
- - uses: actions/checkout@v3
18
- with:
19
- fetch-depth: 0
20
- - name: Set up Ruby ${{ matrix.ruby-version }}
21
- uses: ruby/setup-ruby@v1
22
- with:
23
- bundler-cache: true
24
- ruby-version: ${{ matrix.ruby-version }}
25
- - name: Lint
26
- run: bundle exec rubocop
27
- - name: Test
28
- run: bundle exec rspec
29
-
30
- # Separate `release` job from `build`, as we only want release to be run once
31
- # and not run for each ruby version in the matrix:
32
- release:
33
- name: Release
34
- if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
35
- needs: build
36
- runs-on: ubuntu-22.04
37
- steps:
38
- - uses: actions/checkout@v3
39
- with:
40
- fetch-depth: 0
41
- - name: Set up Ruby
42
- uses: ruby/setup-ruby@v1
43
- with:
44
- bundler-cache: true
45
- - name: Release the gem
46
- run: |
47
- mkdir -p ~/.gem
48
- cat << EOF > ~/.gem/credentials
49
- ---
50
- :github: Bearer ${GITHUB_TOKEN}
51
- :rubygems_api_key: ${RUBYGEMS_API_KEY}
52
- EOF
53
- chmod 0600 ~/.gem/credentials
54
- git config user.email "noreply@wealthsimple.com"
55
- git config user.name "Wolfbot"
56
- bundle exec rake release
57
- env:
58
- RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
data/lib/pheme/rollbar.rb DELETED
@@ -1,7 +0,0 @@
1
- module Pheme
2
- def self.rollbar(exception, message, data = {})
3
- return if configuration.rollbar.nil?
4
-
5
- configuration.rollbar.error(exception, message, data)
6
- end
7
- end
data/spec/rollbar_spec.rb DELETED
@@ -1,22 +0,0 @@
1
- RSpec.describe Pheme do
2
- let(:rollbar) { double }
3
-
4
- describe '.rollbar' do
5
- subject { described_class.rollbar(exception, message, data) }
6
-
7
- let(:exception) { StandardError }
8
- let(:message) { 'Unable to poll for messages' }
9
- let(:data) { { sqs_url: 'arn::foo::bar' } }
10
-
11
- before do
12
- described_class.configure do |config|
13
- config.rollbar = rollbar
14
- end
15
- end
16
-
17
- it 'sends error message to rollbar' do
18
- expect(rollbar).to receive(:error).with(exception, message, data)
19
- subject
20
- end
21
- end
22
- end