diffend 0.2.23 → 0.2.24

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: 5ce266f8f72de49360adc1e6e1f79c8bf5fa08727ffc990292877c015e1040ee
4
- data.tar.gz: 1a71a4a519b1f2afb9bc993726c045b4db5b87833459ba8f7192c2a2f4232aa6
3
+ metadata.gz: 5bc33803e8086ca502424fae528475182c196daf3b5971200a7988fca0936822
4
+ data.tar.gz: 138b0750cff7e555d62f82ca8716b4d21dbd32fd5c6de898fd7c7653d7c56501
5
5
  SHA512:
6
- metadata.gz: '08dd6da1d3984200d9ac07fd9fd1f9a0adf6b7746f86a77ab560b77b356dc6fad819513adea6fe2d714b1f06ed8cf5441d796681fd507b64247a2db3560d3138'
7
- data.tar.gz: 2155bbba6da089606b38d36fcec4259054f6cac053bf56eefb303d6d3aa223ba4253ca771249a2543696c636e8c509aa75ceb3ab50f055dd18a2ba9715e5cb9f
6
+ metadata.gz: bf6b14a1ca18e978b709905159b17caacb5cc5a2812ecb1b655961041e44134eed33d840ac3679b451aa49b33f2dcf7f96ffa6e5535a102f7799cf927fb8e9af
7
+ data.tar.gz: 39e1f326632af4f2f658d027ebb8277fd1b24262a9e1fd90a10747c8d85e1bf7ead72c65c44716af7a4d4f06a746d0be008b1a76fb82ba88034c1b1c6cdcf04f
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,6 +1,15 @@
1
1
  # Changelog
2
2
 
3
3
  ## [Unreleased][master]
