diff --git a/lib/pact_broker/client/cli/matrix_commands.rb b/lib/pact_broker/client/cli/matrix_commands.rb index d58c7516..b776f42d 100644 --- a/lib/pact_broker/client/cli/matrix_commands.rb +++ b/lib/pact_broker/client/cli/matrix_commands.rb @@ -13,6 +13,7 @@ def self.included(thor) 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." 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." method_option :to_environment, required: false, banner: "ENVIRONMENT", desc: "The environment into which the pacticipant(s) are to be deployed", default: nil + method_option :branch, required: false, desc: "The branch of the version for which you want to check the verification results", default: nil 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 method_option :output, aliases: "-o", desc: "json or table", default: "table" 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)" @@ -77,8 +78,8 @@ def can_i_deploy_exit_status end def validate_can_i_deploy_selectors selectors - pacticipants_without_versions = selectors.select{ |s| s[:version].nil? && s[:latest].nil? && s[:tag].nil? }.collect{ |s| s[:pacticipant] } - raise ::Thor::RequiredArgumentMissingError, "The version must be specified using `--version VERSION`, `--latest`, `--latest TAG`, or `--all TAG` for pacticipant #{pacticipants_without_versions.join(", ")}" if pacticipants_without_versions.any? + pacticipants_without_versions = selectors.select{ |s| s[:version].nil? && s[:latest].nil? && s[:tag].nil? && s[:branch].nil? }.collect{ |s| s[:pacticipant] } + 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? end end end diff --git a/lib/pact_broker/client/cli/version_selector_options_parser.rb b/lib/pact_broker/client/cli/version_selector_options_parser.rb index 1832ee08..906c0594 100644 --- a/lib/pact_broker/client/cli/version_selector_options_parser.rb +++ b/lib/pact_broker/client/cli/version_selector_options_parser.rb @@ -31,6 +31,10 @@ def self.call words when "--latest", "-l" selectors << { pacticipant: nil } if selectors.empty? selectors.last[:tag] = word + when "--branch" + selectors << { pacticipant: nil } if selectors.empty? + selectors.last[:branch] = word + selectors.last[:latest] = true when "--all" selectors << { pacticipant: nil } if selectors.empty? selectors.last[:tag] = word diff --git a/script/can-i-deploy.sh b/script/can-i-deploy.sh new file mode 100755 index 00000000..4c169b2c --- /dev/null +++ b/script/can-i-deploy.sh @@ -0,0 +1,5 @@ +bundle exec bin/pact-broker publish spec/pacts/pact_broker_client-pact_broker.json \ + --consumer-app-version 1.2.26 \ + --branch main + +bundle exec bin/pact-broker can-i-deploy --pacticipant "Pact Broker Client" --branch "main" diff --git a/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb b/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb index 1059ecfd..73335475 100644 --- a/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +++ b/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb @@ -69,6 +69,12 @@ module CLI ],[ ["--version", "2"], [{ pacticipant: nil, version: "2" }] + ],[ + ["--pacticipant", "Foo", "--branch", "main"], + [{ pacticipant: "Foo", branch: "main", latest: true }] + ],[ + ["--branch", "main"], + [{ pacticipant: nil, branch: "main", latest: true }] ] ]