pact_broker-client 1.68.0 → 1.69.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/triage.yml +15 -0
- data/CHANGELOG.md +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +11 -3
- data/lib/pact_broker/client/cli/matrix_commands.rb +34 -4
- data/lib/pact_broker/client/cli/version_selector_options_parser.rb +8 -0
- data/lib/pact_broker/client/matrix/query.rb +4 -1
- data/lib/pact_broker/client/version.rb +1 -1
- data/spec/integration/can_i_merge_spec.rb +43 -0
- data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +6 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d04543119f56e452c3c57968e73850a026d249e4db7a179b07d7fd9e08b1b39e
|
4
|
+
data.tar.gz: e29701ac23814dc00deea077e9dc318e21dcad486b5e01f28e3b422e0394310c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79f0f70224a4991f745e25b04251831f6a57872247780a9c0a4de75f3c1e04116534f42501a0c5fec982305fe235887ab21b7d915651be9275f706fba334a097
|
7
|
+
data.tar.gz: 007d7e79f2ffe068775cecb79324f811371bec604f18d657befebbe597391e70fda5bca489719dcd1fc395d673518b2dcc5a11537a94155562d353a8fc37fa11
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -444,16 +444,24 @@ Options:
|
|
444
444
|
-l, [--latest=[TAG]]
|
445
445
|
# Use the latest pacticipant version. Optionally specify a TAG
|
446
446
|
to use the latest version with the specified tag.
|
447
|
-
[--to-environment=ENVIRONMENT]
|
448
|
-
# The environment into which the pacticipant(s) are to be
|
449
|
-
deployed
|
450
447
|
[--branch=BRANCH]
|
451
448
|
# The branch of the version for which you want to check the
|
449
|
+
verification results.
|
450
|
+
[--main-branch], [--no-main-branch]
|
451
|
+
# Use the latest version of the configured main branch of the
|
452
|
+
pacticipant as the version for which you want to check the
|
452
453
|
verification results
|
454
|
+
[--to-environment=ENVIRONMENT]
|
455
|
+
# The environment into which the pacticipant(s) are to be
|
456
|
+
deployed
|
453
457
|
[--to=TAG]
|
454
458
|
# The tag that represents the branch or environment of the
|
455
459
|
integrated applications for which you want to check the
|
456
460
|
verification result status.
|
461
|
+
[--ignore=IGNORE]
|
462
|
+
# The pacticipant name to ignore. Use once for each pacticipant
|
463
|
+
being ignored. A specific version can be ignored by also
|
464
|
+
specifying a --version after the pacticipant name option.
|
457
465
|
-o, [--output=OUTPUT]
|
458
466
|
# json or table
|
459
467
|
# Default: table
|
@@ -1,20 +1,25 @@
|
|
1
|
+
require "pact_broker/client/string_refinements"
|
1
2
|
module PactBroker
|
2
3
|
module Client
|
3
4
|
module CLI
|
4
5
|
module MatrixCommands
|
6
|
+
using PactBroker::Client::StringRefinements
|
7
|
+
|
5
8
|
def self.included(thor)
|
6
9
|
thor.class_eval do
|
7
10
|
|
8
|
-
desc "can-i-deploy", ""
|
11
|
+
desc "can-i-deploy", "Checks if the specified pacticipant version is safe to be deployed."
|
9
12
|
long_desc File.read(File.join(__dir__, "can_i_deploy_long_desc.txt"))
|
10
13
|
|
11
14
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
|
12
15
|
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
|
13
16
|
method_option :ignore, required: false, desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version after the pacticipant name option. The environment variable PACT_BROKER_CAN_I_DEPLOY_IGNORE may also be used to specify a pacticipant name to ignore, with commas to separate multiple pacticipant names if necessary."
|
14
17
|
method_option :latest, required: false, aliases: "-l", banner: "[TAG]", desc: "Use the latest pacticipant version. Optionally specify a TAG to use the latest version with the specified tag."
|
18
|
+
method_option :branch, required: false, desc: "The branch of the version for which you want to check the verification results.", default: nil
|
19
|
+
method_option :main_branch, required: false, type: :boolean, desc: "Use the latest version of the configured main branch of the pacticipant as the version for which you want to check the verification results", default: false
|
15
20
|
method_option :to_environment, required: false, banner: "ENVIRONMENT", desc: "The environment into which the pacticipant(s) are to be deployed", default: nil
|
16
|
-
method_option :branch, required: false, desc: "The branch of the version for which you want to check the verification results", default: nil
|
17
21
|
method_option :to, required: false, banner: "TAG", desc: "The tag that represents the branch or environment of the integrated applications for which you want to check the verification result status.", default: nil
|
22
|
+
method_option :ignore, required: false, desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version after the pacticipant name option."
|
18
23
|
method_option :output, aliases: "-o", desc: "json or table", default: "table"
|
19
24
|
method_option :retry_while_unknown, banner: "TIMES", type: :numeric, default: 0, required: false, desc: "The number of times to retry while there is an unknown verification result (ie. the provider verification is likely still running)"
|
20
25
|
method_option :retry_interval, banner: "SECONDS", type: :numeric, default: 10, required: false, desc: "The time between retries in seconds. Use in conjuction with --retry-while-unknown"
|
@@ -40,6 +45,31 @@ module PactBroker
|
|
40
45
|
exit(can_i_deploy_exit_status) unless result.success
|
41
46
|
end
|
42
47
|
|
48
|
+
desc "can-i-merge", "Checks if the specified pacticipant version is safe to merge into the main branch."
|
49
|
+
long_desc "Checks if the specified pacticipant version is compatible with the configured main branch of each of the pacticipants with which it is integrated."
|
50
|
+
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
|
51
|
+
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
|
52
|
+
method_option :output, aliases: "-o", desc: "json or table", default: "table"
|
53
|
+
method_option :retry_while_unknown, banner: "TIMES", type: :numeric, default: 0, required: false, desc: "The number of times to retry while there is an unknown verification result (ie. the provider verification is likely still running)"
|
54
|
+
method_option :retry_interval, banner: "SECONDS", type: :numeric, default: 10, required: false, desc: "The time between retries in seconds. Use in conjuction with --retry-while-unknown"
|
55
|
+
method_option :dry_run, type: :boolean, default: false, desc: "When dry-run is enabled, always exit process with a success code. Can also be enabled by setting the environment variable PACT_BROKER_CAN_I_MERGE_DRY_RUN=true. This mode is useful when setting up your CI/CD pipeline for the first time, or in a 'break glass' situation where you need to knowingly deploy what Pact considers a breaking change. For the second scenario, it is recommended to use the environment variable and just set it for the build required to deploy that particular version, so you don't accidentally leave the dry run mode enabled."
|
56
|
+
shared_authentication_options
|
57
|
+
|
58
|
+
def can_i_merge(*ignored_but_necessary)
|
59
|
+
require "pact_broker/client/cli/version_selector_options_parser"
|
60
|
+
require "pact_broker/client/can_i_deploy"
|
61
|
+
|
62
|
+
validate_credentials
|
63
|
+
selectors = VersionSelectorOptionsParser.call(ARGV)
|
64
|
+
validate_can_i_deploy_selectors(selectors)
|
65
|
+
dry_run = options.dry_run || ENV["PACT_BROKER_CAN_I_MERGE_DRY_RUN"] == "true"
|
66
|
+
can_i_merge_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval, dry_run: dry_run, verbose: options.verbose }
|
67
|
+
result = CanIDeploy.call(selectors, { with_main_branches: true }, can_i_merge_options, pact_broker_client_options)
|
68
|
+
$stdout.puts result.message
|
69
|
+
$stdout.flush
|
70
|
+
exit(1) unless result.success
|
71
|
+
end
|
72
|
+
|
43
73
|
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("verification_required")
|
44
74
|
|
45
75
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
|
@@ -50,7 +80,7 @@ module PactBroker
|
|
50
80
|
method_option :output, aliases: "-o", desc: "json or table", default: "table"
|
51
81
|
|
52
82
|
shared_authentication_options
|
53
|
-
desc "verification-required", "Checks if there is a verification required between the given pacticipant versions"
|
83
|
+
desc "verification-required", "Checks if there is a verification required between the given pacticipant versions."
|
54
84
|
def verification_required(*ignored_but_necessary)
|
55
85
|
require "pact_broker/client/cli/version_selector_options_parser"
|
56
86
|
require "pact_broker/client/verification_required"
|
@@ -78,7 +108,7 @@ module PactBroker
|
|
78
108
|
end
|
79
109
|
end
|
80
110
|
|
81
|
-
def validate_can_i_deploy_selectors
|
111
|
+
def validate_can_i_deploy_selectors(selectors)
|
82
112
|
pacticipants_without_versions = selectors.select{ |s| s[:version].nil? && s[:latest].nil? && s[:tag].nil? && s[:branch].nil? }.collect{ |s| s[:pacticipant] }
|
83
113
|
raise ::Thor::RequiredArgumentMissingError, "The version must be specified using `--version VERSION`, `--branch BRANCH` `--latest`, `--latest TAG`, or `--all TAG` for pacticipant #{pacticipants_without_versions.join(", ")}" if pacticipants_without_versions.any?
|
84
114
|
end
|
@@ -17,6 +17,10 @@ module PactBroker
|
|
17
17
|
when "--latest", "-l"
|
18
18
|
selectors << { pacticipant: nil } if selectors.empty?
|
19
19
|
selectors.last[:latest] = true
|
20
|
+
when "--main-branch"
|
21
|
+
selectors << { pacticipant: nil } if selectors.empty?
|
22
|
+
selectors.last[:main_branch] = true
|
23
|
+
selectors.last[:latest] = true
|
20
24
|
when /^\-/
|
21
25
|
nil
|
22
26
|
else
|
@@ -35,6 +39,10 @@ module PactBroker
|
|
35
39
|
selectors << { pacticipant: nil } if selectors.empty?
|
36
40
|
selectors.last[:branch] = word
|
37
41
|
selectors.last[:latest] = true
|
42
|
+
when "--main-branch"
|
43
|
+
selectors << { pacticipant: nil } if selectors.empty?
|
44
|
+
selectors.last[:main_branch] = true
|
45
|
+
selectors.last[:latest] = true
|
38
46
|
when "--all"
|
39
47
|
selectors << { pacticipant: nil } if selectors.empty?
|
40
48
|
selectors.last[:tag] = word
|
@@ -43,6 +43,9 @@ module PactBroker
|
|
43
43
|
if matrix_options[:to_tag]
|
44
44
|
opts[:latest] = 'true'
|
45
45
|
opts[:tag] = matrix_options[:to_tag]
|
46
|
+
elsif matrix_options[:with_main_branches]
|
47
|
+
opts[:latest] = 'true'
|
48
|
+
opts[:mainBranch] = 'true'
|
46
49
|
elsif selectors.size == 1 && !matrix_options[:to_environment]
|
47
50
|
opts[:latest] = 'true'
|
48
51
|
end
|
@@ -59,11 +62,11 @@ module PactBroker
|
|
59
62
|
hash[:latest] = 'true' if selector[:latest]
|
60
63
|
hash[:tag] = selector[:tag] if selector[:tag]
|
61
64
|
hash[:branch] = selector[:branch] if selector[:branch]
|
65
|
+
hash[:mainBranch] = 'true' if selector[:main_branch]
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
66
|
-
|
67
70
|
def result_message
|
68
71
|
if json_output?
|
69
72
|
response_entity.response.raw_body
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "pact_broker/client/cli/broker"
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Client
|
5
|
+
module CLI
|
6
|
+
describe Broker do
|
7
|
+
before do
|
8
|
+
subject.options = OpenStruct.new(minimum_valid_options)
|
9
|
+
allow($stdout).to receive(:puts)
|
10
|
+
allow($stderr).to receive(:puts)
|
11
|
+
allow(Retry).to receive(:sleep)
|
12
|
+
|
13
|
+
stub_const("ARGV", %w[--pacticipant Foo --version 1])
|
14
|
+
stub_request(:get, "http://pact-broker/matrix?latest=true&latestby=cvp&mainBranch=true&q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1").
|
15
|
+
with(
|
16
|
+
headers: {
|
17
|
+
'Accept'=>'application/hal+json',
|
18
|
+
}).
|
19
|
+
to_return(status: 200, body: File.read("spec/support/matrix.json"), headers: { "Content-Type" => "application/hal+json" })
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:minimum_valid_options) do
|
23
|
+
{
|
24
|
+
broker_base_url: 'http://pact-broker',
|
25
|
+
output: 'table',
|
26
|
+
verbose: 'verbose',
|
27
|
+
retry_while_unknown: 1,
|
28
|
+
retry_interval: 2,
|
29
|
+
limit: 1000,
|
30
|
+
dry_run: false
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:invoke_can_i_merge) { subject.can_i_merge }
|
35
|
+
|
36
|
+
it "sends a matrix query" do
|
37
|
+
expect($stdout).to receive(:puts).with(/Computer says yes/)
|
38
|
+
invoke_can_i_merge
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -75,6 +75,12 @@ module PactBroker
|
|
75
75
|
],[
|
76
76
|
["--branch", "main"],
|
77
77
|
[{ pacticipant: nil, branch: "main", latest: true }]
|
78
|
+
],[
|
79
|
+
["--pacticipant", "Foo", "--main-branch", "--pacticipant", "Bar", "--version", "1"],
|
80
|
+
[{ pacticipant: "Foo", main_branch: true, latest: true }, { pacticipant: "Bar", version: "1" }]
|
81
|
+
],[
|
82
|
+
["--main-branch"],
|
83
|
+
[{ pacticipant: nil, main_branch: true, latest: true }]
|
78
84
|
]
|
79
85
|
]
|
80
86
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.69.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beth Skurrie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -217,6 +217,7 @@ files:
|
|
217
217
|
- ".github/workflows/release_gem.yml"
|
218
218
|
- ".github/workflows/smartbear-issue-label-added.yml"
|
219
219
|
- ".github/workflows/test.yml"
|
220
|
+
- ".github/workflows/triage.yml"
|
220
221
|
- ".github/workflows/trigger_pact_docs_update.yml"
|
221
222
|
- ".gitignore"
|
222
223
|
- ".rspec"
|
@@ -224,6 +225,7 @@ files:
|
|
224
225
|
- CHANGELOG.md
|
225
226
|
- Dockerfile
|
226
227
|
- Gemfile
|
228
|
+
- LICENSE.txt
|
227
229
|
- README.md
|
228
230
|
- RELEASING.md
|
229
231
|
- Rakefile
|
@@ -353,6 +355,7 @@ files:
|
|
353
355
|
- spec/fixtures/approvals/list_environments.approved.txt
|
354
356
|
- spec/fixtures/foo-bar.json
|
355
357
|
- spec/integration/can_i_deploy_spec.rb
|
358
|
+
- spec/integration/can_i_merge_spec.rb
|
356
359
|
- spec/integration/create_version_tag_spec.rb
|
357
360
|
- spec/integration/describe_environment_spec.rb
|
358
361
|
- spec/lib/pact_broker/client/base_client_spec.rb
|
@@ -449,7 +452,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
449
452
|
- !ruby/object:Gem::Version
|
450
453
|
version: '0'
|
451
454
|
requirements: []
|
452
|
-
rubygems_version: 3.4.
|
455
|
+
rubygems_version: 3.4.19
|
453
456
|
signing_key:
|
454
457
|
specification_version: 4
|
455
458
|
summary: See description
|
@@ -462,6 +465,7 @@ test_files:
|
|
462
465
|
- spec/fixtures/approvals/list_environments.approved.txt
|
463
466
|
- spec/fixtures/foo-bar.json
|
464
467
|
- spec/integration/can_i_deploy_spec.rb
|
468
|
+
- spec/integration/can_i_merge_spec.rb
|
465
469
|
- spec/integration/create_version_tag_spec.rb
|
466
470
|
- spec/integration/describe_environment_spec.rb
|
467
471
|
- spec/lib/pact_broker/client/base_client_spec.rb
|