Skip to content

Commit

Permalink
chore: simplify? auto detect consumer_version logic
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Sep 14, 2023
1 parent cf660f5 commit bcce5a8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ Options:
-h, [--branch=BRANCH]
# Repository branch of the consumer version
-r, [--auto-detect-version-properties], [--no-auto-detect-version-properties]
# Automatically detect the repository branch from known CI
environment variables or git CLI. Supports Buildkite, Circle
CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor,
GitLab, CodeShip, Bitbucket and Azure DevOps.
# Automatically detect the repository commit and branch from
known CI environment variables or git CLI. Supports Buildkite,
Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson,
AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps.
-t, [--tag=TAG]
# Tag name for consumer version. Can be specified multiple
times.
Expand Down
6 changes: 2 additions & 4 deletions lib/pact_broker/client/cli/pact_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ module PactCommands
def self.included(thor)
thor.class_eval do
desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
method_option :consumer_app_version, aliases: "-a", desc: "The consumer application version", default: ''
method_option :consumer_app_version, aliases: "-a", desc: "The consumer application version"
method_option :branch, aliases: "-h", desc: "Repository branch of the consumer version"
method_option :auto_detect_version_properties, aliases: "-r", type: :boolean, default: false, desc: "Automatically detect the repository branch from known CI environment variables or git CLI. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps."
method_option :auto_detect_version_properties, aliases: "-r", type: :boolean, default: false, desc: "Automatically detect the repository commit and branch from known CI environment variables or git CLI. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps."
method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps. Default: false"
method_option :build_url, desc: "The build URL that created the pact"
Expand Down Expand Up @@ -122,8 +122,6 @@ def consumer_app_version
require 'pact_broker/client/git'
if options.consumer_app_version.blank? && options.auto_detect_version_properties
PactBroker::Client::Git.commit(raise_error: explict_auto_detect_version_properties)
elsif (options.consumer_app_version.nil? || options.consumer_app_version == '' || options.consumer_app_version == 'consumer_app_version') && !options.auto_detect_version_properties
raise Thor::Error.new("ERROR: --consumer-app-version was not provided a value and --auto-detect-version-properties not set")
else
options.consumer_app_version
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/client/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def self.execute_git_commit_command(raise_error)
raise PactBroker::Client::Error,
"Could not determine current git commit using command `#{COMMIT_COMMAND}`. #{e.class} #{e.message}"
else
return nil
return []
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/client/tasks/publication_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def branch= branch
end

def consumer_version=(consumer_version)
@version_required = version_required || !!consumer_version
@version_required = !!consumer_version
@consumer_version = consumer_version
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/pact_broker/client/cli/broker_publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module PactBroker::Client::CLI
context "with --auto-detect-version-properties on by default" do
before do
subject.options = OpenStruct.new(
minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: '')
minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: nil)
)
allow(subject).to receive(:explict_auto_detect_version_properties).and_return(false)
end
Expand Down Expand Up @@ -203,7 +203,7 @@ module PactBroker::Client::CLI
context "with --auto-detect-version-properties specified explicitly" do
before do
subject.options = OpenStruct.new(
minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: '')
minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: nil)
)
allow(subject).to receive(:explict_auto_detect_version_properties).and_return(true)
end
Expand Down

0 comments on commit bcce5a8

Please sign in to comment.