Class: PactBroker::Integrations::Integration

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/integrations/integration.rb

Constant Summary collapse

LATEST_PACT_EAGER_LOADER =

When viewing the index, every latest_pact in the database will match at least one of the rows, so it makes sense to load the entire table and match each pact to the appropriate row. Update: now we have pagination, we should probably filter the pacts by consumer/provider id.

proc do |eo_opts|
  eo_opts[:rows].each do |integration|
    integration.associations[:latest_pact] = nil
  end


  # Would prefer to be able to eager load only the fields specified in the original Integrations
  # query, but we don't seem to have that information in this context.
  # Need the latest verification for the verification status in the index response.
  latest_pact_publications_query = PactBroker::Pacts::PactPublication
                                    .eager_for_domain_with_content
                                    .eager(pact_version: :latest_verification)
                                    .overall_latest

  latest_pact_publications_query.all.each do | pact |
    eo_opts[:id_map][[pact.consumer_id, pact.provider_id]]&.each do | integration |
      integration.associations[:latest_pact] = pact
    end
  end
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.compare_by_last_action_date(a, b) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/pact_broker/integrations/integration.rb', line 70

def self.compare_by_last_action_date a, b
  if b.latest_pact_or_verification_publication_date && a.latest_pact_or_verification_publication_date
    b.latest_pact_or_verification_publication_date <=> a.latest_pact_or_verification_publication_date
  elsif b.latest_pact_or_verification_publication_date
    1
  elsif a.latest_pact_or_verification_publication_date
    -1
  else
    a <=> b
  end
end

Instance Method Details

#<=>(other) ⇒ Object



95
96
97
# File 'lib/pact_broker/integrations/integration.rb', line 95

def <=>(other)
  [consumer_name.downcase, provider_name.downcase] <=> [other.consumer_name.downcase, other.provider_name.downcase]
end

#consumer_nameObject



99
100
101
# File 'lib/pact_broker/integrations/integration.rb', line 99

def consumer_name
  consumer.name
end

#latest_pact_or_verification_publication_dateObject



87
88
89
# File 'lib/pact_broker/integrations/integration.rb', line 87

def latest_pact_or_verification_publication_date
  [latest_pact&.created_at, latest_verification_publication_date].compact.max
end

#latest_verification_publication_dateObject



91
92
93
# File 'lib/pact_broker/integrations/integration.rb', line 91

def latest_verification_publication_date
  latest_verification&.execution_date
end

#provider_nameObject



103
104
105
# File 'lib/pact_broker/integrations/integration.rb', line 103

def provider_name
  provider.name
end

#verification_status_for_latest_pactObject

TODO make this the verification status for the latest from main branch



83
84
85
# File 'lib/pact_broker/integrations/integration.rb', line 83

def verification_status_for_latest_pact
  @verification_status_for_latest_pact ||= PactBroker::Verifications::PseudoBranchStatus.new(latest_pact, latest_pact&.latest_verification)
end