diffend 0.2.31 → 0.2.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/lib/diffend/build_bundler_definition.rb +1 -1
- data/lib/diffend/config.rb +74 -12
- data/lib/diffend/{config → configs}/fetcher.rb +11 -39
- data/lib/diffend/{config → configs}/file_finder.rb +1 -1
- data/lib/diffend/configs/validator.rb +85 -0
- data/lib/diffend/execute.rb +21 -24
- data/lib/diffend/handle_errors/report.rb +9 -17
- data/lib/diffend/latest_version.rb +50 -0
- data/lib/diffend/local_context.rb +4 -5
- data/lib/diffend/local_context/diffend.rb +4 -4
- data/lib/diffend/local_context/packages.rb +2 -2
- data/lib/diffend/logger.rb +66 -0
- data/lib/diffend/monitor.rb +11 -8
- data/lib/diffend/plugin.rb +10 -48
- data/lib/diffend/request.rb +8 -8
- data/lib/diffend/request_verdict.rb +8 -22
- data/lib/diffend/track.rb +7 -20
- data/lib/diffend/version.rb +1 -1
- metadata +7 -5
- metadata.gz.sig +0 -0
- data/lib/diffend/config/validator.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e0efaea5a8bb4c724e24057821578b6c257a5eb313c472ac17dd60747fe10e4
|
4
|
+
data.tar.gz: af3b702fa128eabcc8f6f054895c0e64097f38672b650697e292ab705b749b69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00e60e3f610e03cad43a65b11c1b7f17d839d4b43009dde4436b9eebd96b82bdbf0035860eb85fb0e57c7042221403894a1aaf5f89cb606a86dd15e94f65bc58
|
7
|
+
data.tar.gz: f45b310e0e376b50e27b7a1876f3704a3f282dbadac5c868b4548a4a6a2d582632aeb3f204e47fda5545f47807446e648b0bf2fe70b4a0abdefb17ea40cf1ff1
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
## [Unreleased][master]
|
4
4
|
|
5
|
+
## [0.2.32] (2020-10-02)
|
6
|
+
- fix how we build platform from `Gem::Platform` ([#56](https://github.com/diffend-io/diffend-ruby/pull/56))
|
7
|
+
- introduce `Diffend::LatestVersion` ([#57](https://github.com/diffend-io/diffend-ruby/pull/57))
|
8
|
+
- refactor `Diffend::Config` ([#58](https://github.com/diffend-io/diffend-ruby/pull/58))
|
9
|
+
- set command in `Diffend::Config` ([#59](https://github.com/diffend-io/diffend-ruby/pull/59))
|
10
|
+
- introduce `Diffend::Logger` ([#60](https://github.com/diffend-io/diffend-ruby/pull/60))
|
11
|
+
- set severity to `FATAL` in `Diffend::Monitor` ([#61](https://github.com/diffend-io/diffend-ruby/pull/61))
|
12
|
+
- handle `Bundler::VersionConflict` ([#62](https://github.com/diffend-io/diffend-ruby/pull/62))
|
13
|
+
|
5
14
|
## [0.2.31] (2020-09-24)
|
6
15
|
- change request timeout to 15 seconds ([#53](https://github.com/diffend-io/diffend-ruby/pull/53))
|
7
16
|
- report request issues as warnings ([#54](https://github.com/diffend-io/diffend-ruby/pull/54))
|
data/Gemfile.lock
CHANGED
@@ -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]
|
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
|
#
|
data/lib/diffend/config.rb
CHANGED
@@ -2,18 +2,80 @@
|
|
2
2
|
|
3
3
|
module Diffend
|
4
4
|
# Diffend config object
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
+
#
|
12
|
+
# @raise [Errors::MissingConfigurationFile] when no config file
|
13
|
+
def initialize(command: nil, severity: nil, build_path: nil)
|
14
|
+
@log_level = severity
|
15
|
+
build(command, build_path)
|
16
|
+
validate
|
17
|
+
end
|
18
|
+
|
19
|
+
def logger
|
20
|
+
@logger ||= Diffend::Logger.new(@log_level)
|
21
|
+
end
|
22
|
+
|
23
|
+
def ignore_errors?
|
24
|
+
@ignore_errors
|
25
|
+
end
|
26
|
+
|
27
|
+
def development?
|
28
|
+
@development
|
29
|
+
end
|
30
|
+
|
31
|
+
# Provides diffend commands endpoint url
|
32
|
+
#
|
33
|
+
# @return [String]
|
34
|
+
def commands_url
|
35
|
+
return ENV['DIFFEND_COMMANDS_URL'] if ENV.key?('DIFFEND_COMMANDS_URL')
|
36
|
+
|
37
|
+
"https://my.diffend.io/api/projects/#{project_id}/bundle/#{command}"
|
38
|
+
end
|
39
|
+
|
40
|
+
# Provides diffend errors endpoint url
|
41
|
+
#
|
42
|
+
# @return [String]
|
43
|
+
def errors_url
|
44
|
+
return ENV['DIFFEND_ERRORS_URL'] if ENV.key?('DIFFEND_ERRORS_URL')
|
45
|
+
|
46
|
+
"https://my.diffend.io/api/projects/#{project_id}/errors"
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param request_id [String]
|
50
|
+
#
|
51
|
+
# @return [String]
|
52
|
+
def track_url(request_id)
|
53
|
+
"https://my.diffend.io/api/projects/#{project_id}/bundle/#{request_id}/track"
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def build(command, build_path)
|
59
|
+
build_path ||= File.expand_path('..', ::Bundler.bin_path)
|
60
|
+
hash = Diffend::Configs::Fetcher.call(logger, build_path)
|
61
|
+
hash['build_path'] = build_path
|
62
|
+
hash['env'] = ENV['DIFFEND_ENV'] || 'development'
|
63
|
+
hash['ignore_errors'] = ENV['DIFFEND_IGNORE_ERRORS'] == 'true'
|
64
|
+
hash['development'] = ENV['DIFFEND_DEVELOPMENT'] == 'true'
|
65
|
+
hash['command'] = command || build_command
|
66
|
+
|
67
|
+
hash.each { |key, value| instance_variable_set(:"@#{key}", value) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def validate
|
71
|
+
Diffend::Configs::Validator.call(self)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Command that was run with bundle
|
75
|
+
#
|
76
|
+
# @return [String]
|
77
|
+
def build_command
|
78
|
+
ARGV.first || ::Bundler.feature_flag.default_cli_command.to_s
|
17
79
|
end
|
18
80
|
end
|
19
81
|
end
|
@@ -4,41 +4,33 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
module Diffend
|
6
6
|
# Module for all the components related to setting up the config
|
7
|
-
module
|
7
|
+
module Configs
|
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
|
-
|
18
10
|
class << self
|
11
|
+
# @param logger [Diffend::Logger]
|
19
12
|
# @param build_path [String] path of the current build
|
20
13
|
#
|
21
|
-
# @return [
|
14
|
+
# @return [Hash] details from configuration file
|
22
15
|
#
|
23
16
|
# @example
|
24
17
|
# details = Fetcher.new.call('./')
|
25
18
|
# details.build_path #=> './'
|
26
|
-
def call(build_path)
|
19
|
+
def call(logger, build_path)
|
27
20
|
build(build_path)
|
28
21
|
rescue Errors::MissingConfigurationFile
|
29
|
-
|
22
|
+
build_missing_error_message(build_path)
|
23
|
+
.tap(&logger.method(:fatal))
|
30
24
|
|
31
25
|
raise Diffend::Errors::HandledException
|
32
26
|
rescue Errors::EmptyConfigurationFile
|
33
|
-
|
27
|
+
build_empty_error_message(build_path)
|
28
|
+
.tap(&logger.method(:fatal))
|
34
29
|
|
35
30
|
raise Diffend::Errors::HandledException
|
36
31
|
rescue Errors::MalformedConfigurationFile
|
37
|
-
|
38
|
-
|
39
|
-
raise Diffend::Errors::HandledException
|
40
|
-
rescue *MISSING_KEY_ERRORS => e
|
41
|
-
Bundler.ui.error(build_missing_key_error_message(e))
|
32
|
+
build_malformed_error_message(build_path)
|
33
|
+
.tap(&logger.method(:fatal))
|
42
34
|
|
43
35
|
raise Diffend::Errors::HandledException
|
44
36
|
end
|
@@ -57,8 +49,7 @@ module Diffend
|
|
57
49
|
|
58
50
|
raise Errors::EmptyConfigurationFile if content.empty?
|
59
51
|
|
60
|
-
|
61
|
-
.tap(&Validator.method(:call))
|
52
|
+
parse_file(content)
|
62
53
|
end
|
63
54
|
|
64
55
|
def parse_file(content)
|
@@ -92,25 +83,6 @@ module Diffend
|
|
92
83
|
Please re-setup.\n
|
93
84
|
MSG
|
94
85
|
end
|
95
|
-
|
96
|
-
# @return [String] malformed configuration file message
|
97
|
-
def build_missing_key_error_message(exception)
|
98
|
-
missing_key = missing_key_from_exception(exception)
|
99
|
-
|
100
|
-
<<~MSG
|
101
|
-
\nYour Diffend configuration file is missing #{missing_key} key.\n
|
102
|
-
Please re-setup.\n
|
103
|
-
MSG
|
104
|
-
end
|
105
|
-
|
106
|
-
def missing_key_from_exception(exception)
|
107
|
-
case exception
|
108
|
-
when Errors::ProjectIdMissingInConfigurationFile then 'project_id'
|
109
|
-
when Errors::ShareableIdMissingInConfigurationFile then 'shareable_id'
|
110
|
-
when Errors::ShareableKeyMissingInConfigurationFile then 'shareable_key'
|
111
|
-
when Errors::BuildPathMissingInConfigurationFile then 'build_path'
|
112
|
-
end
|
113
|
-
end
|
114
86
|
end
|
115
87
|
end
|
116
88
|
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
|
data/lib/diffend/execute.rb
CHANGED
@@ -6,12 +6,11 @@ module Diffend
|
|
6
6
|
class << self
|
7
7
|
# Build verdict
|
8
8
|
#
|
9
|
-
# @param
|
10
|
-
|
11
|
-
def call(command, config)
|
9
|
+
# @param config [Diffend::Config]
|
10
|
+
def call(config)
|
12
11
|
Diffend::RequestVerdict
|
13
|
-
.call(
|
14
|
-
.tap { |response| build_message(
|
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
|
31
|
-
# @param config [OpenStruct] diffend config
|
29
|
+
# @param config [Diffend::Config]
|
32
30
|
# @param response [Hash] response from diffend API
|
33
|
-
def build_message(
|
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(
|
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(&
|
49
|
+
.tap(&config.logger.method(:error))
|
52
50
|
|
53
51
|
raise Diffend::Errors::HandledException
|
54
52
|
end
|
55
53
|
|
56
|
-
# @param
|
57
|
-
# @param config [OpenStruct] diffend config
|
54
|
+
# @param config [Diffend::Config]
|
58
55
|
# @param response [Hash] response from diffend API
|
59
|
-
def build_verdict(
|
56
|
+
def build_verdict(config, response)
|
60
57
|
case response['action']
|
61
58
|
when 'allow'
|
62
|
-
build_allow_message(command, response)
|
63
|
-
.tap(&
|
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(&
|
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(&
|
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]
|
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]
|
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]
|
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]
|
126
|
+
# @param command [String] command executed via bundler
|
130
127
|
#
|
131
128
|
# @return [String]
|
132
129
|
def build_message_header(type, command)
|
@@ -7,10 +7,10 @@ module Diffend
|
|
7
7
|
class << self
|
8
8
|
# Execute request to Diffend
|
9
9
|
#
|
10
|
+
# @param config [Diffend::Config]
|
11
|
+
# @param message [Symbol] message that we want to display
|
10
12
|
# @param exception [Exception] expection that was raised
|
11
13
|
# @param payload [Hash] with versions to check
|
12
|
-
# @param config [OpenStruct] Diffend config
|
13
|
-
# @param message [Symbol] message that we want to display
|
14
14
|
# @param report [Boolean] if true we will report the issue to diffend
|
15
15
|
# @param raise_exception [Boolean] if true we will raise an exception
|
16
16
|
#
|
@@ -18,8 +18,11 @@ module Diffend
|
|
18
18
|
def call(config:, message:, exception: nil, payload: {}, report: false, raise_exception: true)
|
19
19
|
exception_payload = prepare_exception_payload(exception, payload)
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
Diffend::HandleErrors::Messages::PAYLOAD_DUMP
|
22
|
+
.tap(&config.logger.method(:error))
|
23
|
+
Diffend::HandleErrors::Messages
|
24
|
+
.const_get(message.to_s.upcase)
|
25
|
+
.tap(&config.logger.method(:error))
|
23
26
|
|
24
27
|
if report
|
25
28
|
Diffend::Request.call(
|
@@ -30,14 +33,14 @@ module Diffend
|
|
30
33
|
raise Diffend::Errors::HandledException if raise_exception
|
31
34
|
end
|
32
35
|
|
33
|
-
# @param config [
|
36
|
+
# @param config [Diffend::Config]
|
34
37
|
# @param payload [Hash]
|
35
38
|
#
|
36
39
|
# @return [Diffend::RequestObject]
|
37
40
|
def build_request_object(config, payload)
|
38
41
|
Diffend::RequestObject.new(
|
39
42
|
config: config,
|
40
|
-
url:
|
43
|
+
url: config.errors_url,
|
41
44
|
payload: payload,
|
42
45
|
request_method: :post
|
43
46
|
)
|
@@ -54,17 +57,6 @@ module Diffend
|
|
54
57
|
.call(exception, payload)
|
55
58
|
.tap(&Diffend::HandleErrors::DisplayToStdout.method(:call))
|
56
59
|
end
|
57
|
-
|
58
|
-
# Provides diffend errors endpoint url
|
59
|
-
#
|
60
|
-
# @param project_id [String] diffend project_id
|
61
|
-
#
|
62
|
-
# @return [String] diffend endpoint
|
63
|
-
def errors_url(project_id)
|
64
|
-
return ENV['DIFFEND_ERROR_URL'] if ENV.key?('DIFFEND_ERROR_URL')
|
65
|
-
|
66
|
-
"https://my.diffend.io/api/projects/#{project_id}/errors"
|
67
|
-
end
|
68
60
|
end
|
69
61
|
end
|
70
62
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Diffend
|
4
|
+
# Verify if we are running latest version of the plugin
|
5
|
+
module LatestVersion
|
6
|
+
class << self
|
7
|
+
# Verify if we are running latest version of the plugin
|
8
|
+
#
|
9
|
+
# @param config [Diffend::Config]
|
10
|
+
def call(config)
|
11
|
+
return if config.development?
|
12
|
+
return if installed_version == Diffend::VERSION
|
13
|
+
|
14
|
+
print_message(config, installed_version)
|
15
|
+
|
16
|
+
exit 2
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# @return [String] installed plugin version
|
22
|
+
def installed_version
|
23
|
+
::Bundler::Plugin
|
24
|
+
.index
|
25
|
+
.plugin_path('diffend')
|
26
|
+
.basename
|
27
|
+
.to_s
|
28
|
+
.split('-')
|
29
|
+
.last
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param config [Diffend::Config]
|
33
|
+
# @param version [Hash] installed version
|
34
|
+
def print_message(config, version)
|
35
|
+
build_message(version)
|
36
|
+
.tap(&config.logger.method(:error))
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param version [Hash] installed version
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
def build_message(version)
|
43
|
+
<<~MSG
|
44
|
+
\nYou are running an outdated version (#{version}) of the plugin, which will lead to issues.
|
45
|
+
\nPlease upgrade to the latest one (#{Diffend::VERSION}) by executing "rm -rf .bundle/plugin".\n
|
46
|
+
MSG
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -6,16 +6,15 @@ module Diffend
|
|
6
6
|
class << self
|
7
7
|
# Build diffend, host, packages, and platform specific information
|
8
8
|
#
|
9
|
-
# @param
|
10
|
-
# @param project_id [String] diffend project_id
|
9
|
+
# @param config [Diffend::Config]
|
11
10
|
# @param definition [Bundler::Definition] definition for your source
|
12
11
|
#
|
13
12
|
# @return [Hash] payload for diffend endpoint
|
14
|
-
def call(
|
13
|
+
def call(config, definition)
|
15
14
|
{
|
16
|
-
'diffend' => Diffend.call(
|
15
|
+
'diffend' => Diffend.call(config),
|
17
16
|
'host' => Host.call,
|
18
|
-
'packages' => Packages.call(command, definition),
|
17
|
+
'packages' => Packages.call(config.command, definition),
|
19
18
|
'platform' => Platform.call
|
20
19
|
}.freeze
|
21
20
|
end
|
@@ -15,14 +15,14 @@ module Diffend
|
|
15
15
|
class << self
|
16
16
|
# Build diffend information
|
17
17
|
#
|
18
|
-
# @param
|
18
|
+
# @param config [Diffend::Config]
|
19
19
|
#
|
20
20
|
# @return [Hash]
|
21
|
-
def call(
|
21
|
+
def call(config)
|
22
22
|
{
|
23
23
|
'api_version' => API_VERSION,
|
24
|
-
'environment' =>
|
25
|
-
'project_id' => project_id,
|
24
|
+
'environment' => config.env,
|
25
|
+
'project_id' => config.project_id,
|
26
26
|
'type' => PLATFORM_TYPE,
|
27
27
|
'version' => ::Diffend::VERSION
|
28
28
|
}.freeze
|
@@ -31,7 +31,7 @@ module Diffend
|
|
31
31
|
}.freeze
|
32
32
|
|
33
33
|
class << self
|
34
|
-
# @param command [String]
|
34
|
+
# @param command [String] command executed via bundler
|
35
35
|
# @param definition [Bundler::Definition] definition for your source
|
36
36
|
def call(command, definition)
|
37
37
|
Bundler.ui.silence { definition.resolve_remotely! }
|
@@ -161,7 +161,7 @@ module Diffend
|
|
161
161
|
def parse_platform(platform)
|
162
162
|
case platform
|
163
163
|
when String then platform
|
164
|
-
when Gem::Platform then platform.
|
164
|
+
when Gem::Platform then platform.to_s
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Diffend
|
4
|
+
# Diffend logging
|
5
|
+
class Logger
|
6
|
+
# Low-level information, mostly for developers.
|
7
|
+
DEBUG = 0
|
8
|
+
# Generic (useful) information about system operation.
|
9
|
+
INFO = 1
|
10
|
+
# A warning.
|
11
|
+
WARN = 2
|
12
|
+
# A handleable error condition.
|
13
|
+
ERROR = 3
|
14
|
+
# An unhandleable error that results in a program crash.
|
15
|
+
FATAL = 4
|
16
|
+
# An unknown message that should always be logged.
|
17
|
+
UNKNOWN = 5
|
18
|
+
|
19
|
+
# @param level [Integer] logging severity threshold
|
20
|
+
def initialize(level = INFO)
|
21
|
+
@level = level
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param message [String]
|
25
|
+
def debug(message)
|
26
|
+
log(DEBUG, message)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param message [String]
|
30
|
+
def info(message)
|
31
|
+
log(INFO, message)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param message [String]
|
35
|
+
def warn(message)
|
36
|
+
log(WARN, message)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param message [String]
|
40
|
+
def error(message)
|
41
|
+
log(ERROR, message)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param message [String]
|
45
|
+
def fatal(message)
|
46
|
+
log(FATAL, message)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# @param severity [Integer]
|
52
|
+
# @param message [String]
|
53
|
+
def log(severity, message)
|
54
|
+
return if severity < @level
|
55
|
+
|
56
|
+
case severity
|
57
|
+
when INFO
|
58
|
+
Bundler.ui.confirm(message)
|
59
|
+
when WARN
|
60
|
+
Bundler.ui.warn(message)
|
61
|
+
when ERROR, FATAL
|
62
|
+
Bundler.ui.error(message)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/diffend/monitor.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
ENV['DIFFEND_ENV'] ||= 'development'
|
4
|
-
|
5
3
|
%w[
|
6
4
|
version
|
5
|
+
logger
|
7
6
|
errors
|
8
7
|
build_bundler_definition
|
9
8
|
commands
|
10
9
|
config
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
configs/fetcher
|
11
|
+
configs/file_finder
|
12
|
+
configs/validator
|
14
13
|
handle_errors/messages
|
15
14
|
handle_errors/build_exception_payload
|
16
15
|
handle_errors/display_to_stdout
|
@@ -27,10 +26,14 @@ ENV['DIFFEND_ENV'] ||= 'development'
|
|
27
26
|
track
|
28
27
|
].each { |file| require "diffend/#{file}" }
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
config = Diffend::Config.new(
|
30
|
+
command: Diffend::Commands::EXEC,
|
31
|
+
severity: Diffend::Logger::FATAL
|
32
|
+
)
|
33
|
+
|
34
|
+
return if %w[development test].include?(config.env)
|
32
35
|
|
33
36
|
Thread.new do
|
34
|
-
track = Diffend::Track.new
|
37
|
+
track = Diffend::Track.new(config)
|
35
38
|
track.start
|
36
39
|
end
|
data/lib/diffend/plugin.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
ENV['DIFFEND_ENV'] ||= 'development'
|
4
|
-
|
5
3
|
%w[
|
6
4
|
bundler
|
7
5
|
].each(&method(:require))
|
8
6
|
|
9
7
|
%w[
|
10
8
|
version
|
9
|
+
logger
|
10
|
+
latest_version
|
11
11
|
errors
|
12
12
|
build_bundler_definition
|
13
13
|
commands
|
14
14
|
config
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
configs/fetcher
|
16
|
+
configs/file_finder
|
17
|
+
configs/validator
|
18
18
|
handle_errors/messages
|
19
19
|
handle_errors/build_exception_payload
|
20
20
|
handle_errors/display_to_stdout
|
@@ -45,13 +45,13 @@ module Diffend
|
|
45
45
|
def execute
|
46
46
|
return unless enabled?
|
47
47
|
|
48
|
-
|
48
|
+
config = Diffend::Config.new(severity: Diffend::Logger::INFO)
|
49
49
|
|
50
|
-
|
50
|
+
Diffend::LatestVersion.call(config)
|
51
51
|
|
52
|
-
Diffend::Execute.call(
|
52
|
+
Diffend::Execute.call(config)
|
53
53
|
rescue Diffend::Errors::HandledException
|
54
|
-
return if
|
54
|
+
return if config.ignore_errors?
|
55
55
|
|
56
56
|
exit 255
|
57
57
|
rescue StandardError => e
|
@@ -63,32 +63,11 @@ module Diffend
|
|
63
63
|
raise_exception: false
|
64
64
|
)
|
65
65
|
|
66
|
-
return if
|
66
|
+
return if config.ignore_errors?
|
67
67
|
|
68
68
|
exit 255
|
69
69
|
end
|
70
70
|
|
71
|
-
def verify_version
|
72
|
-
return if ENV['DIFFEND_DEVELOPMENT'] == 'true'
|
73
|
-
return if installed_version == Diffend::VERSION
|
74
|
-
|
75
|
-
build_outdated_version_message(installed_version)
|
76
|
-
.tap(&::Bundler.ui.method(:error))
|
77
|
-
|
78
|
-
exit 2
|
79
|
-
end
|
80
|
-
|
81
|
-
# @return [String] installed plugin version
|
82
|
-
def installed_version
|
83
|
-
::Bundler::Plugin
|
84
|
-
.index
|
85
|
-
.plugin_path('diffend')
|
86
|
-
.basename
|
87
|
-
.to_s
|
88
|
-
.split('-')
|
89
|
-
.last
|
90
|
-
end
|
91
|
-
|
92
71
|
# Checks if plugin is enabled
|
93
72
|
#
|
94
73
|
# @return [Boolean] true if enabled, false otherwise
|
@@ -102,23 +81,6 @@ module Diffend
|
|
102
81
|
.select { |line| line.start_with?('plugin') }
|
103
82
|
.any? { |line| line.include?('diffend') }
|
104
83
|
end
|
105
|
-
|
106
|
-
# @param version [Hash] installed version
|
107
|
-
#
|
108
|
-
# @return [String]
|
109
|
-
def build_outdated_version_message(version)
|
110
|
-
<<~MSG
|
111
|
-
\nYou are running an outdated version (#{version}) of the plugin, which will lead to issues.
|
112
|
-
\nPlease upgrade to the latest one (#{VERSION}) by executing "rm -rf .bundle/plugin".\n
|
113
|
-
MSG
|
114
|
-
end
|
115
|
-
|
116
|
-
# Command that was run with bundle
|
117
|
-
#
|
118
|
-
# @return [String]
|
119
|
-
def command
|
120
|
-
ARGV.first || ::Bundler.feature_flag.default_cli_command.to_s
|
121
|
-
end
|
122
84
|
end
|
123
85
|
end
|
124
86
|
end
|
data/lib/diffend/request.rb
CHANGED
@@ -67,7 +67,7 @@ module Diffend
|
|
67
67
|
rescue Diffend::Errors::RequestServerError => e
|
68
68
|
retry_count += 1
|
69
69
|
|
70
|
-
retry if handle_retry(SERVER_ERROR_MESSAGE, retry_count)
|
70
|
+
retry if handle_retry(request_object.config, SERVER_ERROR_MESSAGE, retry_count)
|
71
71
|
|
72
72
|
Diffend::HandleErrors::Report.call(
|
73
73
|
exception: e,
|
@@ -78,7 +78,7 @@ module Diffend
|
|
78
78
|
rescue *CONNECTION_EXCEPTIONS => e
|
79
79
|
retry_count += 1
|
80
80
|
|
81
|
-
retry if handle_retry(CONNECTION_MESSAGE, retry_count)
|
81
|
+
retry if handle_retry(request_object.config, CONNECTION_MESSAGE, retry_count)
|
82
82
|
|
83
83
|
Diffend::HandleErrors::Report.call(
|
84
84
|
exception: e,
|
@@ -89,7 +89,7 @@ module Diffend
|
|
89
89
|
rescue *TIMEOUT_EXCEPTIONS => e
|
90
90
|
retry_count += 1
|
91
91
|
|
92
|
-
retry if handle_retry(TIMEOUT_MESSAGE, retry_count)
|
92
|
+
retry if handle_retry(request_object.config, TIMEOUT_MESSAGE, retry_count)
|
93
93
|
|
94
94
|
Diffend::HandleErrors::Report.call(
|
95
95
|
exception: e,
|
@@ -101,12 +101,13 @@ module Diffend
|
|
101
101
|
|
102
102
|
# Handle retry
|
103
103
|
#
|
104
|
+
# @param config [Diffend::Config]
|
104
105
|
# @param message [String] message we want to display
|
105
106
|
# @param retry_count [Integer]
|
106
|
-
def handle_retry(message, retry_count)
|
107
|
+
def handle_retry(config, message, retry_count)
|
107
108
|
return false if retry_count == RETRIES
|
108
109
|
|
109
|
-
|
110
|
+
config.logger.warn(message)
|
110
111
|
sleep(exponential_backoff(retry_count))
|
111
112
|
|
112
113
|
retry_count < RETRIES
|
@@ -132,7 +133,7 @@ module Diffend
|
|
132
133
|
#
|
133
134
|
# @param uri [URI::HTTPS]
|
134
135
|
# @param request_method [Symbol]
|
135
|
-
# @param config [
|
136
|
+
# @param config [Diffend::Config]
|
136
137
|
# @param payload [Hash] with versions to check
|
137
138
|
#
|
138
139
|
# @return [Net::HTTP::Post, Net::HTTP::Put]
|
@@ -160,9 +161,8 @@ module Diffend
|
|
160
161
|
# Assigns basic authorization if provided in the config
|
161
162
|
#
|
162
163
|
# @param request [Net::HTTP::Post] prepared http post
|
163
|
-
# @param config [
|
164
|
+
# @param config [Diffend::Config]
|
164
165
|
def assign_auth(request, config)
|
165
|
-
return unless config
|
166
166
|
return unless config.shareable_id
|
167
167
|
return unless config.shareable_key
|
168
168
|
|
@@ -6,18 +6,17 @@ module Diffend
|
|
6
6
|
# Module responsible for fetching diffend verdict on local context
|
7
7
|
module RequestVerdict
|
8
8
|
class << self
|
9
|
-
# @param
|
9
|
+
# @param config [Diffend::Config]
|
10
10
|
# @param definition [Bundler::Definition] definition for your source
|
11
|
-
|
12
|
-
|
13
|
-
payload = Diffend::LocalContext.call(command, config.project_id, definition)
|
11
|
+
def call(config, definition)
|
12
|
+
payload = Diffend::LocalContext.call(config, definition)
|
14
13
|
|
15
14
|
response = Diffend::Request.call(
|
16
|
-
build_request_object(
|
15
|
+
build_request_object(config, payload)
|
17
16
|
)
|
18
17
|
|
19
18
|
JSON.parse(response.body)
|
20
|
-
rescue Bundler::GemNotFound
|
19
|
+
rescue Bundler::GemNotFound, Bundler::VersionConflict
|
21
20
|
raise ::Diffend::Errors::DependenciesResolveException
|
22
21
|
rescue StandardError => e
|
23
22
|
Diffend::HandleErrors::Report.call(
|
@@ -29,31 +28,18 @@ module Diffend
|
|
29
28
|
)
|
30
29
|
end
|
31
30
|
|
32
|
-
# @param
|
33
|
-
# @param config [OpenStruct] diffend config
|
31
|
+
# @param config [Diffend::Config]
|
34
32
|
# @param payload [Hash]
|
35
33
|
#
|
36
34
|
# @return [Diffend::RequestObject]
|
37
|
-
def build_request_object(
|
35
|
+
def build_request_object(config, payload)
|
38
36
|
Diffend::RequestObject.new(
|
39
37
|
config: config,
|
40
|
-
url:
|
38
|
+
url: config.commands_url,
|
41
39
|
payload: payload,
|
42
40
|
request_method: :post
|
43
41
|
)
|
44
42
|
end
|
45
|
-
|
46
|
-
# Provides diffend command endpoint url
|
47
|
-
#
|
48
|
-
# @param command [String] either install or update
|
49
|
-
# @param project_id [String] diffend project_id
|
50
|
-
#
|
51
|
-
# @return [String] diffend endpoint
|
52
|
-
def commands_url(command, project_id)
|
53
|
-
return ENV['DIFFEND_COMMAND_URL'] if ENV.key?('DIFFEND_COMMAND_URL')
|
54
|
-
|
55
|
-
"https://my.diffend.io/api/projects/#{project_id}/bundle/#{command}"
|
56
|
-
end
|
57
43
|
end
|
58
44
|
end
|
59
45
|
end
|
data/lib/diffend/track.rb
CHANGED
@@ -9,14 +9,16 @@ module Diffend
|
|
9
9
|
RETRY_SLEEP = 15
|
10
10
|
|
11
11
|
# Initialize tracking
|
12
|
-
|
12
|
+
#
|
13
|
+
# @param config [Diffend::Config]
|
14
|
+
def initialize(config)
|
13
15
|
@mutex = Mutex.new
|
14
|
-
@config =
|
16
|
+
@config = config
|
15
17
|
end
|
16
18
|
|
17
19
|
# Start tracking
|
18
20
|
def start
|
19
|
-
response =
|
21
|
+
response = Diffend::Execute.call(@config)
|
20
22
|
|
21
23
|
perform(response['id'])
|
22
24
|
rescue Diffend::Errors::HandledException
|
@@ -40,19 +42,12 @@ module Diffend
|
|
40
42
|
# @param request_id [String]
|
41
43
|
def perform(request_id)
|
42
44
|
loop do
|
43
|
-
@mutex.synchronize
|
44
|
-
track_request(request_id)
|
45
|
-
end
|
45
|
+
@mutex.synchronize { track_request(request_id) }
|
46
46
|
|
47
47
|
sleep(TRACK_SLEEP)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
# Perform an exec request
|
52
|
-
def exec_request
|
53
|
-
Diffend::Execute.call(Diffend::Commands::EXEC, @config)
|
54
|
-
end
|
55
|
-
|
56
51
|
# Perform a track request
|
57
52
|
#
|
58
53
|
# @param request_id [String]
|
@@ -68,18 +63,10 @@ module Diffend
|
|
68
63
|
def build_request_object(request_id)
|
69
64
|
Diffend::RequestObject.new(
|
70
65
|
config: @config,
|
71
|
-
url:
|
66
|
+
url: @config.track_url(request_id),
|
72
67
|
payload: { id: request_id }.freeze,
|
73
68
|
request_method: :put
|
74
69
|
).freeze
|
75
70
|
end
|
76
|
-
|
77
|
-
# @param project_id [String] diffend project_id
|
78
|
-
# @param request_id [String]
|
79
|
-
#
|
80
|
-
# @return [String]
|
81
|
-
def track_url(project_id, request_id)
|
82
|
-
"https://my.diffend.io/api/projects/#{project_id}/bundle/#{request_id}/track"
|
83
|
-
end
|
84
71
|
end
|
85
72
|
end
|
data/lib/diffend/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.32
|
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-
|
37
|
+
date: 2020-10-02 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: bundler
|
@@ -95,20 +95,22 @@ files:
|
|
95
95
|
- lib/diffend/build_bundler_definition.rb
|
96
96
|
- lib/diffend/commands.rb
|
97
97
|
- lib/diffend/config.rb
|
98
|
-
- lib/diffend/
|
99
|
-
- lib/diffend/
|
100
|
-
- lib/diffend/
|
98
|
+
- lib/diffend/configs/fetcher.rb
|
99
|
+
- lib/diffend/configs/file_finder.rb
|
100
|
+
- lib/diffend/configs/validator.rb
|
101
101
|
- lib/diffend/errors.rb
|
102
102
|
- lib/diffend/execute.rb
|
103
103
|
- lib/diffend/handle_errors/build_exception_payload.rb
|
104
104
|
- lib/diffend/handle_errors/display_to_stdout.rb
|
105
105
|
- lib/diffend/handle_errors/messages.rb
|
106
106
|
- lib/diffend/handle_errors/report.rb
|
107
|
+
- lib/diffend/latest_version.rb
|
107
108
|
- lib/diffend/local_context.rb
|
108
109
|
- lib/diffend/local_context/diffend.rb
|
109
110
|
- lib/diffend/local_context/host.rb
|
110
111
|
- lib/diffend/local_context/packages.rb
|
111
112
|
- lib/diffend/local_context/platform.rb
|
113
|
+
- lib/diffend/logger.rb
|
112
114
|
- lib/diffend/monitor.rb
|
113
115
|
- lib/diffend/plugin.rb
|
114
116
|
- lib/diffend/request.rb
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,25 +0,0 @@
|
|
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
|