diffend 0.2.16 → 0.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d23a558405ac69141d76368e9a642d153300c2a9bb01fd67b9c8f3c949a9225b
4
- data.tar.gz: 5d74b929a8debf7c7a32aa0cb8d01e9f51c373b0859468a3936e40a1bccc1004
3
+ metadata.gz: 5ce266f8f72de49360adc1e6e1f79c8bf5fa08727ffc990292877c015e1040ee
4
+ data.tar.gz: 1a71a4a519b1f2afb9bc993726c045b4db5b87833459ba8f7192c2a2f4232aa6
5
5
  SHA512:
6
- metadata.gz: 8fe13be65aad9dda4c8a4cf3341851d691f253e4dc2d3d4a31e1da2bba92bffb2902e69ea08f78a5d3a9c6a5fb3f233abf72dd569d732df317aa5f0d8748830b
7
- data.tar.gz: 86929a3b0259f8de839edfdd2901c203ed0e69d35a733d31860d6628c71a5874097efd3a08fb4203e4fa4768f110d5d36ec192f064b144b1a99c8c208111be0f
6
+ metadata.gz: '08dd6da1d3984200d9ac07fd9fd1f9a0adf6b7746f86a77ab560b77b356dc6fad819513adea6fe2d714b1f06ed8cf5441d796681fd507b64247a2db3560d3138'
7
+ data.tar.gz: 2155bbba6da089606b38d36fcec4259054f6cac053bf56eefb303d6d3aa223ba4253ca771249a2543696c636e8c509aa75ceb3ab50f055dd18a2ba9715e5cb9f
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,9 @@ 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
27
37
  run: |
28
- bundle config set without development
38
+ bundle config path vendor/bundle
29
39
  bundle install --jobs 4 --retry 3
30
40
  - name: Run all tests
31
41
  env:
