Skip to content

Commit

Permalink
refactor: rename --auto-detect-branch to --auto-detect-version-proper…
Browse files Browse the repository at this point in the history
…ties
  • Loading branch information
bethesque committed Feb 26, 2021
1 parent 05ae44c commit f15452d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
12 changes: 6 additions & 6 deletions lib/pact_broker/client/cli/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions lib/pact_broker/client/tasks/publication_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions spec/lib/pact_broker/client/cli/broker_publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
16 changes: 8 additions & 8 deletions spec/lib/pact_broker/client/tasks/publication_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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'
Expand Down

0 comments on commit f15452d

Please sign in to comment.