Class: PactBroker::Integrations::Integration

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

Overview

The columns are explicitly specified for the Integration object so that the consumer_name and provider_name columns aren’t included in the model. Those columns exist in the integrations table because the integrations table used to be an integrations view based on the pact_publications table, and those columns existed in the view. When the view was migrated to be a table (in db/migrations/20211102_create_table_temp_integrations.rb and the following migrations) the columns had to be maintained for backwards compatiblity. They are not used by the current code, however.

Constant Summary collapse

INTEGRATION_COLUMNS =
Sequel::Model.db.schema(:integrations).collect(&:first) - [:consumer_name, :provider_name]
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



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/pact_broker/integrations/integration.rb', line 102

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



127
128
129
# File 'lib/pact_broker/integrations/integration.rb', line 127

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

#consumer_nameObject



131
132
133
# File 'lib/pact_broker/integrations/integration.rb', line 131

def consumer_name
  consumer.name
end

#latest_pact_or_verification_publication_dateObject



119
120
121
# File 'lib/pact_broker/integrations/integration.rb', line 119

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

#latest_verification_publication_dateObject



123
124
125
# File 'lib/pact_broker/integrations/integration.rb', line 123

def latest_verification_publication_date
  latest_verification&.execution_date
end

#pacticipant_idsObject



139
140
141
# File 'lib/pact_broker/integrations/integration.rb', line 139

def pacticipant_ids
  [consumer_id, provider_id]
end

#provider_nameObject



135
136
137
# File 'lib/pact_broker/integrations/integration.rb', line 135

def provider_name
  provider.name
end

#to_sObject



143
144
145
# File 'lib/pact_broker/integrations/integration.rb', line 143

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



115
116
117
# File 'lib/pact_broker/integrations/integration.rb', line 115

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