4
+
5
+ ## [0.2.24] (2020-09-08)
6
+ - better error handling of response ([#28](https://github.com/diffend-io/diffend-ruby/pull/28))
7
+ - fix jruby specs ([#29](https://github.com/diffend-io/diffend-ruby/pull/29))
8
+ - handle request server errors ([#30](https://github.com/diffend-io/diffend-ruby/pull/30))
9
+ - better detection of gem source ([#31](https://github.com/diffend-io/diffend-ruby/pull/31))
10
+ - detect if we are running outdated version of the plugin ([#32](https://github.com/diffend-io/diffend-ruby/pull/32))
11
+
12
+ ## [0.2.23] (2020-09-06)
4
13
  - fix how we build gem platform ([#26](https://github.com/diffend-io/diffend-ruby/pull/26))
5
14
  - test against jruby, ruby-2.5 and ruby-2.6 ([#25](https://github.com/diffend-io/diffend-ruby/pull/25))
6
15
 
@@ -38,7 +47,9 @@
38
47
 
39
48
  - initial release
40
49
 
41
- [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.22...HEAD
50
+ [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.24...HEAD
51
+ [0.2.24]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.23...v0.2.24
52
+ [0.2.23]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.22...v0.2.23
42
53
  [0.2.22]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.21...v0.2.22
43
54
  [0.2.21]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.20...v0.2.21
44
55
  [0.2.20]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.19...v0.2.20
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diffend (0.2.23)
4
+ diffend (0.2.24)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -27,7 +27,7 @@
27
27
  # Diffend main namespace
28
28
  module Diffend
29
29
  # Current plugin version
30
- VERSION = '0.2.23'
30
+ VERSION = '0.2.24'
31
31
  # Diffend homepage
32
32
  HOMEPAGE = 'https://diffend.io'
33
33
 
@@ -41,10 +41,13 @@ module Diffend
41
41
 
42
42
  # Execute diffend plugin
43
43
  def execute
44
+ detect_installed_version
45
+
44
46
  config = fetch_config
45
47
 
46
48
  Diffend::Voting.call(
47
49
  command,
50
+ config,
48
51
  Diffend::BuildBundlerDefinition.call(
49
52
  command,
50
53
  Bundler.default_gemfile,
@@ -60,6 +63,36 @@ module Diffend
60
63
  )
61
64
  end
62
65
 
66
+ def detect_installed_version
67
+ return if installed_version == VERSION
68
+
69
+ build_outdated_version_message(installed_version)
70
+ .tap(&Bundler.ui.method(:error))
71
+
72
+ exit 1
73
+ end
74
+
75
+ # @param version [Hash] installed version
76
+ #
77
+ # @return [String]
78
+ def build_outdated_version_message(version)
79
+ <<~MSG
80
+ \nYou are running an outdated version (#{version}) of the plugin, which will lead to issues.
81
+ \nPlease upgrade to the latest one (#{VERSION}) by executing "rm -rf .bundle/plugin".\n
82
+ MSG
83
+ end
84
+
85
+ # @return [String] installed plugin version
86
+ def installed_version
87
+ Bundler::Plugin
88
+ .index
89
+ .plugin_path('diffend')
90
+ .basename
91
+ .to_s
92
+ .split('-')
93
+ .last
94
+ end
95
+
63
96
  # Command that was run with bundle
64
97
  #
65
98
  # @return [String]
@@ -19,9 +19,7 @@ module Diffend
19
19
  ShareableKeyMissingInConfigurationFile = Class.new(BaseError)
20
20
  # Raised when build_path is missing in configuration file
21
21
  BuildPathMissingInConfigurationFile = Class.new(BaseError)
22
- # When unsupported response returned from the endpoint
23
- UnsupportedResponse = Class.new(BaseError)
24
- # When unsupported action returned from the endpoint
25
- UnsupportedAction = Class.new(BaseError)
22
+ # Raised when server-side error occurs
23
+ RequestServerError = Class.new(BaseError)
26
24
  end
27
25
  end
@@ -9,7 +9,7 @@ module Diffend
9
9
  class << self
10
10
  # Build exception payload
11
11
  #
12
- # @param exception [Exception] expection that was raised
12
+ # @param exception [Exception, NilClass] expection that was raised
13
13
  # @param payload [Hash] with versions to check
14
14
  #
15
15
  # @return [Hash]
@@ -18,9 +18,9 @@ module Diffend
18
18
  request_id: SecureRandom.uuid,
19
19
  payload: payload,
20
20
  exception: {
21
- class: exception.class,
22
- message: exception.message,
23
- backtrace: exception.backtrace
21
+ class: exception&.class,
22
+ message: exception&.message,
23
+ backtrace: exception&.backtrace
24
24
  }
25
25
  }.freeze
26
26
  end
@@ -9,6 +9,16 @@ module Diffend
9
9
  This is a bug, don't hesitate.\n
10
10
  Create an issue at https://github.com/diffend-io/diffend-ruby/issues\n
11
11
  MSG
12
+ UNSUPPORTED_RESPONSE = <<~MSG
13
+ \nAPI returned an unsupported response. We recorded this incident in our system and will review it.\n
14
+ This is a bug, don't hesitate.\n
15
+ Create an issue at https://github.com/diffend-io/diffend-ruby/issues\n
16
+ MSG
17
+ UNSUPPORTED_VERDICT = <<~MSG
18
+ \nAPI returned an unsupported verdict. We recorded this incident in our system and will review it.\n
19
+ This is a bug, don't hesitate.\n
20
+ Create an issue at https://github.com/diffend-io/diffend-ruby/issues\n
21
+ MSG
12
22
  REQUEST_ERROR = <<~MSG
13
23
  \nWe were unable to process your request at this time. We recorded this incident in our system and will review it.\n
14
24
  If you think that this is a bug, don't hesitate.\n
@@ -14,7 +14,7 @@ module Diffend
14
14
  # @param report [Boolean] if true we will report the issue to diffend
15
15
  #
16
16
  # @return [Net::HTTPResponse] response from Diffend
17
- def call(exception:, payload: {}, config:, message:, report: false)
17
+ def call(config:, message:, exception: nil, payload: {}, report: false)
18
18
  exception_payload = prepare_exception_payload(exception, payload)
19
19
 
20
20
  Bundler.ui.error(Diffend::HandleErrors::Messages::PAYLOAD_DUMP)
@@ -23,6 +23,15 @@ module Diffend
23
23
  Net::OpenTimeout,
24
24
  Net::ReadTimeout
25
25
  ].freeze
26
+ # Message displayed when server issue occured and we will retry
27
+ SERVER_ERROR_MESSAGE = 'We experienced a server-side issue, retrying...'
28
+ # List of server issues
29
+ #
30
+ # 500 - Internal Server Error
31
+ # 502 - Bad Gateway
32
+ # 503 - Service Unavailable
33
+ # 504 - Gateway Timeout
34
+ SERVER_ERRORS = [500, 502, 503, 504].freeze
26
35
  # Number of retries
27
36
  RETRIES = 3
28
37
  # Request headers
@@ -42,8 +51,25 @@ module Diffend
42
51
  retry_count ||= -1
43
52
 
44
53
  build_http(endpoint_url) do |http, uri|
45
- http.request(build_request(uri, config, payload))
54
+ response = http.request(build_request(uri, config, payload))
55
+
56
+ if SERVER_ERRORS.include?(response.code.to_i)
57
+ raise Diffend::Errors::RequestServerError, response.code.to_i
58
+ end
59
+
60
+ response
46
61
  end
62
+ rescue Diffend::Errors::RequestServerError => e
63
+ retry_count += 1
64
+
65
+ retry if handle_retry(SERVER_ERROR_MESSAGE, retry_count)
66
+
67
+ Diffend::HandleErrors::Report.call(
68
+ exception: e,
69
+ payload: payload,
70
+ config: config,
71
+ message: :request_error
72
+ )
47
73
  rescue *CONNECTION_EXCEPTIONS => e
48
74
  retry_count += 1
49
75
 
@@ -7,23 +7,33 @@ module Diffend
7
7
  # Build verdict
8
8
  #
9
9
  # @param command [String] either install or update
10
+ # @param config [OpenStruct] diffend config
10
11
  # @param definition [Bundler::Definition] definition for your source
11
- def call(command, definition)
12
+ def call(command, config, definition)
12
13
  Versions::Remote
13
- .call(command, definition)
14
- .tap { |response| build_message(command, response) }
14
+ .call(command, config, definition)
15
+ .tap { |response| build_message(command, config, response) }
15
16
  end
16
17
 
17
- def build_message(command, response)
18
+ # @param command [String] either install or update
19
+ # @param config [OpenStruct] diffend config
20
+ # @param response [Hash] response from diffend API
21
+ def build_message(command, config, response)
18
22
  if response.key?('error')
19
23
  build_error(response)
20
24
  elsif response.key?('action')
21
- build_verdict(command, response)
25
+ build_verdict(command, config, response)
22
26
  else
23
- raise UnsupportedResponse, response['action']
27
+ Diffend::HandleErrors::Report.call(
28
+ config: config,
29
+ message: :unsupported_response,
30
+ payload: response,
31
+ report: true
32
+ )
24
33
  end
25
34
  end
26
35
 
36
+ # @param response [Hash] response from diffend API
27
37
  def build_error(response)
28
38
  build_error_message(response)
29
39
  .tap(&Bundler.ui.method(:error))
@@ -31,7 +41,10 @@ module Diffend
31
41
  exit 1
32
42
  end
33
43
 
34
- def build_verdict(command, response)
44
+ # @param command [String] either install or update
45
+ # @param config [OpenStruct] diffend config
46
+ # @param response [Hash] response from diffend API
47
+ def build_verdict(command, config, response)
35
48
  case response['action']
36
49
  when 'allow'
37
50
  build_allow_message(command, response)
@@ -42,10 +55,18 @@ module Diffend
42
55
 
43
56
  exit 1
44
57
  else
45
- raise UnsupportedAction, response['action']
58
+ Diffend::HandleErrors::Report.call(
59
+ config: config,
60
+ message: :unsupported_verdict,
61
+ payload: response,
62
+ report: true
63
+ )
46
64
  end
47
65
  end
48
66
 
67
+ # @param response [Hash] response from diffend API
68
+ #
69
+ # @return [String]
49
70
  def build_error_message(response)
50
71
  <<~MSG
51
72
  \nDiffend returned an error for your request.\n
@@ -53,6 +74,10 @@ module Diffend
53
74
  MSG
54
75
  end
55
76
 
77
+ # @param command [String] either install or update
78
+ # @param response [Hash] response from diffend API
79
+ #
80
+ # @return [String]
56
81
  def build_allow_message(command, response)
57
82
  <<~MSG
58
83
  \nDiffend reported an allow verdict for #{command} command for this project.\n
@@ -61,6 +86,10 @@ module Diffend
61
86
  MSG
62
87
  end
63
88
 
89
+ # @param command [String] either install or update
90
+ # @param response [Hash] response from diffend API
91
+ #
92
+ # @return [String]
64
93
  def build_deny_message(command, response)
65
94
  <<~MSG
66
95
  \nDiffend reported a deny verdict for #{command} command for this project.\n
@@ -54,7 +54,6 @@ module Diffend
54
54
  def initialize(definition)
55
55
  @definition = definition
56
56
  @direct_dependencies = Hash[definition.dependencies.map { |val| [val.name, val] }]
57
- @main_source = definition.send(:sources).rubygems_sources.last
58
57
  # Support case without Gemfile.lock
59
58
  @locked_specs = @definition.locked_gems ? @definition.locked_gems.specs : []
60
59
  end
@@ -150,17 +149,17 @@ module Diffend
150
149
  #
151
150
  # @return [String]
152
151
  def build_spec_platform(spec, locked_spec)
153
- spec.platform || locked_spec&.platform || build_spec_generic_platform(spec)
152
+ parse_platform(
153
+ spec.platform || locked_spec&.platform || spec.send(:generic_local_platform)
154
+ )
154
155
  end
155
156
 
156
- # Build gem generic platform
157
+ # Parse gem platform
157
158
  #
158
- # @param spec [Bundler::StubSpecification, Bundler::LazySpecification, Gem::Specification]
159
+ # @param platform [String, Gem::Platform]
159
160
  #
160
161
  # @return [String]
161
- def build_spec_generic_platform(spec)
162
- platform = spec.send(:generic_local_platform)
163
-
162
+ def parse_platform(platform)
164
163
  case platform
165
164
  when String then platform
166
165
  when Gem::Platform then platform.os
@@ -176,7 +175,7 @@ module Diffend
176
175
  case source
177
176
  when Bundler::Source::Metadata
178
177
  GEM_SOURCES_TYPES[:local]
179
- when Bundler::Source::Rubygems
178
+ when Bundler::Source::Rubygems, Bundler::Source::Rubygems::Remote
180
179
  GEM_SOURCES_TYPES[:gemfile_source]
181
180
  when Bundler::Source::Git
182
181
  GEM_SOURCES_TYPES[:gemfile_git]
@@ -207,10 +206,20 @@ module Diffend
207
206
  #
208
207
  # @return [Bundler::Source] gem source type
209
208
  def source_for_spec(spec)
210
- if @direct_dependencies.key?(spec.name)
211
- @direct_dependencies[spec.name].source || @main_source
212
- else
209
+ return spec.remote if spec.remote
210
+
211
+ case spec.source
212
+ when Bundler::Source::Rubygems
213
+ spec
214
+ .source
215
+ .send(:remote_specs)
216
+ .search(Bundler::Dependency.new(spec.name, spec.version))
217
+ .last
218
+ .remote
219
+ when Bundler::Source::Metadata, Bundler::Source::Git, Bundler::Source::Path
213
220
  spec.source
221
+ else
222
+ raise ArgumentError, "unknown source #{spec.source.class}"
214
223
  end
215
224
  end
216
225
 
@@ -223,10 +232,10 @@ module Diffend
223
232
  case source
224
233
  when Bundler::Source::Metadata
225
234
  ''
226
- when Bundler::Source::Rubygems
227
- source_name(source.remotes.first)
235
+ when Bundler::Source::Rubygems::Remote
236
+ source_name(source.anonymized_uri)
228
237
  when Bundler::Source::Git
229
- source.uri
238
+ source.instance_variable_get(:@safe_uri)
230
239
  when Bundler::Source::Path
231
240
  source.path
232
241
  else
@@ -234,11 +243,11 @@ module Diffend
234
243
  end
235
244
  end
236
245
 
237
- # @param name [Bundler::URI]
246
+ # @param uri [Bundler::URI]
238
247
  #
239
- # @return [String] cleaned source name
240
- def source_name(name)
241
- name.to_s[0...-1]
248
+ # @return [String]
249
+ def source_name(uri)
250
+ uri.to_s[0...-1]
242
251
  end
243
252
 
244
253
  # Build sources used in the Gemfile
@@ -20,9 +20,8 @@ module Diffend
20
20
  class << self
21
21
  # @param command [String] either install or update
22
22
  # @param definition [Bundler::Definition] definition for your source
23
- def call(command, definition)
24
- config = fetch_config
25
-
23
+ # @param config [OpenStruct] diffend config
24
+ def call(command, config, definition)
26
25
  payload = payload(command, config.project_id, definition)
27
26
 
28
27
  response = Diffend::Request.call(
@@ -35,7 +34,7 @@ module Diffend
35
34
  rescue StandardError => e
36
35
  Diffend::HandleErrors::Report.call(
37
36
  exception: e,
38
- payload: payload,
37
+ payload: payload || {},
39
38
  config: config,
40
39
  message: :unhandled_exception,
41
40
  report: true
@@ -187,17 +186,6 @@ module Diffend
187
186
  tags
188
187
  end
189
188
 
190
- # Fetch diffend config file
191
- #
192
- # @return [OpenStruct, nil] configuration object
193
- #
194
- # @raise [Errors::MissingConfigurationFile] when no config file
195
- def fetch_config
196
- Config::Fetcher.call(
197
- File.expand_path('..', Bundler.bin_path)
198
- )
199
- end
200
-
201
189
  # Provides diffend command endpoint url
202
190
  #
203
191
  # @param command [String] either install or update
@@ -10,6 +10,6 @@ project_id = nil
10
10
  gemfile = ARGV[0]
11
11
  lockfile = ARGV[1]
12
12
 
13
- definition = Bundler::Definition.build(gemfile, lockfile, true)
13
+ definition = Diffend::BuildBundlerDefinition.call(command, gemfile lockfile)
14
14
 
15
15
  pp Diffend::Voting::Versions::Remote.payload(command, project_id, definition)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diffend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.23
4
+ version: 0.2.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Pajor
@@ -34,7 +34,7 @@ cert_chain:
34
34
  9MmF6uCQa1EjK2p8tYT0MnbHrFkoehxdX4VO9y99GAkhZyJNKPYPtyAUFV27sT2V
35
35
  LfCJRk4ifKIN/FUCwDSn8Cz0m6oH265q0p6wdzI6qrWOjP8tGOMBTA==
36
36
  -----END CERTIFICATE-----
37
- date: 2020-09-06 00:00:00.000000000 Z
37
+ date: 2020-09-08 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: bundler
metadata.gz.sig CHANGED
Binary file