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



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/pact_broker/integrations/integration.rb', line 92

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



117
118
119
# File 'lib/pact_broker/integrations/integration.rb', line 117

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

#consumer_nameObject



121
122
123
# File 'lib/pact_broker/integrations/integration.rb', line 121

def consumer_name
  consumer.name
end

#latest_pact_or_verification_publication_dateObject



109
110
111
# File 'lib/pact_broker/integrations/integration.rb', line 109

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

#latest_verification_publication_dateObject



113
114
115
# File 'lib/pact_broker/integrations/integration.rb', line 113

def latest_verification_publication_date
  latest_verification&.execution_date
end

#pacticipant_idsObject



129
130
131
# File 'lib/pact_broker/integrations/integration.rb', line 129

def pacticipant_ids
  [consumer_id, provider_id]
end

#provider_nameObject



125
126
127
# File 'lib/pact_broker/integrations/integration.rb', line 125

def provider_name
  provider.name
end

#to_sObject



133
134
135
# File 'lib/pact_broker/integrations/integration.rb', line 133

def to_s
  "Integration: consumer #{associations[:consumer]&.name || consumer_id}/provider #{associations[:provider]&.name || provider_id}"
end

#verification_status_for_latest_pactObject

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



105
106
107
# File 'lib/pact_broker/integrations/integration.rb', line 105

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