diffend 0.2.30 → 0.2.35

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: 52618cdf40375202e18c1cdaa481554084f3b92f337fd61c089e147f0027e982
4
- data.tar.gz: 859f390055e3030d3a357b604067e6c05814f653225a802136563be4bc32f9ee
3
+ metadata.gz: '0780c79922b3857482318780ad968af290af191fd0c59e032f9a0f94d671ad6d'
4
+ data.tar.gz: d2f91acc6e7ea5d3a59bd8b86c49c5c4d763eff6bf3af3ecf6b00d99730da36b
5
5
  SHA512:
6
- metadata.gz: 9f17436faa3bdabe77c891c930bb9dac01f426ae715d37035d7727112e221526ac003daa44d196dbb056f4c21bca49589a7799e36bef81db6bf8b3c29012adb5
7
- data.tar.gz: 232310953c6dc8cd500aac54b0fd8d7f9980457b40032021b46bf7753f62c8a7d6167486c3e15e0d2e940101b47b8b8cdd8af67577eca7ba626b2db9706724c6
6
+ metadata.gz: 15ec791f3eea3e174ad8a09d68f9f5b20511e9728c3f4481b9b2c97e377cdb5eb6e0faee215a24979b18f846e8a2bd01cc9569634c4307ccf448e4bcb73e035d
7
+ data.tar.gz: a5b7b8ab500fa6dcb187f46137d89337bc1f4bd3eaa006c5ba43dada667ffbce01ea61a68678a5f04a211b91cbdc8e73f55fcb3350db7bb74a93dc50d3051cd7
Binary file
data.tar.gz.sig CHANGED
@@ -1,4 +1 @@
1
- P{���hK_�=(k1��G�d}�g��%���\:U���nC?�_��*{Z�w�Fz��29�%`bv���*2~��ac�����̮�R�N).
2
- 2A�.΀��I'�/W�pbB�d8|D|JV1�
3
- � 9�����V,@�3�V����H��9���Qk� 9|��a�՟�dB�J�3��*h�����\~�~U�9o�{H�c��H���@�ۨ����.H��+�Q������Q��V��ޣ��ڕ������j�iY/�3B㻧������A���jK��3?��w� ݀�]��$���K��`��?Y�sl��&eF�
4
- llj��ժm���eE�En��l�6ԳQԠH�c�r��猁�h�T��u.�����;f��
1
+ 2��oa�)qN���Q6���@`Sb-��8��!=4
@@ -1 +1 @@
1
- 2.7.1
1
+ 2.7.2
@@ -2,6 +2,32 @@
2
2
 
3
3
  ## [Unreleased][master]
4
4
 
5
+ ## [0.2.35] (2020-11-04)
6
+ - clean command name and title of a process ([#76](https://github.com/diffend-io/diffend-ruby/pull/76))
7
+ - handle `uninitialized constant #<Class:Diffend::Configs::Fetcher>::ERB` ([#75](https://github.com/diffend-io/diffend-ruby/pull/75))
8
+
9
+ ## [0.2.34] (2020-10-25)
10
+ - handle `Bundler::GitError` ([#72](https://github.com/diffend-io/diffend-ruby/pull/72))
11
+
12
+ ## [0.2.33] (2020-10-25)
13
+ - fix an exception when configuration file is missing ([#65](https://github.com/diffend-io/diffend-ruby/pull/65))
14
+ - silently exit when configuration file is missing in `Diffend::Monitor` ([#66](https://github.com/diffend-io/diffend-ruby/pull/66))
15
+ - introduce default config ([#67](https://github.com/diffend-io/diffend-ruby/pull/67))
16
+ - handle `SocketError` ([#68](https://github.com/diffend-io/diffend-ruby/pull/68))
17
+
18
+ ## [0.2.32] (2020-10-02)
19
+ - fix how we build platform from `Gem::Platform` ([#56](https://github.com/diffend-io/diffend-ruby/pull/56))
20
+ - introduce `Diffend::LatestVersion` ([#57](https://github.com/diffend-io/diffend-ruby/pull/57))
21
+ - refactor `Diffend::Config` ([#58](https://github.com/diffend-io/diffend-ruby/pull/58))
22
+ - set command in `Diffend::Config` ([#59](https://github.com/diffend-io/diffend-ruby/pull/59))
23
+ - introduce `Diffend::Logger` ([#60](https://github.com/diffend-io/diffend-ruby/pull/60))
24
+ - set severity to `FATAL` in `Diffend::Monitor` ([#61](https://github.com/diffend-io/diffend-ruby/pull/61))
25
+ - handle `Bundler::VersionConflict` ([#62](https://github.com/diffend-io/diffend-ruby/pull/62))
26
+
27
+ ## [0.2.31] (2020-09-24)
28
+ - change request timeout to 15 seconds ([#53](https://github.com/diffend-io/diffend-ruby/pull/53))
29
+ - report request issues as warnings ([#54](https://github.com/diffend-io/diffend-ruby/pull/54))
30
+
5
31
  ## [0.2.30] (2020-09-21)
6
32
  - handle dependencies resolve issues ([#51](https://github.com/diffend-io/diffend-ruby/pull/51))
7
33
  - better detection when to start `Diffend::Monitor` ([#50](https://github.com/diffend-io/diffend-ruby/pull/50))
@@ -72,7 +98,12 @@
72
98
 
73
99
  - initial release
74
100
 
75
- [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.30...HEAD
101
+ [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.35...HEAD
102
+ [0.2.35]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.34...v0.2.35
103
+ [0.2.34]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.33...v0.2.34
104
+ [0.2.33]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.32...v0.2.33
105
+ [0.2.32]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.31...v0.2.32
106
+ [0.2.31]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.30...v0.2.31
76
107
  [0.2.30]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.29...v0.2.30
77
108
  [0.2.29]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.28...v0.2.29
78
109
  [0.2.28]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.27...v0.2.28
data/Gemfile CHANGED
@@ -7,7 +7,5 @@ plugin 'diffend'
7
7
  gemspec
8
8
 
9
9
  group :development, :test do
10
- gem 'byebug', platform: :ruby
11
- gem 'pry', platform: :jruby
12
10
  gem 'rspec'
13
11
  end
@@ -1,36 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diffend (0.2.30)
4
+ diffend (0.2.35)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- byebug (11.1.3)
10
- coderay (1.1.3)
11
9
  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)
18
10
  rake (13.0.1)
19
- rspec (3.9.0)
20
- rspec-core (~> 3.9.0)
21
- rspec-expectations (~> 3.9.0)
22
- rspec-mocks (~> 3.9.0)
23
- rspec-core (3.9.2)
24
- rspec-support (~> 3.9.3)
25
- rspec-expectations (3.9.2)
11
+ rspec (3.10.0)
12
+ rspec-core (~> 3.10.0)
13
+ rspec-expectations (~> 3.10.0)
14
+ rspec-mocks (~> 3.10.0)
15
+ rspec-core (3.10.0)
16
+ rspec-support (~> 3.10.0)
17
+ rspec-expectations (3.10.0)
26
18
  diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.9.0)
28
- rspec-mocks (3.9.1)
19
+ rspec-support (~> 3.10.0)
20
+ rspec-mocks (3.10.0)
29
21
  diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.9.0)
31
- rspec-support (3.9.3)
32
- spoon (0.0.6)
33
- ffi
22
+ rspec-support (~> 3.10.0)
23
+ rspec-support (3.10.0)
34
24
 
35
25
  PLATFORMS
36
26
  java
@@ -38,9 +28,7 @@ PLATFORMS
38
28
 
39
29
  DEPENDENCIES
40
30
  bundler
41
- byebug
42
31
  diffend!
43
- pry
44
32
  rake
45
33
  rspec
46
34
 
@@ -0,0 +1,6 @@
1
+ project_id: <%= ENV['DIFFEND_PROJECT_ID'] %>
2
+ shareable_id: <%= ENV['DIFFEND_SHAREABLE_ID'] %>
3
+ shareable_key: <%= ENV['DIFFEND_SHAREABLE_KEY'] %>
4
+ env: <%= ENV['DIFFEND_ENV'] || 'development' %>
5
+ ignore_errors: <%= ENV['DIFFEND_IGNORE_ERRORS'] || 'true' %>
6
+ development: <%= ENV['DIFFEND_DEVELOPMENT'] || 'true' %>
@@ -6,7 +6,7 @@ module Diffend
6
6
  class << self
7
7
  # Build clean instance of bundler definition, as we don't want to pollute the main one
8
8
  #
9
- # @param command [String] bundler command that we are executing
9
+ # @param command [String] command executed via bundler
10
10
  # @param gemfile [String] path to Gemfile
11
11
  # @param lockfile [String] path to Gemfile.lock
12
12
  #
@@ -2,18 +2,79 @@
2
2
 
3
3
  module Diffend
4
4
  # Diffend config object
5
- module Config
6
- class << self
7
- # Build diffend config object
8
- #
9
- # @return [OpenStruct, nil]
10
- #
11
- # @raise [Errors::MissingConfigurationFile] when no config file
12
- def call
13
- Diffend::Config::Fetcher.call(
14
- File.expand_path('..', ::Bundler.bin_path)
15
- )
16
- end
5
+ class Config
6
+ attr_reader :project_id, :shareable_id, :shareable_key, :build_path, :env, :command
7
+
8
+ # Build diffend config object
9
+ #
10
+ # @return [Diffend::Config]
11
+ def initialize(command: nil, severity: nil, build_path: nil)
12
+ @log_level = severity
13
+ build(command, build_path)
14
+ validate
15
+ end
16
+
17
+ def logger
18
+ @logger ||= Diffend::Logger.new(@log_level)
19
+ end
20
+
21
+ def ignore_errors?
22
+ @ignore_errors
23
+ end
24
+
25
+ def development?
26
+ @development
27
+ end
28
+
29
+ # Provides diffend commands endpoint url
30
+ #
31
+ # @return [String]
32
+ def commands_url
33
+ return ENV['DIFFEND_COMMANDS_URL'] if ENV.key?('DIFFEND_COMMANDS_URL')
34
+
35
+ "https://my.diffend.io/api/projects/#{project_id}/bundle/#{command}"
36
+ end
37
+
38
+ # Provides diffend errors endpoint url
39
+ #
40
+ # @return [String]
41
+ def errors_url
42
+ return ENV['DIFFEND_ERRORS_URL'] if ENV.key?('DIFFEND_ERRORS_URL')
43
+
44
+ "https://my.diffend.io/api/projects/#{project_id}/errors"
45
+ end
46
+
47
+ # @param request_id [String]
48
+ #
49
+ # @return [String]
50
+ def track_url(request_id)
51
+ "https://my.diffend.io/api/projects/#{project_id}/bundle/#{request_id}/track"
52
+ end
53
+
54
+ private
55
+
56
+ def build(command, build_path)
57
+ build_path ||= File.expand_path('..', ::Bundler.bin_path)
58
+ hash = Diffend::Configs::Fetcher.call(logger, plugin_path, build_path)
59
+ hash['build_path'] = build_path
60
+ hash['command'] = command || build_command
61
+
62
+ hash.each { |key, value| instance_variable_set(:"@#{key}", value) }
63
+ end
64
+
65
+ def validate
66
+ Diffend::Configs::Validator.call(self)
67
+ end
68
+
69
+ # Command that was run with bundle
70
+ #
71
+ # @return [String]
72
+ def build_command
73
+ ARGV.first || ::Bundler.feature_flag.default_cli_command.to_s
74
+ end
75
+
76
+ def plugin_path
77
+ Pathname.new(File.expand_path('../..', __dir__))
17
78
  end
18
79
  end
19
80
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[
4
+ erb
5
+ yaml
6
+ ].each(&method(:require))
7
+
8
+ module Diffend
9
+ # Module for all the components related to setting up the config
10
+ module Configs
11
+ # Class responsible for fetching the config from .diffend.yml
12
+ module Fetcher
13
+ class << self
14
+ # @param logger [Diffend::Logger]
15
+ # @param plugin_path [String] path of the plugin
16
+ # @param build_path [String] path of the current build
17
+ #
18
+ # @return [Hash] details from configuration file
19
+ #
20
+ # @example
21
+ # details = Fetcher.new.call('./')
22
+ # details.build_path #=> './'
23
+ def call(logger, plugin_path, build_path)
24
+ build(plugin_path, build_path)
25
+ rescue Errors::MalformedConfigurationFile
26
+ build_malformed_error_message(build_path)
27
+ .tap(&logger.method(:fatal))
28
+
29
+ raise Diffend::Errors::HandledException
30
+ end
31
+
32
+ private
33
+
34
+ # @param plugin_path [String] path of the plugin
35
+ # @param build_path [String] path of the current build
36
+ #
37
+ # @return [OpenStruct] open struct with config details
38
+ def build(plugin_path, build_path)
39
+ default_config = File.join(plugin_path, 'config', 'diffend.yml')
40
+ project_config = File.join(build_path, '.diffend.yml')
41
+
42
+ hash = read_file(default_config)
43
+
44
+ if File.exist?(project_config)
45
+ hash.merge!(read_file(project_config) || {})
46
+ end
47
+
48
+ hash
49
+ end
50
+
51
+ def read_file(path)
52
+ YAML.safe_load(ERB.new(File.read(path)).result)
53
+ rescue Psych::SyntaxError
54
+ raise Errors::MalformedConfigurationFile
55
+ end
56
+
57
+ # @return [String] malformed configuration file message
58
+ def build_malformed_error_message
59
+ <<~MSG
60
+ \nYour Diffend configuration file is malformed.\n
61
+ Please re-setup.\n
62
+ MSG
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ # Module for all the components related to setting up the config
5
+ module Configs
6
+ # Class responsible for validating the config from .diffend.yml
7
+ module Validator
8
+ KNOWN_KEYS = {
9
+ project_id: [String],
10
+ shareable_id: [String],
11
+ shareable_key: [String],
12
+ build_path: [String],
13
+ env: [String],
14
+ command: [String],
15
+ ignore_errors?: [TrueClass, FalseClass],
16
+ development?: [TrueClass, FalseClass]
17
+ }.freeze
18
+
19
+ class << self
20
+ # @param config [Diffend::Config]
21
+ def call(config)
22
+ KNOWN_KEYS.each_key do |key|
23
+ if missing?(config, key)
24
+ missing_key_message(key)
25
+ .tap(&config.logger.method(:fatal))
26
+
27
+ raise Diffend::Errors::HandledException
28
+ end
29
+
30
+ if invalid?(config, key)
31
+ invalid_key_message(config, key)
32
+ .tap(&config.logger.method(:fatal))
33
+
34
+ raise Diffend::Errors::HandledException
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ # @param config [Diffend::Config]
42
+ # @param key [String]
43
+ #
44
+ # @return [Boolean] true if we are missing a key, false otherwise
45
+ def missing?(config, key)
46
+ value = config.public_send(key)
47
+
48
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
49
+ end
50
+
51
+ # @param config [Diffend::Config]
52
+ # @param key [String]
53
+ #
54
+ # @return [Boolean] true if we are missing a key, false otherwise
55
+ def invalid?(config, key)
56
+ !KNOWN_KEYS[key].include?(config.public_send(key).class)
57
+ end
58
+
59
+ # Missing key message
60
+ #
61
+ # @param key [String] missing key
62
+ #
63
+ # @return [String]
64
+ def missing_key_message(key)
65
+ <<~MSG
66
+ \nDiffend configuration is missing #{key} key.\n
67
+ MSG
68
+ end
69
+
70
+ # Invalid key message
71
+ #
72
+ # @param hash [Hash] config hash
73
+ # @param key [String] invalid key
74
+ #
75
+ # @return [String]
76
+ def invalid_key_message(hash, key)
77
+ <<~MSG
78
+ \nDiffend configuration value for #{key} is invalid.\n
79
+ It should be #{KNOWN_KEYS[key].join(' or ')} but is #{hash.public_send(key).class}.\n
80
+ MSG
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -5,10 +5,6 @@ module Diffend
5
5
  module Errors
6
6
  # Base error class from which all the errors should inherit
7
7
  BaseError = Class.new(StandardError)
8
- # Raised when we couldn't find a valid configuration file
9
- MissingConfigurationFile = Class.new(BaseError)
10
- # Raised when configuration file is empty
11
- EmptyConfigurationFile = Class.new(BaseError)
12
8
  # Raised when configuration file is malformed
13
9
  MalformedConfigurationFile = Class.new(BaseError)
14
10
  # Raised when project_id is missing in configuration file
@@ -6,12 +6,11 @@ module Diffend
6
6
  class << self
7
7
  # Build verdict
8
8
  #
9
- # @param command [String] either install or update
10
- # @param config [OpenStruct] diffend config
11
- def call(command, config)
9
+ # @param config [Diffend::Config]
10
+ def call(config)
12
11
  Diffend::RequestVerdict
13
- .call(command, config, build_definition(command))
14
- .tap { |response| build_message(command, config, response) }
12
+ .call(config, build_definition(config.command))
13
+ .tap { |response| build_message(config, response) }
15
14
  rescue Diffend::Errors::DependenciesResolveException
16
15
  # We are unable to resolve dependencies, no message will be printed
17
16
  end
@@ -27,14 +26,13 @@ module Diffend
27
26
  )
28
27
  end
29
28
 
30
- # @param command [String] either install or update
31
- # @param config [OpenStruct] diffend config
29
+ # @param config [Diffend::Config]
32
30
  # @param response [Hash] response from diffend API
33
- def build_message(command, config, response)
31
+ def build_message(config, response)
34
32
  if response.key?('error')
35
- build_error(response)
33
+ build_error(config, response)
36
34
  elsif response.key?('action')
37
- build_verdict(command, config, response)
35
+ build_verdict(config, response)
38
36
  else
39
37
  Diffend::HandleErrors::Report.call(
40
38
  config: config,
@@ -48,25 +46,24 @@ module Diffend
48
46
  # @param response [Hash] response from diffend API
49
47
  def build_error(response)
50
48
  build_error_message(response)
51
- .tap(&Bundler.ui.method(:error))
49
+ .tap(&config.logger.method(:error))
52
50
 
53
51
  raise Diffend::Errors::HandledException
54
52
  end
55
53
 
56
- # @param command [String] either install or update
57
- # @param config [OpenStruct] diffend config
54
+ # @param config [Diffend::Config]
58
55
  # @param response [Hash] response from diffend API
59
- def build_verdict(command, config, response)
56
+ def build_verdict(config, response)
60
57
  case response['action']
61
58
  when 'allow'
62
- build_allow_message(command, response)
63
- .tap(&Bundler.ui.method(:confirm))
59
+ build_allow_message(config.command, response)
60
+ .tap(&config.logger.method(:info))
64
61
  when 'warn'
65
- build_warn_message(command, response)
66
- .tap(&Bundler.ui.method(:warn))
62
+ build_warn_message(config.command, response)
63
+ .tap(&config.logger.method(:warn))
67
64
  when 'deny'
68
- build_deny_message(command, response)
69
- .tap(&Bundler.ui.method(:error))
65
+ build_deny_message(config.command, response)
66
+ .tap(&config.logger.method(:error))
70
67
 
71
68
  exit 1
72
69
  else
@@ -89,7 +86,7 @@ module Diffend
89
86
  MSG
90
87
  end
91
88
 
92
- # @param command [String] either install or update
89
+ # @param command [String] command executed via bundler
93
90
  # @param response [Hash] response from diffend API
94
91
  #
95
92
  # @return [String]
@@ -101,7 +98,7 @@ module Diffend
101
98
  MSG
102
99
  end
103
100
 
104
- # @param command [String] either install or update
101
+ # @param command [String] command executed via bundler
105
102
  # @param response [Hash] response from diffend API
106
103
  #
107
104
  # @return [String]
@@ -113,7 +110,7 @@ module Diffend
113
110
  MSG
114
111
  end
115
112
 
116
- # @param command [String] either install or update
113
+ # @param command [String] command executed via bundler
117
114
  # @param response [Hash] response from diffend API
118
115
  #
119
116
  # @return [String]
@@ -126,7 +123,7 @@ module Diffend
126
123
  end
127
124
 
128
125
  # @param type [String] verdict type
129
- # @param command [String] either install or update
126
+ # @param command [String] command executed via bundler
130
127
  #
131
128
  # @return [String]
132
129
  def build_message_header(type, command)