diffend 0.2.26 → 0.2.27
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 +8 -2
- data/Gemfile.lock +1 -1
- data/lib/diffend.rb +14 -3
- data/lib/diffend/commands.rb +4 -2
- data/lib/diffend/config/fetcher.rb +8 -4
- data/lib/diffend/errors.rb +2 -0
- data/lib/diffend/handle_errors/report.rb +17 -5
- data/lib/diffend/monitor.rb +28 -0
- data/lib/diffend/request.rb +35 -15
- data/lib/diffend/request_object.rb +6 -0
- data/lib/diffend/track.rb +104 -0
- data/lib/diffend/voting.rb +1 -1
- data/lib/diffend/voting/versions/local.rb +1 -1
- data/lib/diffend/voting/versions/remote.rb +15 -3
- metadata +5 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6539b727e33d38eb0b3fb6f38f25c3fd2abda05f337f50af2db1fe135575510
|
4
|
+
data.tar.gz: c6808082290c195a846117fd4c16a4fa4cb20f65cc289cbadbd71532f8ae5713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eb4e7749b9a9a0824770921d150e180ed5b40ba19a7f22d1f65154474347110221dc96049c2b4b5d7136c850c5775c07bc4e840b005dda13043742ac74238d2
|
7
|
+
data.tar.gz: 427d6b00c913174e535de300020f8fe715bda9b3f946f1fbe25906dfa734bb4dd3c349735470fbacb9740c287dd5252bcf6b481e40120daba3138afda6f334e9
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -2,8 +2,13 @@
|
|
2
2
|
|
3
3
|
## [Unreleased][master]
|
4
4
|
|
5
|
+
## [0.2.27] (2020-09-16)
|
6
|
+
- introduce `Diffend::RequestObject` ([#40](https://github.com/diffend-io/diffend-ruby/pull/40))
|
7
|
+
- clean up error codes and introduce `DIFFEND_INGORE_EXCEPTIONS` ([#41](https://github.com/diffend-io/diffend-ruby/pull/41))
|
8
|
+
- introduce `Diffend::Monitor` and `Diffend::Track` ([#15](https://github.com/diffend-io/diffend-ruby/pull/15))
|
9
|
+
|
5
10
|
## [0.2.26] (2020-09-10)
|
6
|
-
- introduce DIFFEND_DEVELOPMENT environment variable ([#36](https://github.com/diffend-io/diffend-ruby/pull/36))
|
11
|
+
- introduce `DIFFEND_DEVELOPMENT` environment variable ([#36](https://github.com/diffend-io/diffend-ruby/pull/36))
|
7
12
|
- adjust message for allow verdict ([#37](https://github.com/diffend-io/diffend-ruby/pull/37))
|
8
13
|
- do not run the plugin when it is not enabled ([#38](https://github.com/diffend-io/diffend-ruby/pull/38))
|
9
14
|
|
@@ -55,7 +60,8 @@
|
|
55
60
|
|
56
61
|
- initial release
|
57
62
|
|
58
|
-
[master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.
|
63
|
+
[master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.27...HEAD
|
64
|
+
[0.2.27]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.26...v0.2.27
|
59
65
|
[0.2.26]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.25...v0.2.26
|
60
66
|
[0.2.25]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.24...v0.2.25
|
61
67
|
[0.2.24]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.23...v0.2.24
|
data/Gemfile.lock
CHANGED
data/lib/diffend.rb
CHANGED
@@ -15,8 +15,10 @@
|
|
15
15
|
handle_errors/build_exception_payload
|
16
16
|
handle_errors/display_to_stdout
|
17
17
|
handle_errors/report
|
18
|
+
request_object
|
18
19
|
request
|
19
20
|
voting
|
21
|
+
track
|
20
22
|
].each { |file| require "diffend/#{file}" }
|
21
23
|
|
22
24
|
%w[
|
@@ -27,7 +29,7 @@
|
|
27
29
|
# Diffend main namespace
|
28
30
|
module Diffend
|
29
31
|
# Current plugin version
|
30
|
-
VERSION = '0.2.
|
32
|
+
VERSION = '0.2.27'
|
31
33
|
# Diffend homepage
|
32
34
|
HOMEPAGE = 'https://diffend.io'
|
33
35
|
|
@@ -56,13 +58,22 @@ module Diffend
|
|
56
58
|
Bundler.default_lockfile
|
57
59
|
)
|
58
60
|
)
|
61
|
+
rescue Diffend::Errors::HandledException
|
62
|
+
return if ENV['DIFFEND_IGNORE_ERRORS'] == 'true'
|
63
|
+
|
64
|
+
exit 255
|
59
65
|
rescue StandardError => e
|
60
66
|
Diffend::HandleErrors::Report.call(
|
61
67
|
exception: e,
|
62
68
|
config: config,
|
63
69
|
message: :unhandled_exception,
|
64
|
-
report: true
|
70
|
+
report: true,
|
71
|
+
raise_exception: false
|
65
72
|
)
|
73
|
+
|
74
|
+
return if ENV['DIFFEND_IGNORE_ERRORS'] == 'true'
|
75
|
+
|
76
|
+
exit 255
|
66
77
|
end
|
67
78
|
|
68
79
|
def verify_version
|
@@ -72,7 +83,7 @@ module Diffend
|
|
72
83
|
build_outdated_version_message(installed_version)
|
73
84
|
.tap(&Bundler.ui.method(:error))
|
74
85
|
|
75
|
-
exit
|
86
|
+
exit 2
|
76
87
|
end
|
77
88
|
|
78
89
|
# @return [String] installed plugin version
|
data/lib/diffend/commands.rb
CHANGED
@@ -3,9 +3,11 @@
|
|
3
3
|
module Diffend
|
4
4
|
# Modules grouping supported bundler commands
|
5
5
|
module Commands
|
6
|
-
#
|
6
|
+
# Bundler install command
|
7
7
|
INSTALL = 'install'
|
8
|
-
#
|
8
|
+
# Bundler update command
|
9
9
|
UPDATE = 'update'
|
10
|
+
# Bundler exec command
|
11
|
+
EXEC = 'exec'
|
10
12
|
end
|
11
13
|
end
|
@@ -27,16 +27,20 @@ module Diffend
|
|
27
27
|
build(build_path)
|
28
28
|
rescue Errors::MissingConfigurationFile
|
29
29
|
Bundler.ui.error(build_missing_error_message(build_path))
|
30
|
-
|
30
|
+
|
31
|
+
raise Diffend::Errors::HandledException
|
31
32
|
rescue Errors::EmptyConfigurationFile
|
32
33
|
Bundler.ui.error(build_empty_error_message(build_path))
|
33
|
-
|
34
|
+
|
35
|
+
raise Diffend::Errors::HandledException
|
34
36
|
rescue Errors::MalformedConfigurationFile
|
35
37
|
Bundler.ui.error(build_malformed_error_message(build_path))
|
36
|
-
|
38
|
+
|
39
|
+
raise Diffend::Errors::HandledException
|
37
40
|
rescue *MISSING_KEY_ERRORS => e
|
38
41
|
Bundler.ui.error(build_missing_key_error_message(e))
|
39
|
-
|
42
|
+
|
43
|
+
raise Diffend::Errors::HandledException
|
40
44
|
end
|
41
45
|
|
42
46
|
private
|
data/lib/diffend/errors.rb
CHANGED
@@ -21,5 +21,7 @@ module Diffend
|
|
21
21
|
BuildPathMissingInConfigurationFile = Class.new(BaseError)
|
22
22
|
# Raised when server-side error occurs
|
23
23
|
RequestServerError = Class.new(BaseError)
|
24
|
+
# Raised when we had an exception that we know how to handle
|
25
|
+
HandledException = Class.new(BaseError)
|
24
26
|
end
|
25
27
|
end
|
@@ -12,9 +12,10 @@ module Diffend
|
|
12
12
|
# @param config [OpenStruct] Diffend config
|
13
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
|
+
# @param raise_exception [Boolean] if true we will raise an exception
|
15
16
|
#
|
16
17
|
# @return [Net::HTTPResponse] response from Diffend
|
17
|
-
def call(config:, message:, exception: nil, payload: {}, report: false)
|
18
|
+
def call(config:, message:, exception: nil, payload: {}, report: false, raise_exception: true)
|
18
19
|
exception_payload = prepare_exception_payload(exception, payload)
|
19
20
|
|
20
21
|
Bundler.ui.error(Diffend::HandleErrors::Messages::PAYLOAD_DUMP)
|
@@ -22,13 +23,24 @@ module Diffend
|
|
22
23
|
|
23
24
|
if report
|
24
25
|
Diffend::Request.call(
|
25
|
-
config,
|
26
|
-
errors_url(config.project_id),
|
27
|
-
exception_payload
|
26
|
+
build_request_object(config, exception_payload)
|
28
27
|
)
|
29
28
|
end
|
30
29
|
|
31
|
-
|
30
|
+
raise Diffend::Errors::HandledException if raise_exception
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param config [OpenStruct] diffend config
|
34
|
+
# @param payload [Hash]
|
35
|
+
#
|
36
|
+
# @return [Diffend::RequestObject]
|
37
|
+
def build_request_object(config, payload)
|
38
|
+
Diffend::RequestObject.new(
|
39
|
+
config: config,
|
40
|
+
url: errors_url(config.project_id),
|
41
|
+
payload: payload,
|
42
|
+
request_method: :post
|
43
|
+
)
|
32
44
|
end
|
33
45
|
|
34
46
|
# Prepare exception payload and display it to stdout
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
%w[
|
4
|
+
build_bundler_definition
|
5
|
+
errors
|
6
|
+
config/fetcher
|
7
|
+
config/file_finder
|
8
|
+
config/validator
|
9
|
+
commands
|
10
|
+
handle_errors/messages
|
11
|
+
handle_errors/build_exception_payload
|
12
|
+
handle_errors/display_to_stdout
|
13
|
+
handle_errors/report
|
14
|
+
request_object
|
15
|
+
request
|
16
|
+
voting
|
17
|
+
track
|
18
|
+
].each { |file| require "diffend/#{file}" }
|
19
|
+
|
20
|
+
%w[
|
21
|
+
versions/local
|
22
|
+
versions/remote
|
23
|
+
].each { |file| require "diffend/voting/#{file}" }
|
24
|
+
|
25
|
+
Thread.new do
|
26
|
+
track = Diffend::Track.new
|
27
|
+
track.start
|
28
|
+
end
|
data/lib/diffend/request.rb
CHANGED
@@ -42,16 +42,21 @@ module Diffend
|
|
42
42
|
class << self
|
43
43
|
# Execute request
|
44
44
|
#
|
45
|
-
# @param
|
46
|
-
# @param endpoint_url [String]
|
47
|
-
# @param payload [Hash]
|
45
|
+
# @param request_object [Diffend::RequestObject]
|
48
46
|
#
|
49
47
|
# @return [Net::HTTPResponse] response from Diffend
|
50
|
-
def call(
|
48
|
+
def call(request_object)
|
51
49
|
retry_count ||= -1
|
52
50
|
|
53
|
-
build_http(
|
54
|
-
response = http.request(
|
51
|
+
build_http(request_object.url) do |http, uri|
|
52
|
+
response = http.request(
|
53
|
+
build_request(
|
54
|
+
uri,
|
55
|
+
request_object.request_method,
|
56
|
+
request_object.config,
|
57
|
+
request_object.payload
|
58
|
+
)
|
59
|
+
)
|
55
60
|
|
56
61
|
if SERVER_ERRORS.include?(response.code.to_i)
|
57
62
|
raise Diffend::Errors::RequestServerError, response.code.to_i
|
@@ -66,8 +71,8 @@ module Diffend
|
|
66
71
|
|
67
72
|
Diffend::HandleErrors::Report.call(
|
68
73
|
exception: e,
|
69
|
-
payload: payload,
|
70
|
-
config: config,
|
74
|
+
payload: request_object.payload,
|
75
|
+
config: request_object.config,
|
71
76
|
message: :request_error
|
72
77
|
)
|
73
78
|
rescue *CONNECTION_EXCEPTIONS => e
|
@@ -77,8 +82,8 @@ module Diffend
|
|
77
82
|
|
78
83
|
Diffend::HandleErrors::Report.call(
|
79
84
|
exception: e,
|
80
|
-
payload: payload,
|
81
|
-
config: config,
|
85
|
+
payload: request_object.payload,
|
86
|
+
config: request_object.config,
|
82
87
|
message: :request_error
|
83
88
|
)
|
84
89
|
rescue *TIMEOUT_EXCEPTIONS => e
|
@@ -88,8 +93,8 @@ module Diffend
|
|
88
93
|
|
89
94
|
Diffend::HandleErrors::Report.call(
|
90
95
|
exception: e,
|
91
|
-
payload: payload,
|
92
|
-
config: config,
|
96
|
+
payload: request_object.payload,
|
97
|
+
config: request_object.config,
|
93
98
|
message: :request_error
|
94
99
|
)
|
95
100
|
end
|
@@ -126,17 +131,32 @@ module Diffend
|
|
126
131
|
# Build http post request and assigns headers and payload
|
127
132
|
#
|
128
133
|
# @param uri [URI::HTTPS]
|
134
|
+
# @param request_method [Symbol]
|
129
135
|
# @param config [OpenStruct] Diffend config
|
130
136
|
# @param payload [Hash] with versions to check
|
131
137
|
#
|
132
|
-
# @return [Net::HTTP::Post]
|
133
|
-
def build_request(uri, config, payload)
|
134
|
-
|
138
|
+
# @return [Net::HTTP::Post, Net::HTTP::Put]
|
139
|
+
def build_request(uri, request_method, config, payload)
|
140
|
+
pick_request_method(request_method)
|
135
141
|
.new(uri.request_uri, HEADERS)
|
136
142
|
.tap { |request| assign_auth(request, config) }
|
137
143
|
.tap { |request| assign_payload(request, payload) }
|
138
144
|
end
|
139
145
|
|
146
|
+
# Pick request method
|
147
|
+
#
|
148
|
+
# @param request_method [Symbol]
|
149
|
+
#
|
150
|
+
# @return [Net::HTTP::Post, Net::HTTP::Put]
|
151
|
+
def pick_request_method(request_method)
|
152
|
+
case request_method
|
153
|
+
when :post
|
154
|
+
Net::HTTP::Post
|
155
|
+
when :put
|
156
|
+
Net::HTTP::Put
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
140
160
|
# Assigns basic authorization if provided in the config
|
141
161
|
#
|
142
162
|
# @param request [Net::HTTP::Post] prepared http post
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Diffend
|
4
|
+
# Track what is run in production
|
5
|
+
class Track
|
6
|
+
# Time that we want to wait between track requests
|
7
|
+
TRACK_SLEEP = 15
|
8
|
+
# Time that we want to wait before we retry
|
9
|
+
RETRY_SLEEP = 15
|
10
|
+
|
11
|
+
# Initialize tracking
|
12
|
+
def initialize
|
13
|
+
@mutex = Mutex.new
|
14
|
+
@config = fetch_config
|
15
|
+
end
|
16
|
+
|
17
|
+
# Start tracking
|
18
|
+
def start
|
19
|
+
response = exec_request
|
20
|
+
|
21
|
+
perform(response['id'])
|
22
|
+
rescue Diffend::Errors::HandledException
|
23
|
+
sleep(RETRY_SLEEP)
|
24
|
+
|
25
|
+
retry
|
26
|
+
rescue StandardError => e
|
27
|
+
Diffend::HandleErrors::Report.call(
|
28
|
+
exception: e,
|
29
|
+
config: @config,
|
30
|
+
message: :unhandled_exception,
|
31
|
+
report: true,
|
32
|
+
raise_exception: false
|
33
|
+
)
|
34
|
+
|
35
|
+
sleep(RETRY_SLEEP)
|
36
|
+
|
37
|
+
retry
|
38
|
+
end
|
39
|
+
|
40
|
+
# @param request_id [String]
|
41
|
+
def perform(request_id)
|
42
|
+
loop do
|
43
|
+
@mutex.synchronize do
|
44
|
+
track_request(request_id)
|
45
|
+
end
|
46
|
+
|
47
|
+
sleep(TRACK_SLEEP)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Perform an exec request
|
52
|
+
def exec_request
|
53
|
+
Diffend::Voting.call(
|
54
|
+
Diffend::Commands::EXEC,
|
55
|
+
@config,
|
56
|
+
Diffend::BuildBundlerDefinition.call(
|
57
|
+
Diffend::Commands::EXEC,
|
58
|
+
Bundler.default_gemfile,
|
59
|
+
Bundler.default_lockfile
|
60
|
+
)
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Perform a track request
|
65
|
+
#
|
66
|
+
# @param request_id [String]
|
67
|
+
def track_request(request_id)
|
68
|
+
Diffend::Request.call(
|
69
|
+
build_request_object(request_id)
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
# @param request_id [String]
|
74
|
+
#
|
75
|
+
# @return [Diffend::RequestObject]
|
76
|
+
def build_request_object(request_id)
|
77
|
+
Diffend::RequestObject.new(
|
78
|
+
config: @config,
|
79
|
+
url: track_url(@config.project_id, request_id),
|
80
|
+
payload: { id: request_id }.freeze,
|
81
|
+
request_method: :put
|
82
|
+
).freeze
|
83
|
+
end
|
84
|
+
|
85
|
+
# Fetch diffend config file
|
86
|
+
#
|
87
|
+
# @return [OpenStruct, nil] configuration object
|
88
|
+
#
|
89
|
+
# @raise [Errors::MissingConfigurationFile] when no config file
|
90
|
+
def fetch_config
|
91
|
+
Config::Fetcher.call(
|
92
|
+
File.expand_path('..', Bundler.bin_path)
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
# @param project_id [String] diffend project_id
|
97
|
+
# @param request_id [String]
|
98
|
+
#
|
99
|
+
# @return [String]
|
100
|
+
def track_url(project_id, request_id)
|
101
|
+
"https://my.diffend.io/api/projects/#{project_id}/bundle/#{request_id}/track"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/diffend/voting.rb
CHANGED
@@ -40,7 +40,7 @@ module Diffend
|
|
40
40
|
instance = new(definition)
|
41
41
|
|
42
42
|
case command
|
43
|
-
when Commands::INSTALL then instance.build_install
|
43
|
+
when Commands::INSTALL, Commands::EXEC then instance.build_install
|
44
44
|
when Commands::UPDATE then instance.build_update
|
45
45
|
else
|
46
46
|
raise ArgumentError, "invalid command: #{command}"
|
@@ -25,9 +25,7 @@ module Diffend
|
|
25
25
|
payload = payload(command, config.project_id, definition)
|
26
26
|
|
27
27
|
response = Diffend::Request.call(
|
28
|
-
config,
|
29
|
-
commands_url(command, config.project_id),
|
30
|
-
payload
|
28
|
+
build_request_object(command, config, payload)
|
31
29
|
)
|
32
30
|
|
33
31
|
JSON.parse(response.body)
|
@@ -41,6 +39,20 @@ module Diffend
|
|
41
39
|
)
|
42
40
|
end
|
43
41
|
|
42
|
+
# @param command [String] either install or update
|
43
|
+
# @param config [OpenStruct] diffend config
|
44
|
+
# @param payload [Hash]
|
45
|
+
#
|
46
|
+
# @return [Diffend::RequestObject]
|
47
|
+
def build_request_object(command, config, payload)
|
48
|
+
Diffend::RequestObject.new(
|
49
|
+
config: config,
|
50
|
+
url: commands_url(command, config.project_id),
|
51
|
+
payload: payload,
|
52
|
+
request_method: :post
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
44
56
|
# Build diffend, host, packages, and platform specific information
|
45
57
|
#
|
46
58
|
# @param command [String] either install or update
|
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.27
|
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-09-
|
37
|
+
date: 2020-09-16 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: bundler
|
@@ -102,7 +102,10 @@ files:
|
|
102
102
|
- lib/diffend/handle_errors/display_to_stdout.rb
|
103
103
|
- lib/diffend/handle_errors/messages.rb
|
104
104
|
- lib/diffend/handle_errors/report.rb
|
105
|
+
- lib/diffend/monitor.rb
|
105
106
|
- lib/diffend/request.rb
|
107
|
+
- lib/diffend/request_object.rb
|
108
|
+
- lib/diffend/track.rb
|
106
109
|
- lib/diffend/voting.rb
|
107
110
|
- lib/diffend/voting/versions/local.rb
|
108
111
|
- lib/diffend/voting/versions/remote.rb
|
metadata.gz.sig
CHANGED
Binary file
|