class PactBroker::Client::Versions::Create

Public Instance Methods

do_call() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 9
def do_call
  if branch_name
    if branch_versions_supported?
      create_branch_version
    else
      raise PactBroker::Client::Error.new("This version of #{pact_broker_name} does not support branch versions,or you do not have the required permissions to create one. Please ensure you have upgraded to version 2.82.0 or later for branch support.")
    end
  end

  if tags
    create_version_tags
  end

  if !branch_name && !tags.any?
    create_version
  end

  PactBroker::Client::CommandResult.new(true, result_message)
end

Private Instance Methods

branch_name() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 39
def branch_name
  params[:branch_name]
end
branch_versions_supported?() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 47
def branch_versions_supported?
  index_resource._link("pb:pacticipant-branch-version")
end
create_branch_version() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 51
def create_branch_version
  branch_params = {
    "pacticipant" => pacticipant_name,
    "version" => version_number,
    "branch" => branch_name
  }
  branch_version_entity = index_resource
                        ._link("pb:pacticipant-branch-version")
                        .expand(branch_params)
                        .put!
end
create_version() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 77
def create_version
  @version_resource ||= expanded_version_relation.put!
end
create_version_tags() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 63
def create_version_tags
  tags.each do | tag |
    tag_params = {
      "pacticipant" => pacticipant_name,
      "version" => version_number,
      "tag" => tag
    }
    index_resource
      ._link("pb:pacticipant-version-tag")
      .expand(tag_params)
      .put!
  end
end
expanded_version_relation() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 81
def expanded_version_relation
  version_params = {
    "pacticipant" => pacticipant_name,
    "version" => version_number
  }
  index_resource
    ._link("pb:pacticipant-version")
    .expand(version_params)
end
pacticipant_name() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 31
def pacticipant_name
  params.fetch(:pacticipant_name)
end
result_message() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 91
def result_message
  if json_output?
    (@version_resource || expanded_version_relation.get).response.raw_body
  else
    message = "Created/updated pacticipant version #{version_number}"
    if branch_name && tags.any?
      message = message + " with branch #{branch_name} and tag(s) #{tags.join(", ")}"
    elsif branch_name
      message = message + " with branch #{branch_name}"
    elsif tags.any?
      message = message + " with tag(s) #{tags.join(", ")}"
    end

    message = message + " in #{pact_broker_name}"
    green(message)
  end
end
tags() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 43
def tags
  params[:tags] || []
end
version_number() click to toggle source
# File lib/pact_broker/client/versions/create.rb, line 35
def version_number
  params.fetch(:version_number)
end