diffend 0.2.18 → 0.2.26

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: a0a5718a6d7b90225e8a9d3dd8aff55c3bc8e84dced09b84f6a575a4decf002f
4
- data.tar.gz: '006843f27693e587008b3bf25676203050329460814e9f94ffd6f4af1cc4a8df'
3
+ metadata.gz: f22ef308037176744a8795a6371eb3340f01d597b706c66e45b8355dbf2d41a9
4
+ data.tar.gz: 1e5734925c51663f20e804ecef8d329f7b24a05dfce891b33366f1e867edbf78
5
5
  SHA512:
6
- metadata.gz: 6040014adc4dac35c1f42fd663c5ad95a96a5b68e5b4591387c9be4d91840312ed1b8c4fe9fab17f6c410b225b11c31236f66bb131986c09d0f28538ac2e6ea7
7
- data.tar.gz: bf93737d117bc09a8fc9698b9b431459f6805dd4c4a35757d3a1c8e1a02c442cf53a2a782008349342a09faa6cf8659e7ceddcd128ba73c4c9665cfb41f13c42
6
+ metadata.gz: 8930d5dfc0e3c8438515069ab5c472ae93aaf934c6d16c595c70b9167384347d7c0358c4c50fc49d18b1a4024ed959be4fff00485731c9e622b8c8e89f7c1a98
7
+ data.tar.gz: e9741f2fe2db83a7650dd2272b9f79cfa7e5bc4b3c2989cae0d8390215459a386a545f23eb0163e350e6e32a7dca7963c9a9bfcdb65496dfa062051a2c023aad
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -3,16 +3,27 @@ name: ci
3
3
  jobs:
4
4
  specs:
5
5
  runs-on: ubuntu-latest
6
+
6
7
  strategy:
7
8
  fail-fast: false
8
9
  matrix:
9
10
  ruby:
10
11
  - '2.7'
12
+ - '2.6'
13
+ - '2.5'
14
+ - 'jruby'
11
15
  include:
12
16
  - ruby: '2.7'
13
17
  coverage: 'true'
18
+
14
19
  steps:
15
20
  - uses: actions/checkout@v2
21
+ - uses: actions/cache@v2
22
+ with:
23
+ path: vendor/bundle
24
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
25
+ restore-keys: |
26
+ ${{ runner.os }}-gems-
16
27
  - name: Install package dependencies
17
28
  run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
18
29
  - name: Set up Ruby
@@ -22,10 +33,11 @@ jobs:
22
33
  - name: Install latest bundler
23
34
  run: |
24
35
  gem install bundler --no-document
25
- bundle config set without 'tools benchmarks docs'
26
36
  - name: Bundle install
37
+ env:
38
+ DIFFEND_DEVELOPMENT: true
27
39
  run: |
28
- bundle config set without development
40
+ bundle config path vendor/bundle
29
41
  bundle install --jobs 4 --retry 3
30
42
  - name: Run all tests
31
43
  env:
@@ -2,6 +2,43 @@
2
2
 
3
3
  ## [Unreleased][master]
4
4
 
