Skip to content

Commit

Permalink
feat: support the --branch option in the version selectors for can-i-…
Browse files Browse the repository at this point in the history
…deploy
  • Loading branch information
bethesque committed Nov 5, 2021
1 parent 6625b74 commit dba8ec4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/pact_broker/client/cli/matrix_commands.rb
Expand Up @@ -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)"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/client/cli/version_selector_options_parser.rb
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions 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"
Expand Up @@ -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 }]
]
]

Expand Down

0 comments on commit dba8ec4

Please sign in to comment.