From f15452d7d1fa720e04863a95fea84586d7d7d866 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 26 Feb 2021 15:42:51 +1100 Subject: [PATCH] refactor: rename --auto-detect-branch to --auto-detect-version-properties --- lib/pact_broker/client/cli/broker.rb | 12 ++++++------ lib/pact_broker/client/tasks/publication_task.rb | 14 +++++++------- .../client/cli/broker_publish_spec.rb | 14 +++++++------- .../client/tasks/publication_task_spec.rb | 16 ++++++++-------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/pact_broker/client/cli/broker.rb b/lib/pact_broker/client/cli/broker.rb index 1da517b9..025372d6 100644 --- a/lib/pact_broker/client/cli/broker.rb +++ b/lib/pact_broker/client/cli/broker.rb @@ -50,7 +50,7 @@ def can_i_deploy(*ignored_but_necessary) method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password" method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token" method_option :branch, aliases: "-h", desc: "Repository branch of the consumer version" - method_option :auto_detect_branch, type: :boolean, default: true, desc: "Automatically detect the repository branch from known CI environment variables or git CLI." + method_option :auto_detect_version_properties, hidden: true, type: :boolean, default: false, desc: "Automatically detect the repository branch from known CI environment variables or git CLI." 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. Default: false" method_option :build_url, desc: "The build URL that created the pact" @@ -220,7 +220,7 @@ def publish_pacts pact_files branch: branch, tags: tags, build_url: options.build_url, - version_required: (!!options.branch || !!options.build_url || explict_auto_detect_branch) + version_required: (!!options.branch || !!options.build_url || explict_auto_detect_version_properties) }.compact PactBroker::Client::PublishPacts.call( @@ -255,15 +255,15 @@ def tags def branch require 'pact_broker/client/git' - if options.branch.nil? && options.auto_detect_branch - PactBroker::Client::Git.branch(raise_error: explict_auto_detect_branch) + if options.branch.nil? && options.auto_detect_version_properties + PactBroker::Client::Git.branch(raise_error: explict_auto_detect_version_properties) else options.branch end end - def explict_auto_detect_branch - @explict_auto_detect_branch ||= ARGV.include?("--auto-detect-branch") + def explict_auto_detect_version_properties + @explict_auto_detect_version_properties ||= ARGV.include?("--auto-detect-version-properties") end def pact_broker_client_options diff --git a/lib/pact_broker/client/tasks/publication_task.rb b/lib/pact_broker/client/tasks/publication_task.rb index fdc2d25b..d5b33238 100644 --- a/lib/pact_broker/client/tasks/publication_task.rb +++ b/lib/pact_broker/client/tasks/publication_task.rb @@ -19,22 +19,22 @@ module Client class PublicationTask < ::Rake::TaskLib attr_accessor :pattern, :pact_broker_base_url, :consumer_version, :tag, :write_method, :tag_with_git_branch, :pact_broker_basic_auth, :pact_broker_token - attr_reader :auto_detect_branch, :branch, :build_url + attr_reader :auto_detect_version_properties, :branch, :build_url alias_method :tags=, :tag= alias_method :tags, :tag def initialize name = nil, &block @name = name - @auto_detect_branch = nil + @auto_detect_version_properties = nil @version_required = false @pattern = 'spec/pacts/*.json' @pact_broker_base_url = 'http://pact-broker' rake_task &block end - def auto_detect_branch= auto_detect_branch - @version_required = version_required || auto_detect_branch - @auto_detect_branch = auto_detect_branch + def auto_detect_version_properties= auto_detect_version_properties + @version_required = version_required || auto_detect_version_properties + @auto_detect_version_properties = auto_detect_version_properties end def branch= branch @@ -78,8 +78,8 @@ def all_tags end def the_branch - if branch.nil? && auto_detect_branch != false - PactBroker::Client::Git.branch(raise_error: auto_detect_branch == true) + if branch.nil? && auto_detect_version_properties != false + PactBroker::Client::Git.branch(raise_error: auto_detect_version_properties == true) else branch end diff --git a/spec/lib/pact_broker/client/cli/broker_publish_spec.rb b/spec/lib/pact_broker/client/cli/broker_publish_spec.rb index 55a876ee..5d2bd1ce 100644 --- a/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +++ b/spec/lib/pact_broker/client/cli/broker_publish_spec.rb @@ -133,12 +133,12 @@ module PactBroker::Client::CLI end end - context "with --auto-detect-branch on by default" do + context "with --auto-detect-version-properties on by default" do before do subject.options = OpenStruct.new( - minimum_valid_options.merge(auto_detect_branch: true) + minimum_valid_options.merge(auto_detect_version_properties: true) ) - allow(subject).to receive(:explict_auto_detect_branch).and_return(false) + allow(subject).to receive(:explict_auto_detect_version_properties).and_return(false) end it "determines the git branch name" do @@ -158,12 +158,12 @@ module PactBroker::Client::CLI end - context "with --auto-detect-branch specified explicitly" do + context "with --auto-detect-version-properties specified explicitly" do before do subject.options = OpenStruct.new( - minimum_valid_options.merge(auto_detect_branch: true) + minimum_valid_options.merge(auto_detect_version_properties: true) ) - allow(subject).to receive(:explict_auto_detect_branch).and_return(true) + allow(subject).to receive(:explict_auto_detect_version_properties).and_return(true) end it "determines the git branch name" do @@ -184,7 +184,7 @@ module PactBroker::Client::CLI context "with the branch specified as well" do before do subject.options = OpenStruct.new( - minimum_valid_options.merge(branch: "specified-branch", auto_detect_branch: true) + minimum_valid_options.merge(branch: "specified-branch", auto_detect_version_properties: true) ) end diff --git a/spec/lib/pact_broker/client/tasks/publication_task_spec.rb b/spec/lib/pact_broker/client/tasks/publication_task_spec.rb index 943658d0..b8110cda 100644 --- a/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +++ b/spec/lib/pact_broker/client/tasks/publication_task_spec.rb @@ -63,7 +63,7 @@ module PactBroker::Client PactBroker::Client::PublicationTask.new(:git_branch) do | task | task.consumer_version = '1.2.3' task.tag_with_git_branch = true - task.auto_detect_branch = false + task.auto_detect_version_properties = false task.tags = ['bar'] end end @@ -79,11 +79,11 @@ module PactBroker::Client end end - context "when auto_detect_branch is explicitly set to true" do + context "when auto_detect_version_properties is explicitly set to true" do before :all do PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_true) do | task | task.consumer_version = '1.2.3' - task.auto_detect_branch = true + task.auto_detect_version_properties = true end end @@ -98,11 +98,11 @@ module PactBroker::Client end end - context "when auto_detect_branch is explicitly set to true and the branch is specified" do + context "when auto_detect_version_properties is explicitly set to true and the branch is specified" do before :all do PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_true_with_branch) do | task | task.consumer_version = '1.2.3' - task.auto_detect_branch = true + task.auto_detect_version_properties = true task.branch = "main" end end @@ -118,11 +118,11 @@ module PactBroker::Client end end - context "when auto_detect_branch is explicitly set to false" do + context "when auto_detect_version_properties is explicitly set to false" do before :all do PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_false) do | task | task.consumer_version = '1.2.3' - task.auto_detect_branch = false + task.auto_detect_version_properties = false end end @@ -137,7 +137,7 @@ module PactBroker::Client end end - context "when auto_detect_branch is left as its default" do + context "when auto_detect_version_properties is left as its default" do before :all do PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_default) do | task | task.consumer_version = '1.2.3'