module PactBroker::Domain

Constants

WebhookPacticipant

Public Class Methods

new(consumer, provider, consumer_version = nil, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/pact_broker/domain/index_item.rb, line 23
def initialize(consumer, provider, consumer_version = nil, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [], latest_for_branch = nil)
  @consumer = consumer
  @provider = provider
  @consumer_version = consumer_version
  @latest_pact = latest_pact
  @latest = latest
  @latest_verification = latest_verification
  @webhooks = webhooks
  @triggered_webhooks = triggered_webhooks
  @tags = tags
  @latest_verification_latest_tags = latest_verification_latest_tags
  @latest_for_branch = latest_for_branch
end

Public Instance Methods

<=>(other) click to toggle source

Add logic for ignoring case

# File lib/pact_broker/domain/index_item.rb, line 166
def <=> other
  comparisons = [
    compare_name_asc(consumer_name, other.consumer_name),
    compare_number_desc(consumer_version.order, other.consumer_version.order),
    compare_number_desc(latest_pact.revision_number, other.latest_pact.revision_number),
    compare_name_asc(provider_name, other.provider_name)
  ]

  comparisons.find{|c| c != 0 } || 0
end
==(other) click to toggle source

rubocop: enable Metrics/CyclomaticComplexity

# File lib/pact_broker/domain/index_item.rb, line 49
def == other
  eq?(other)
end
any_webhooks?() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 121
def any_webhooks?
  @webhooks.any?
end
compare_name_asc(name1, name2) click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 177
def compare_name_asc name1, name2
  name1&.downcase <=> name2&.downcase
end
compare_number_desc(number1, number2) click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 181
def compare_number_desc number1, number2
  if number1 && number2
    number2 <=> number1
  elsif number1
    1
  else
    -1
  end
end
connected?(other) click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 157
def connected? other
  include?(other.consumer) || include?(other.provider)
end
consumer_name() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 53
def consumer_name
  consumer.name
end
consumer_version_branch_heads() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 77
def consumer_version_branch_heads
  consumer_version.branch_heads
end
consumer_version_branches() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 73
def consumer_version_branches
  consumer_version.branch_heads.collect(&:branch_name)
end
consumer_version_environment_names() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 81
def consumer_version_environment_names
  (consumer_version.current_deployed_versions.collect(&:environment).collect(&:name) + consumer_version.current_supported_released_versions.collect(&:environment).collect(&:name)).uniq
end
consumer_version_number() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 65
def consumer_version_number
  @latest_pact.consumer_version_number
end
consumer_version_order() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 69
def consumer_version_order
  consumer_version.order
end
eq?(other) click to toggle source

rubocop: disable Metrics/CyclomaticComplexity

# File lib/pact_broker/domain/index_item.rb, line 39
def eq? other
  IndexItem === other && other.consumer == consumer && other.provider == provider &&
    other.latest_pact == latest_pact &&
    other.latest? == latest? &&
    other.latest_verification == latest_verification &&
    other.webhooks == webhooks &&
    other.latest_for_branch? == latest_for_branch?
end
ever_verified?() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 137
def ever_verified?
  !!latest_verification
end
include?(pacticipant) click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 161
def include? pacticipant
  pacticipant.id == consumer.id || pacticipant.id == provider.id
end
last_activity_date() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 199
def last_activity_date
  @last_activity_date ||= [latest_pact.created_at, latest_verification ? latest_verification.execution_date : nil].compact.max
end
last_webhook_execution_date() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 129
def last_webhook_execution_date
  @last_webhook_execution_date ||= @triggered_webhooks.any? ? @triggered_webhooks.sort{|a, b| a.created_at <=> b.created_at }.last.created_at : nil
end
latest?() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 61
def latest?
  @latest
end
latest_for_branch?() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 85
def latest_for_branch?
  @latest_for_branch
end
latest_verification_provider_version_number() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 149
def latest_verification_provider_version_number
  latest_verification.provider_version.number
end
latest_verification_successful?() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 141
def latest_verification_successful?
  latest_verification.success
end
pact_changed_since_last_verification?() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 145
def pact_changed_since_last_verification?
  latest_verification.pact_version_sha != latest_pact.pact_version_sha
end
pacticipants() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 153
def pacticipants
  [consumer, provider]
end
provider_name() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 57
def provider_name
  provider.name
end
provider_version() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 89
def provider_version
  @latest_verification ? @latest_verification.provider_version : nil
end
provider_version_branch_heads() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 97
def provider_version_branch_heads
  provider_version&.branch_heads || []
end
provider_version_branches() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 102
def provider_version_branches
  provider_version&.branch_heads&.collect(&:branch_name) || []
end
provider_version_environment_names() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 106
def provider_version_environment_names
  if provider_version
    (provider_deployed_environment_names + provider_released_environment_names).uniq
  else
    []
  end

end
provider_version_number() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 93
def provider_version_number
  @latest_verification ? @latest_verification.provider_version_number : nil
end
pseudo_branch_verification_status() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 133
def pseudo_branch_verification_status
  @pseudo_branch_verification_status ||= PactBroker::Verifications::PseudoBranchStatus.new(@latest_pact, @latest_verification).to_sym
end
tag_names() click to toggle source

these are the consumer tag names for which this pact publication is the latest with that tag

# File lib/pact_broker/domain/index_item.rb, line 117
def tag_names
  @tags
end
to_a() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 195
def to_a
  [consumer, provider]
end
to_s() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 191
def to_s
  "Pact between #{consumer_name} #{consumer_version_number} and #{provider_name} #{provider_version_number}"
end
webhook_status() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 125
def webhook_status
  @webhook_status ||= PactBroker::Webhooks::Status.new(@latest_pact, @webhooks, @triggered_webhooks).to_sym
end

Private Instance Methods

provider_deployed_environment_names() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 205
def provider_deployed_environment_names
  provider_version.current_deployed_versions.collect(&:environment)&.collect(&:name)
end
provider_released_environment_names() click to toggle source
# File lib/pact_broker/domain/index_item.rb, line 209
def provider_released_environment_names
  provider_version.current_supported_released_versions.collect(&:environment)&.collect(&:name)
end