@@ -0,0 +1,48 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased][master]
4
+ - fix how we build gem platform ([#26](https://github.com/diffend-io/diffend-ruby/pull/26))
5
+ - test against jruby, ruby-2.5 and ruby-2.6 ([#25](https://github.com/diffend-io/diffend-ruby/pull/25))
6
+
7
+ ## [0.2.22] (2020-09-03)
8
+ - fix how we build host command
9
+
10
+ ## [0.2.21] (2020-09-03)
11
+ - bring back support for ruby 2.5.x
12
+
13
+ ## [0.2.20] (2020-09-03)
14
+ - expose host command ([#21](https://github.com/diffend-io/diffend-ruby/pull/21))
15
+ - expose host pid ([#20](https://github.com/diffend-io/diffend-ruby/pull/20))
16
+ - 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))
17
+ - better error handling ([#18](https://github.com/diffend-io/diffend-ruby/pull/18))
18
+ - better detection of gem versions ([#17](https://github.com/diffend-io/diffend-ruby/pull/17))
19
+ - introduce `Diffend::BuildBundlerDefinition` ([#16](https://github.com/diffend-io/diffend-ruby/pull/16))
20
+
21
+ ## [0.2.19] (2020-08-18)
22
+
23
+ - better detection of gem sources ([#13](https://github.com/diffend-io/diffend-ruby/pull/13))
24
+
25
+ ## [0.2.18] (2020-08-05)
26
+
27
+ - use `Etc.getpwuid` instead of `Etc.getlogin` for fetching host user ([#11](https://github.com/diffend-io/diffend-ruby/pull/11))
28
+
29
+ ## [0.2.17] (2020-08-05)
30
+
31
+ - introduce config validation ([#9](https://github.com/diffend-io/diffend-ruby/pull/9))
32
+
33
+ ## [0.2.16] (2020-07-28)
34
+
35
+ - report unexpected errors ([#8](https://github.com/diffend-io/diffend-ruby/pull/8))
36
+
37
+ ## 0.2.15 (2020-06-07)
38
+
39
+ - initial release
40
+
41
+ [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.22...HEAD
42
+ [0.2.22]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.21...v0.2.22
43
+ [0.2.21]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.20...v0.2.21
44
+ [0.2.20]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.19...v0.2.20
45
+ [0.2.19]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.18...v0.2.19
46
+ [0.2.18]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.17...v0.2.18
47
+ [0.2.17]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.16...v0.2.17
48
+ [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.16)
4
+ diffend (0.2.23)
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,15 +5,21 @@
5
5
  ].each(&method(:require))
6
6
 
7
7
  %w[
8
+ build_bundler_definition
9
+ errors
8
10
  config/fetcher
9
11
  config/file_finder
12
+ config/validator
10
13
  commands
11
- errors
14
+ handle_errors/messages
15
+ handle_errors/build_exception_payload
16
+ handle_errors/display_to_stdout
17
+ handle_errors/report
18
+ request
12
19
  voting
13
20
  ].each { |file| require "diffend/#{file}" }
14
21
 
15
22
  %w[
16
- request
17
23
  versions/local
18
24
  versions/remote
19
25
  ].each { |file| require "diffend/voting/#{file}" }
@@ -21,7 +27,7 @@
21
27
  # Diffend main namespace
22
28
  module Diffend
23
29
  # Current plugin version
24
- VERSION = '0.2.16'
30
+ VERSION = '0.2.23'
25
31
  # Diffend homepage
26
32
  HOMEPAGE = 'https://diffend.io'
27
33
 
@@ -29,27 +35,28 @@ module Diffend
29
35
  # Registers the plugin and add before install all hook
30
36
  def register
31
37
  Bundler::Plugin.add_hook('before-install-all') do |_|
32
- Diffend::Voting.call(
33
- command,
34
- build_definition(command)
35
- )
38
+ execute
36
39
  end
37
40
  end
38
41
 
39
- # Build clean instance of bundler definition, as we don't want to pollute the main one
40
- #
41
- # @param command [String] bundler command that we are executing
42
- #
43
- # @return [Bundler::Definition]
44
- def build_definition(command)
45
- unlock = command == 'update' ? true : nil
46
-
47
- Bundler.configure
42
+ # Execute diffend plugin
43
+ def execute
44
+ config = fetch_config
48
45
 
49
- Bundler::Definition.build(
50
- Bundler.default_gemfile,
51
- Bundler.default_lockfile,
52
- unlock
46
+ Diffend::Voting.call(
47
+ command,
48
+ Diffend::BuildBundlerDefinition.call(
49
+ command,
50
+ Bundler.default_gemfile,
51
+ Bundler.default_lockfile
52
+ )
53
+ )
54
+ rescue StandardError => e
55
+ Diffend::HandleErrors::Report.call(
56
+ exception: e,
57
+ config: config,
58
+ message: :unhandled_exception,
59
+ report: true
53
60
  )
54
61
  end
55
62
 
@@ -57,7 +64,18 @@ module Diffend
57
64
  #
58
65
  # @return [String]
59
66
  def command
60
- ARGV.first || Diffend::Commands::INSTALL
67
+ ARGV.first || Bundler.feature_flag.default_cli_command.to_s
68
+ end
69
+
70
+ # Fetch diffend config file
71
+ #
72
+ # @return [OpenStruct, nil] configuration object
73
+ #
74
+ # @raise [Errors::MissingConfigurationFile] when no config file
75
+ def fetch_config
76
+ Config::Fetcher.call(
77
+ File.expand_path('..', Bundler.bin_path)
78
+ )
61
79
  end
62
80
  end
63
81
  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
@@ -7,22 +7,105 @@ module Diffend
7
7
  module Config
8
8
  # Class responsible for fetching the config from .diffend.yml
9
9
  module Fetcher
10
+ # All the errors for missing keys in the configuration file
11
+ MISSING_KEY_ERRORS = [
12
+ Errors::ProjectIdMissingInConfigurationFile,
13
+ Errors::ShareableIdMissingInConfigurationFile,
14
+ Errors::ShareableKeyMissingInConfigurationFile,
15
+ Errors::BuildPathMissingInConfigurationFile
16
+ ].freeze
17
+
10
18
  class << self
11
19
  # @param build_path [String] path of the current build
20
+ #
12
21
  # @return [OpenStruct] open struct with config details
22
+ #
13
23
  # @example
14
24
  # details = Fetcher.new.call('./')
15
25
  # details.build_path #=> './'
16
26
  def call(build_path)
17
- OpenStruct.new(
18
- YAML.safe_load(
19
- ERB.new(
20
- File.read(
21
- FileFinder.call(build_path)
22
- )
23
- ).result
24
- ).merge(build_path: build_path)
25
- )
27
+ build(build_path)
28
+ rescue Errors::MissingConfigurationFile
29
+ Bundler.ui.error(build_missing_error_message(build_path))
30
+ exit 1
31
+ rescue Errors::EmptyConfigurationFile
32
+ Bundler.ui.error(build_empty_error_message(build_path))
33
+ exit 1
34
+ rescue Errors::MalformedConfigurationFile
35
+ Bundler.ui.error(build_malformed_error_message(build_path))
36
+ exit 1
37
+ rescue *MISSING_KEY_ERRORS => e
38
+ Bundler.ui.error(build_missing_key_error_message(e))
39
+ exit 1
40
+ end
41
+
42
+ private
43
+
44
+ # @param build_path [String] path of the current build
45
+ #
46
+ # @return [OpenStruct] open struct with config details
47
+ def build(build_path)
48
+ content = ERB.new(
49
+ File.read(
50
+ FileFinder.call(build_path)
51
+ )
52
+ ).result
53
+
54
+ raise Errors::EmptyConfigurationFile if content.empty?
55
+
56
+ OpenStruct.new(parse_file(content).merge(build_path: build_path))
57
+ .tap(&Validator.method(:call))
58
+ end
59
+
60
+ def parse_file(content)
61
+ YAML.safe_load(content)
62
+ rescue Psych::SyntaxError
63
+ raise Errors::MalformedConfigurationFile
64
+ end
65
+
66
+ # @param build_path [String] path of the current build
67
+ #
68
+ # @return [String] missing configuration file message
69
+ def build_missing_error_message(build_path)
70
+ <<~MSG
71
+ \nWe were unable to locate Diffend configuration file.\n
72
+ Please make sure that .diffend.yml is present in #{build_path} folder.\n
73
+ MSG
74
+ end
75
+
76
+ # @return [String] empty configuration file message
77
+ def build_empty_error_message
78
+ <<~MSG
79
+ \nYour Diffend configuration file is empty.\n
80
+ Please re-setup.\n
81
+ MSG
82
+ end
83
+
84
+ # @return [String] malformed configuration file message
85
+ def build_malformed_error_message
86
+ <<~MSG
87
+ \nYour Diffend configuration file is malformed.\n
88
+ Please re-setup.\n
89
+ MSG
90
+ end
91
+
92
+ # @return [String] malformed configuration file message
93
+ def build_missing_key_error_message(exception)
94
+ missing_key = missing_key_from_exception(exception)
95
+
96
+ <<~MSG
97
+ \nYour Diffend configuration file is missing #{missing_key} key.\n
98
+ Please re-setup.\n
99
+ MSG
100
+ end
101
+
102
+ def missing_key_from_exception(exception)
103
+ case exception
104
+ when Errors::ProjectIdMissingInConfigurationFile then 'project_id'
105
+ when Errors::ShareableIdMissingInConfigurationFile then 'shareable_id'
106
+ when Errors::ShareableKeyMissingInConfigurationFile then 'shareable_key'
107
+ when Errors::BuildPathMissingInConfigurationFile then 'build_path'
108
+ end
26
109
  end
27
110
  end
28
111
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ # Module for all the components related to setting up the config
5
+ module Config
6
+ # Class responsible for validating the config from .diffend.yml
7
+ module Validator
8
+ class << self
9
+ # @param config [OpenStruct] path of the current build
10
+ def call(config)
11
+ raise Errors::ProjectIdMissingInConfigurationFile if missing?(config, 'project_id')
12
+ raise Errors::ShareableIdMissingInConfigurationFile if missing?(config, 'shareable_id')
13
+ raise Errors::ShareableKeyMissingInConfigurationFile if missing?(config, 'shareable_key')
14
+ raise Errors::BuildPathMissingInConfigurationFile if missing?(config, 'build_path')
15
+ end
16
+
17
+ private
18
+
19
+ def missing?(config, key)
20
+ config.public_send(key).nil? || config.public_send(key).empty?
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -7,6 +7,18 @@ module Diffend
7
7
  BaseError = Class.new(StandardError)
8
8
  # Raised when we couldn't find a valid configuration file
9
9
  MissingConfigurationFile = Class.new(BaseError)
10
+ # Raised when configuration file is empty
11
+ EmptyConfigurationFile = Class.new(BaseError)
12
+ # Raised when configuration file is malformed
13
+ MalformedConfigurationFile = Class.new(BaseError)
14
+ # Raised when project_id is missing in configuration file
15
+ ProjectIdMissingInConfigurationFile = Class.new(BaseError)
16
+ # Raised when shareable_id is missing in configuration file
17
+ ShareableIdMissingInConfigurationFile = Class.new(BaseError)
18
+ # Raised when shareable_key is missing in configuration file
19
+ ShareableKeyMissingInConfigurationFile = Class.new(BaseError)
20
+ # Raised when build_path is missing in configuration file
21
+ BuildPathMissingInConfigurationFile = Class.new(BaseError)
10
22
  # When unsupported response returned from the endpoint
11
23
  UnsupportedResponse = Class.new(BaseError)
12
24
  # When unsupported action returned from the endpoint
@@ -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] 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