diffend-monitor 0.2.31 → 0.2.36

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: 8856c9521b44100d7bc4b5e74c23981e1e68b4c928520aa9184613bdcaa21132
4
- data.tar.gz: 9c5ba788a778bd498d6d637758a6bb82eebe22b1dc3a18d4cba74a5a0cbc7912
3
+ metadata.gz: 6894ce2349ae65f5159d8604b0ca268fceed97c1f03c4508d91b0149a6b2c52d
4
+ data.tar.gz: d7f457c94fd72d9be57e52535c40b6b49533da918e613a694cbd1be0db9749b3
5
5
  SHA512:
6
- metadata.gz: dc8022116960958ce72ebb0da96a6e52c801406f2cef2bf61adaf8fc82c9a11b6aedacac53a2dde59f927c71e763388e722eb9407b0db6a875ce1fe6d5ca24b6
7
- data.tar.gz: 5b892d7634c73d7fd65c65132613aecc678963e1ead23a847e9baa01b1bb93c2f92f77029ce9183452c10b2a4416844b9df5f4eabaeb07b122f5884b5b7b9c9c
6
+ metadata.gz: c2ada266ca68ee8fd17047b4156c22df8360bf55f070885ad77338b6d5b4f1c1adcf73945b6bb0ec47b006c01cafa5c1538cde8235e1dfe80576cd367a59cea4
7
+ data.tar.gz: c29713c40743d4c4489e22940446746f0418ae46cac74070535fa79f76110f0840b018c8ce2333a9e74556bbdbffa1a2a299c538a9554a179f25122fc498da6b
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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.36] (2020-12-06)
6
+ - handle `Bundler::PermissionError` ([#79](https://github.com/diffend-io/diffend-ruby/pull/79))
7
+ - use cache to resolve dependencies in exec mode ([#78](https://github.com/diffend-io/diffend-ruby/pull/78))
8
+
9
+ ## [0.2.35] (2020-11-04)
10
+ - clean command name and title of a process ([#76](https://github.com/diffend-io/diffend-ruby/pull/76))
11
+ - handle `uninitialized constant #<Class:Diffend::Configs::Fetcher>::ERB` ([#75](https://github.com/diffend-io/diffend-ruby/pull/75))
12
+
13
+ ## [0.2.34] (2020-10-25)
14
+ - handle `Bundler::GitError` ([#72](https://github.com/diffend-io/diffend-ruby/pull/72))
15
+
16
+ ## [0.2.33] (2020-10-25)
17
+ - fix an exception when configuration file is missing ([#65](https://github.com/diffend-io/diffend-ruby/pull/65))
18
+ - silently exit when configuration file is missing in `Diffend::Monitor` ([#66](https://github.com/diffend-io/diffend-ruby/pull/66))
19
+ - introduce default config ([#67](https://github.com/diffend-io/diffend-ruby/pull/67))
20
+ - handle `SocketError` ([#68](https://github.com/diffend-io/diffend-ruby/pull/68))
21
+
22
+ ## [0.2.32] (2020-10-02)
23
+ - fix how we build platform from `Gem::Platform` ([#56](https://github.com/diffend-io/diffend-ruby/pull/56))
24
+ - introduce `Diffend::LatestVersion` ([#57](https://github.com/diffend-io/diffend-ruby/pull/57))
25
+ - refactor `Diffend::Config` ([#58](https://github.com/diffend-io/diffend-ruby/pull/58))
26
+ - set command in `Diffend::Config` ([#59](https://github.com/diffend-io/diffend-ruby/pull/59))
27
+ - introduce `Diffend::Logger` ([#60](https://github.com/diffend-io/diffend-ruby/pull/60))
28
+ - set severity to `FATAL` in `Diffend::Monitor` ([#61](https://github.com/diffend-io/diffend-ruby/pull/61))
29
+ - handle `Bundler::VersionConflict` ([#62](https://github.com/diffend-io/diffend-ruby/pull/62))
30
+
5
31
  ## [0.2.31] (2020-09-24)
6
32
  - change request timeout to 15 seconds ([#53](https://github.com/diffend-io/diffend-ruby/pull/53))
7
33
  - report request issues as warnings ([#54](https://github.com/diffend-io/diffend-ruby/pull/54))
@@ -76,7 +102,13 @@
76
102
 
77
103
  - initial release
78
104
 
79
- [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.30...HEAD
105
+ [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.36...HEAD
106
+ [0.2.36]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.35...v0.2.36
107
+ [0.2.35]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.34...v0.2.35
108
+ [0.2.34]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.33...v0.2.34
109
+ [0.2.33]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.32...v0.2.33
110
+ [0.2.32]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.31...v0.2.32
111
+ [0.2.31]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.30...v0.2.31
80
112
  [0.2.30]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.29...v0.2.30
81
113
  [0.2.29]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.28...v0.2.29
82
114
  [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.31)
4
+ diffend (0.2.36)
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)