class PactBroker::Client::Deployments::RecordRelease

Attributes

deployed_version_resource[R]
environment_name[R]
pacticipant_name[R]
version_number[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/deployments/record_release.rb, line 7
def initialize(params, options, pact_broker_client_options)
  super
  @pacticipant_name = params.fetch(:pacticipant_name)
  @version_number = params.fetch(:version_number)
  @environment_name = params.fetch(:environment_name)
end

Private Instance Methods

action() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 24
def action
  "release"
end
action_relation_name() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 28
def action_relation_name
  "pb:record-release"
end
check_if_command_supported() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 99
def check_if_command_supported
  unless index_resource.can?("pb:environments")
    raise PactBroker::Client::Error.new(not_supported_message)
  end
end
do_call() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 19
def do_call
  record_action
  PactBroker::Client::CommandResult.new(true, result_message)
end
environment_exists?() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 40
def environment_exists?
  index_resource
    ._link!("pb:environments")
    .get!
    ._links("pb:environments")
    .find(environment_name)
end
environment_relation_not_found_error_message() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 63
def environment_relation_not_found_error_message
  if environment_exists?
    "Environment '#{environment_name}' is not an available option for recording a deployment of #{pacticipant_name}."
  else
    if is_pactflow?
      "Environment '#{environment_name}' is not an available option for recording a deployment of #{pacticipant_name}. The environment may not exist, or you may not have the required permissions or team associations to view it."
    else
      "No environment found with name '#{environment_name}'."
    end
  end
end
get_pacticipant_version() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 75
def get_pacticipant_version
  index_resource
    ._link!("pb:pacticipant-version")
    .expand(pacticipant: pacticipant_name, version: version_number)
    .get
    .assert_success!(404 => "#{pacticipant_name} version #{version_number} not found")
end
get_record_action_relation() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 59
def get_record_action_relation
  record_action_links.find(environment_name) or record_action_links.find!(environment_name, environment_relation_not_found_error_message)
end
not_supported_message() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 32
def not_supported_message
  if is_pactflow?
    "This version of PactFlow does not support recording #{action}s, or you do not have the required permission to read environments. Please upgrade to the latest version if using PactFlow On-Premises, and ensure the user has the environment read permission."
  else
    "This version of the Pact Broker does not support recording #{action}s. Please upgrade to version 2.80.0 or later."
  end
end
record_action() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 48
def record_action
  @deployed_version_resource =
    get_record_action_relation
    .post(record_action_request_body)
    .assert_success!
end
record_action_request_body() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 83
def record_action_request_body
  {}
end
result_message() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 87
def result_message
  if json_output?
    deployed_version_resource.response.raw_body
  else
    green("#{result_text_message} in #{pact_broker_name}.")
  end
end
result_text_message() click to toggle source
# File lib/pact_broker/client/deployments/record_release.rb, line 95
def result_text_message
  "Recorded #{action} of #{pacticipant_name} version #{version_number} to #{environment_name} environment"
end