5
+ ## [0.2.26] (2020-09-10)
6
+ - introduce DIFFEND_DEVELOPMENT environment variable ([#36](https://github.com/diffend-io/diffend-ruby/pull/36))
7
+ - adjust message for allow verdict ([#37](https://github.com/diffend-io/diffend-ruby/pull/37))
8
+ - do not run the plugin when it is not enabled ([#38](https://github.com/diffend-io/diffend-ruby/pull/38))
9
+
10
+ ## [0.2.25] (2020-09-09)
11
+ - add support for a warn verdict ([#34](https://github.com/diffend-io/diffend-ruby/pull/34))
12
+
13
+ ## [0.2.24] (2020-09-08)
14
+ - better error handling of response ([#28](https://github.com/diffend-io/diffend-ruby/pull/28))
15
+ - fix jruby specs ([#29](https://github.com/diffend-io/diffend-ruby/pull/29))
16
+ - handle request server errors ([#30](https://github.com/diffend-io/diffend-ruby/pull/30))
17
+ - better detection of gem source ([#31](https://github.com/diffend-io/diffend-ruby/pull/31))
18
+ - detect if we are running outdated version of the plugin ([#32](https://github.com/diffend-io/diffend-ruby/pull/32))
19
+
20
+ ## [0.2.23] (2020-09-06)
21
+ - fix how we build gem platform ([#26](https://github.com/diffend-io/diffend-ruby/pull/26))
22
+ - test against jruby, ruby-2.5 and ruby-2.6 ([#25](https://github.com/diffend-io/diffend-ruby/pull/25))
23
+
24
+ ## [0.2.22] (2020-09-03)
25
+ - fix how we build host command
26
+
27
+ ## [0.2.21] (2020-09-03)
28
+ - bring back support for ruby 2.5.x
29
+
30
+ ## [0.2.20] (2020-09-03)
31
+ - expose host command ([#21](https://github.com/diffend-io/diffend-ruby/pull/21))
32
+ - expose host pid ([#20](https://github.com/diffend-io/diffend-ruby/pull/20))
33
+ - use `Bundler.feature_flag.default_cli_command` which is used as the default task if no command provided, instead of `Diffend::Commands::INSTALL` ([#19](https://github.com/diffend-io/diffend-ruby/pull/19))
34
+ - better error handling ([#18](https://github.com/diffend-io/diffend-ruby/pull/18))
35
+ - better detection of gem versions ([#17](https://github.com/diffend-io/diffend-ruby/pull/17))
36
+ - introduce `Diffend::BuildBundlerDefinition` ([#16](https://github.com/diffend-io/diffend-ruby/pull/16))
37
+
38
+ ## [0.2.19] (2020-08-18)
39
+
40
+ - better detection of gem sources ([#13](https://github.com/diffend-io/diffend-ruby/pull/13))
41
+
5
42
  ## [0.2.18] (2020-08-05)
6
43
 
7
44
  - use `Etc.getpwuid` instead of `Etc.getlogin` for fetching host user ([#11](https://github.com/diffend-io/diffend-ruby/pull/11))
@@ -18,6 +55,15 @@
18
55
 
19
56
  - initial release
20
57
 
21
- [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.17...HEAD
58
+ [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.26...HEAD
59
+ [0.2.26]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.25...v0.2.26
60
+ [0.2.25]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.24...v0.2.25
61
+ [0.2.24]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.23...v0.2.24
62
+ [0.2.23]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.22...v0.2.23
63
+ [0.2.22]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.21...v0.2.22
64
+ [0.2.21]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.20...v0.2.21
65
+ [0.2.20]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.19...v0.2.20
66
+ [0.2.19]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.18...v0.2.19
67
+ [0.2.18]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.17...v0.2.18
22
68
  [0.2.17]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.16...v0.2.17
23
69
  [0.2.16]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.15...v0.2.16
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ plugin 'diffend'
7
7
  gemspec
8
8
 
9
9
  group :development, :test do
10
- gem 'byebug'
10
+ gem 'byebug', platform: :ruby
11
+ gem 'pry', platform: :jruby
11
12
  gem 'rspec'
12
13
  end
@@ -1,13 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diffend (0.2.18)
4
+ diffend (0.2.26)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  byebug (11.1.3)
10
+ coderay (1.1.3)
10
11
  diff-lcs (1.4.4)
12
+ ffi (1.13.1-java)
13
+ method_source (1.0.0)
14
+ pry (0.13.1-java)
15
+ coderay (~> 1.1)
16
+ method_source (~> 1.0)
17
+ spoon (~> 0.0)
11
18
  rake (13.0.1)
12
19
  rspec (3.9.0)
13
20
  rspec-core (~> 3.9.0)
@@ -22,14 +29,18 @@ GEM
22
29
  diff-lcs (>= 1.2.0, < 2.0)
23
30
  rspec-support (~> 3.9.0)
24
31
  rspec-support (3.9.3)
32
+ spoon (0.0.6)
33
+ ffi
25
34
 
26
35
  PLATFORMS
36
+ java
27
37
  ruby
28
38
 
29
39
  DEPENDENCIES
30
40
  bundler
31
41
  byebug
32
42
  diffend!
43
+ pry
33
44
  rake
34
45
  rspec
35
46
 
File without changes
@@ -5,16 +5,21 @@
5
5
  ].each(&method(:require))
6
6
 
7
7
  %w[
8
+ build_bundler_definition
8
9
  errors
9
10
  config/fetcher
10
11
  config/file_finder
11
12
  config/validator
12
13
  commands
14
+ handle_errors/messages
15
+ handle_errors/build_exception_payload
16
+ handle_errors/display_to_stdout
17
+ handle_errors/report
18
+ request
13
19
  voting
14
20
  ].each { |file| require "diffend/#{file}" }
15
21
 
16
22
  %w[
17
- request
18
23
  versions/local
19
24
  versions/remote
20
25
  ].each { |file| require "diffend/voting/#{file}" }
@@ -22,7 +27,7 @@
22
27
  # Diffend main namespace
23
28
  module Diffend
24
29
  # Current plugin version
25
- VERSION = '0.2.18'
30
+ VERSION = '0.2.26'
26
31
  # Diffend homepage
27
32
  HOMEPAGE = 'https://diffend.io'
28
33
 
@@ -30,35 +35,97 @@ module Diffend
30
35
  # Registers the plugin and add before install all hook
31
36
  def register
32
37
  Bundler::Plugin.add_hook('before-install-all') do |_|
33
- Diffend::Voting.call(
34
- command,
35
- build_definition(command)
36
- )
38
+ execute
37
39
  end
38
40
  end
39
41
 
40
- # Build clean instance of bundler definition, as we don't want to pollute the main one
41
- #
42
- # @param command [String] bundler command that we are executing
43
- #
44
- # @return [Bundler::Definition]
45
- def build_definition(command)
46
- unlock = command == 'update' ? true : nil
42
+ # Execute diffend plugin
43
+ def execute
44
+ return unless enabled?
45
+
46
+ verify_version
47
47
 
48
- Bundler.configure
48
+ config = fetch_config
49
49
 
50
- Bundler::Definition.build(
51
- Bundler.default_gemfile,
52
- Bundler.default_lockfile,
53
- unlock
50
+ Diffend::Voting.call(
51
+ command,
52
+ config,
53
+ Diffend::BuildBundlerDefinition.call(
54
+ command,
55
+ Bundler.default_gemfile,
56
+ Bundler.default_lockfile
57
+ )
54
58
  )
59
+ rescue StandardError => e
60
+ Diffend::HandleErrors::Report.call(
61
+ exception: e,
62
+ config: config,
63
+ message: :unhandled_exception,
64
+ report: true
65
+ )
66
+ end
67
+
68
+ def verify_version
69
+ return if ENV['DIFFEND_DEVELOPMENT'] == 'true'
70
+ return if installed_version == VERSION
71
+
72
+ build_outdated_version_message(installed_version)
73
+ .tap(&Bundler.ui.method(:error))
74
+
75
+ exit 1
76
+ end
77
+
78
+ # @return [String] installed plugin version
79
+ def installed_version
80
+ Bundler::Plugin
81
+ .index
82
+ .plugin_path('diffend')
83
+ .basename
84
+ .to_s
85
+ .split('-')
86
+ .last
87
+ end
88
+
89
+ # Checks if plugin is enabled
90
+ #
91
+ # @return [Boolean] true if enabled, false otherwise
92
+ def enabled?
93
+ Bundler
94
+ .default_gemfile
95
+ .read
96
+ .split("\n")
97
+ .reject(&:empty?)
98
+ .map(&:strip)
99
+ .select { |line| line.start_with?('plugin') }
100
+ .any? { |line| line.include?('diffend') }
101
+ end
102
+
103
+ # @param version [Hash] installed version
104
+ #
105
+ # @return [String]
106
+ def build_outdated_version_message(version)
107
+ <<~MSG
108
+ \nYou are running an outdated version (#{version}) of the plugin, which will lead to issues.
109
+ \nPlease upgrade to the latest one (#{VERSION}) by executing "rm -rf .bundle/plugin".\n
110
+ MSG
55
111
  end
56
112
 
57
113
  # Command that was run with bundle
58
114
  #
59
115
  # @return [String]
60
116
  def command
61
- ARGV.first || Diffend::Commands::INSTALL
117
+ ARGV.first || Bundler.feature_flag.default_cli_command.to_s
118
+ end
119
+
120
+ # Fetch diffend config file
121
+ #
122
+ # @return [OpenStruct, nil] configuration object
123
+ #
124
+ # @raise [Errors::MissingConfigurationFile] when no config file
125
+ def fetch_config
126
+ Config::Fetcher.call(
127
+ File.expand_path('..', Bundler.bin_path)
128
+ )
62
129
  end
63
130
  end
64
131
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ # Builds bundler definition used within the plugin
5
+ module BuildBundlerDefinition
6
+ class << self
7
+ # Build clean instance of bundler definition, as we don't want to pollute the main one
8
+ #
9
+ # @param command [String] bundler command that we are executing
10
+ # @param gemfile [String] path to Gemfile
11
+ # @param lockfile [String] path to Gemfile.lock
12
+ #
13
+ # @return [Bundler::Definition]
14
+ def call(command, gemfile, lockfile)
15
+ unlock = command == 'update' ? true : nil
16
+
17
+ Bundler.configure
18
+ Bundler::Fetcher.disable_endpoint = nil
19
+
20
+ Bundler::Definition
21
+ .build(gemfile, lockfile, unlock)
22
+ .tap(&:validate_runtime!)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -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
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ module Diffend
6
+ module HandleErrors
7
+ # Module responsible for building exception payload
8
+ module BuildExceptionPayload
9
+ class << self
10
+ # Build exception payload
11
+ #
12
+ # @param exception [Exception, NilClass] expection that was raised
13
+ # @param payload [Hash] with versions to check
14
+ #
15
+ # @return [Hash]
16
+ def call(exception, payload)
17
+ {
18
+ request_id: SecureRandom.uuid,
19
+ payload: payload,
20
+ exception: {
21
+ class: exception&.class,
22
+ message: exception&.message,
23
+ backtrace: exception&.backtrace
24
+ }
25
+ }.freeze
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ module HandleErrors
5
+ # Module responsible for displaying exception payload to stdout
6
+ module DisplayToStdout
7
+ class << self
8
+ # Display exception payload to stdout
9
+ #
10
+ # @param exception_payload [Hash]
11
+ def call(exception_payload)
12
+ puts exception_payload.to_json
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ module HandleErrors
5
+ module Messages
6
+ PAYLOAD_DUMP = '^^^ Above is the dump of your request ^^^'
7
+ UNHANDLED_EXCEPTION = <<~MSG
8
+ \nSomething went really wrong. We recorded this incident in our system and will review it.\n
9
+ This is a bug, don't hesitate.\n
10
+ Create an issue at https://github.com/diffend-io/diffend-ruby/issues\n
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
22
+ REQUEST_ERROR = <<~MSG
23
+ \nWe were unable to process your request at this time. We recorded this incident in our system and will review it.\n
24
+ If you think that this is a bug, don't hesitate.\n
25
+ Create an issue at https://github.com/diffend-io/diffend-ruby/issues\n
26
+ MSG
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ module HandleErrors
5
+ # Module responsible for reporting errors to diffend
6
+ module Report
7
+ class << self
8
+ # Execute request to Diffend
9
+ #
10
+ # @param exception [Exception] expection that was raised
11
+ # @param payload [Hash] with versions to check
12
+ # @param config [OpenStruct] Diffend config
13
+ # @param message [Symbol] message that we want to display
14
+ # @param report [Boolean] if true we will report the issue to diffend
15
+ #
16
+ # @return [Net::HTTPResponse] response from Diffend
17
+ def call(config:, message:, exception: nil, payload: {}, report: false)
18
+ exception_payload = prepare_exception_payload(exception, payload)
19
+
20
+ Bundler.ui.error(Diffend::HandleErrors::Messages::PAYLOAD_DUMP)
21
+ Bundler.ui.error(Diffend::HandleErrors::Messages.const_get(message.to_s.upcase))
22
+
23
+ if report
24
+ Diffend::Request.call(
25
+ config,
26
+ errors_url(config.project_id),
27
+ exception_payload
28
+ )
29
+ end
30
+
31
+ exit 1
32
+ end
33
+
34
+ # Prepare exception payload and display it to stdout
35
+ #
36
+ # @param exception [Exception] expection that was raised
37
+ # @param payload [Hash] with versions to check
38
+ #
39
+ # @return [Hash]
40
+ def prepare_exception_payload(exception, payload)
41
+ Diffend::HandleErrors::BuildExceptionPayload
42
+ .call(exception, payload)
43
+ .tap(&Diffend::HandleErrors::DisplayToStdout.method(:call))
44
+ end
45
+
46
+ # Provides diffend errors endpoint url
47
+ #
48
+ # @param project_id [String] diffend project_id
49
+ #
50
+ # @return [String] diffend endpoint
51
+ def errors_url(project_id)
52
+ return ENV['DIFFEND_ERROR_URL'] if ENV.key?('DIFFEND_ERROR_URL')
53
+
54
+ "https://my.diffend.io/api/projects/#{project_id}/errors"
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end