class PactBroker::Client::Branches::DeleteBranch

Constants

NOT_SUPPORTED_MESSAGE_PACTFLOW
NOT_SUPPORTED_MESSAGE_PACT_BROKER

Attributes

branch_name[R]
deleted_resource[R]
error_when_not_found[R]
pacticipant_name[R]

Public Class Methods

new(params, options, pact_broker_client_options) click to toggle source
Calls superclass method PactBroker::Client::BaseCommand::new
# File lib/pact_broker/client/branches/delete_branch.rb, line 11
def initialize(params, options, pact_broker_client_options)
        super
  @pacticipant_name = params.fetch(:pacticipant)
        @branch_name = params.fetch(:branch)
  @error_when_not_found = params.fetch(:error_when_not_found)
end

Public Instance Methods

do_call() click to toggle source
# File lib/pact_broker/client/branches/delete_branch.rb, line 18
                        def do_call
                                check_if_command_supported
  @deleted_resource = branch_link.delete
  PactBroker::Client::CommandResult.new(success?, result_message)
end

Private Instance Methods

check_if_command_supported() click to toggle source
# File lib/pact_broker/client/branches/delete_branch.rb, line 32
def check_if_command_supported
  unless index_resource.can?("pb:pacticipant-branch")
        raise PactBroker::Client::Error.new(is_pactflow? ? NOT_SUPPORTED_MESSAGE_PACTFLOW : NOT_SUPPORTED_MESSAGE_PACT_BROKER)
  end
end
result_message() click to toggle source
# File lib/pact_broker/client/branches/delete_branch.rb, line 48
def result_message
  if deleted_resource.success?
                                 green("Successfully deleted branch #{branch_name} of pacticipant #{pacticipant_name}")
  elsif deleted_resource.response.status == 404
    if error_when_not_found
      red("Could not delete branch #{branch_name} of pacticipant #{pacticipant_name} as it was not found")
    else
      green("Branch #{branch_name} of pacticipant #{pacticipant_name} not found")
    end
  else
    red(deleted_resource.response.raw_body)
  end
end
success?() click to toggle source
# File lib/pact_broker/client/branches/delete_branch.rb, line 38
def success?
  if deleted_resource.success?
    true
  elsif deleted_resource.response.status == 404 && !error_when_not_found
    true
  else
    false
  end
end