pact_broker 2.96.0 → 2.97.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -0
- data/docs/CONFIGURATION.md +98 -66
- data/lib/db.rb +1 -7
- data/lib/pact_broker/api/middleware/http_debug_logs.rb +36 -0
- data/lib/pact_broker/app.rb +1 -7
- data/lib/pact_broker/config/runtime_configuration.rb +20 -3
- data/lib/pact_broker/config/runtime_configuration_coercion_methods.rb +11 -0
- data/lib/pact_broker/config/runtime_configuration_database_methods.rb +1 -1
- data/lib/pact_broker/config/runtime_configuration_logging_methods.rb +7 -2
- data/lib/pact_broker/configuration.rb +2 -0
- data/lib/pact_broker/db/models.rb +2 -2
- data/lib/pact_broker/index/service.rb +1 -2
- data/lib/pact_broker/integrations/integration.rb +21 -6
- data/lib/pact_broker/integrations/service.rb +1 -1
- data/lib/pact_broker/matrix/repository.rb +2 -3
- data/lib/pact_broker/matrix/service.rb +0 -1
- data/lib/pact_broker/metrics/service.rb +2 -2
- data/lib/pact_broker/pacts/pact_publication.rb +9 -6
- data/lib/pact_broker/pacts/pact_version.rb +24 -28
- data/lib/pact_broker/pacts/pact_version_association_loaders.rb +36 -0
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +9 -13
- data/lib/pact_broker/pacts/repository.rb +29 -27
- data/lib/pact_broker/test/http_test_data_builder.rb +8 -1
- data/lib/pact_broker/test/test_data_builder.rb +2 -1
- data/lib/pact_broker/ui/controllers/matrix.rb +14 -11
- data/lib/pact_broker/version.rb +1 -1
- data/pact_broker.gemspec +1 -1
- metadata +9 -16
- data/lib/pact_broker/matrix/aggregated_row.rb +0 -79
- data/lib/pact_broker/matrix/head_row.rb +0 -80
- data/lib/pact_broker/matrix/row.rb +0 -287
@@ -7,7 +7,6 @@ require "pact_broker/pacts/pact_version"
|
|
7
7
|
require "pact/shared/json_differ"
|
8
8
|
require "pact_broker/domain"
|
9
9
|
require "pact_broker/pacts/parse"
|
10
|
-
require "pact_broker/matrix/head_row"
|
11
10
|
require "pact_broker/pacts/latest_pact_publication_id_for_consumer_version"
|
12
11
|
require "pact_broker/pacts/verifiable_pact"
|
13
12
|
require "pact_broker/repositories/helpers"
|
@@ -117,8 +116,8 @@ module PactBroker
|
|
117
116
|
|
118
117
|
def find_all_pact_versions_between consumer_name, options
|
119
118
|
find_all_database_versions_between(consumer_name, options)
|
120
|
-
.eager(:tags)
|
121
119
|
.reverse_order(:consumer_version_order)
|
120
|
+
.all
|
122
121
|
.collect(&:to_domain)
|
123
122
|
end
|
124
123
|
|
@@ -143,7 +142,7 @@ module PactBroker
|
|
143
142
|
def find_latest_pacts_for_provider provider_name, tag = nil
|
144
143
|
query = scope_for(PactPublication)
|
145
144
|
.for_provider_name(provider_name)
|
146
|
-
.
|
145
|
+
.eager_for_domain_with_content
|
147
146
|
|
148
147
|
if tag
|
149
148
|
query = query.latest_for_consumer_tag(tag)
|
@@ -151,7 +150,7 @@ module PactBroker
|
|
151
150
|
query = query.overall_latest
|
152
151
|
end
|
153
152
|
|
154
|
-
query.sort_by{ | p| p.consumer_name.downcase }.collect(&:to_head_pact)
|
153
|
+
query.all.sort_by{ | p| p.consumer_name.downcase }.collect(&:to_head_pact)
|
155
154
|
end
|
156
155
|
|
157
156
|
def find_for_verification(provider_name, consumer_version_selectors)
|
@@ -165,41 +164,45 @@ module PactBroker
|
|
165
164
|
def find_pact_versions_for_provider provider_name, tag = nil
|
166
165
|
query = scope_for(PactPublication)
|
167
166
|
.select_all_qualified
|
167
|
+
.eager_for_domain_with_content
|
168
168
|
.for_provider_name(provider_name)
|
169
|
-
.eager(:consumer)
|
170
|
-
.eager(:provider)
|
171
169
|
query = query.for_consumer_version_tag(tag) if tag
|
172
|
-
query.collect(&:to_domain).sort
|
170
|
+
query.all.collect(&:to_domain).sort
|
173
171
|
end
|
174
172
|
|
175
173
|
# Returns latest pact version for the consumer_version_number
|
176
174
|
def find_by_consumer_version consumer_name, consumer_version_number
|
177
175
|
scope_for(PactPublication)
|
176
|
+
.eager_for_domain_with_content
|
178
177
|
.for_consumer_name_and_maybe_version_number(consumer_name, consumer_version_number)
|
179
178
|
.remove_overridden_revisions_from_complete_query
|
179
|
+
.all
|
180
180
|
.collect(&:to_domain_with_content)
|
181
181
|
end
|
182
182
|
|
183
183
|
def find_by_version_and_provider version_id, provider_id
|
184
184
|
scope_for(PactPublication)
|
185
|
-
.
|
185
|
+
.eager_for_domain_with_content
|
186
186
|
.where(consumer_version_id: version_id, provider_id: provider_id)
|
187
187
|
.remove_overridden_revisions_from_complete_query
|
188
188
|
.limit(1)
|
189
|
+
.all
|
189
190
|
.collect(&:to_domain_with_content)[0]
|
190
191
|
end
|
191
192
|
|
192
193
|
def find_latest_pacts
|
193
194
|
scope_for(PactPublication)
|
195
|
+
.eager_for_domain_with_content
|
194
196
|
.overall_latest
|
195
|
-
.eager(:consumer)
|
196
197
|
.eager(:provider)
|
198
|
+
.all
|
197
199
|
.collect(&:to_domain)
|
198
200
|
.sort
|
199
201
|
end
|
200
202
|
|
201
203
|
def find_latest_pact(consumer_name, provider_name, tag = nil)
|
202
204
|
query = scope_for(PactPublication)
|
205
|
+
.eager_for_domain_with_content
|
203
206
|
.select_all_qualified
|
204
207
|
.for_consumer_name(consumer_name)
|
205
208
|
.for_provider_name(provider_name)
|
@@ -214,7 +217,7 @@ module PactBroker
|
|
214
217
|
|
215
218
|
# Allows optional consumer_name and provider_name
|
216
219
|
def search_for_latest_pact(consumer_name, provider_name, tag = nil)
|
217
|
-
query = scope_for(PactPublication).select_all_qualified
|
220
|
+
query = scope_for(PactPublication).select_all_qualified.eager_for_domain_with_content
|
218
221
|
query = query.for_consumer_name(consumer_name) if consumer_name
|
219
222
|
query = query.for_provider_name(provider_name) if provider_name
|
220
223
|
|
@@ -233,6 +236,7 @@ module PactBroker
|
|
233
236
|
# rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
234
237
|
def find_pact consumer_name, consumer_version_number, provider_name, pact_version_sha = nil
|
235
238
|
pact_publication_by_consumer_version = scope_for(PactPublication)
|
239
|
+
.eager_for_domain_with_content
|
236
240
|
.select_all_qualified
|
237
241
|
.for_consumer_name_and_maybe_version_number(consumer_name, consumer_version_number)
|
238
242
|
.for_provider_name(provider_name)
|
@@ -240,6 +244,7 @@ module PactBroker
|
|
240
244
|
.limit(1)
|
241
245
|
|
242
246
|
latest_pact_publication_by_sha = scope_for(PactPublication)
|
247
|
+
.eager_for_domain_with_content
|
243
248
|
.select_all_qualified
|
244
249
|
.for_consumer_name(consumer_name)
|
245
250
|
.for_provider_name(provider_name)
|
@@ -249,46 +254,39 @@ module PactBroker
|
|
249
254
|
|
250
255
|
if consumer_version_number && !pact_version_sha
|
251
256
|
pact_publication_by_consumer_version
|
252
|
-
.
|
253
|
-
.all_allowing_lazy_load
|
254
|
-
.collect(&:to_domain_with_content).first
|
257
|
+
.first&.to_domain_with_content
|
255
258
|
elsif pact_version_sha && !consumer_version_number
|
256
259
|
latest_pact_publication_by_sha
|
257
|
-
.
|
258
|
-
.collect(&:to_domain_with_content).first
|
260
|
+
.first&.to_domain_with_content
|
259
261
|
elsif consumer_version_number && pact_version_sha
|
260
|
-
pact_publication = pact_publication_by_consumer_version.
|
262
|
+
pact_publication = pact_publication_by_consumer_version.first
|
261
263
|
if pact_publication && pact_publication.pact_version.sha == pact_version_sha
|
262
|
-
pact_publication.tags
|
263
264
|
pact_publication.to_domain_with_content
|
264
265
|
else
|
265
|
-
latest_pact_publication_by_sha
|
266
|
-
.eager(:tags)
|
267
|
-
.all_allowing_lazy_load
|
268
|
-
.collect(&:to_domain_with_content).first
|
266
|
+
latest_pact_publication_by_sha.first&.to_domain_with_content
|
269
267
|
end
|
270
268
|
else
|
271
269
|
pact_publication_by_consumer_version
|
272
|
-
.eager(:tags)
|
273
270
|
.reverse_order(:consumer_version_order, :revision_number)
|
274
|
-
.
|
275
|
-
.collect(&:to_domain_with_content).first
|
271
|
+
.first&.to_domain_with_content
|
276
272
|
end
|
277
273
|
end
|
278
274
|
# rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
279
275
|
|
280
276
|
def find_all_revisions consumer_name, consumer_version_number, provider_name
|
281
277
|
scope_for(PactPublication)
|
278
|
+
.eager_for_domain_with_content
|
282
279
|
.for_provider_name(provider_name)
|
283
280
|
.for_consumer_name_and_maybe_version_number(consumer_name, consumer_version_number)
|
284
281
|
.order_by_consumer_version_order
|
282
|
+
.all
|
285
283
|
.collect(&:to_domain_with_content)
|
286
284
|
end
|
287
285
|
|
288
286
|
def find_previous_pact pact, tag = nil
|
289
287
|
query = scope_for(PactPublication)
|
288
|
+
.eager_for_domain_with_content
|
290
289
|
.remove_overridden_revisions
|
291
|
-
.eager(:tags)
|
292
290
|
.for_consumer_name(pact.consumer.name)
|
293
291
|
.for_provider_name(pact.provider.name)
|
294
292
|
|
@@ -301,17 +299,19 @@ module PactBroker
|
|
301
299
|
query
|
302
300
|
.consumer_version_order_before(pact.consumer_version.order)
|
303
301
|
.latest_by_consumer_version_order
|
302
|
+
.all
|
304
303
|
.collect(&:to_domain_with_content)[0]
|
305
304
|
end
|
306
305
|
|
307
306
|
def find_next_pact pact
|
308
307
|
scope_for(PactPublication)
|
309
|
-
.
|
308
|
+
.eager_for_domain_with_content
|
310
309
|
.for_consumer_name(pact.consumer.name)
|
311
310
|
.for_provider_name(pact.provider.name)
|
312
311
|
.remove_overridden_revisions
|
313
312
|
.consumer_version_order_after(pact.consumer_version.order)
|
314
313
|
.earliest
|
314
|
+
.all_allowing_lazy_load
|
315
315
|
.collect(&:to_domain_with_content)[0]
|
316
316
|
end
|
317
317
|
|
@@ -343,12 +343,13 @@ module PactBroker
|
|
343
343
|
def find_previous_distinct_pact_by_sha pact
|
344
344
|
pact_version = PactVersion.for_pact_domain(pact)
|
345
345
|
scope_for(PactPublication)
|
346
|
-
.
|
346
|
+
.eager_for_domain_with_content
|
347
347
|
.for_consumer_name(pact.consumer.name)
|
348
348
|
.for_provider_name(pact.provider.name)
|
349
349
|
.consumer_version_order_before(pact.consumer_version.order)
|
350
350
|
.exclude(pact_version_id: pact_version.id)
|
351
351
|
.latest_by_consumer_version_order
|
352
|
+
.all_allowing_lazy_load
|
352
353
|
.collect(&:to_domain_with_content)[0]
|
353
354
|
end
|
354
355
|
|
@@ -377,6 +378,7 @@ module PactBroker
|
|
377
378
|
provider_name = options.fetch(:and)
|
378
379
|
|
379
380
|
query = scope_for(PactPublication)
|
381
|
+
.eager_for_domain_with_content
|
380
382
|
.for_consumer_name(consumer_name)
|
381
383
|
.for_provider_name(provider_name)
|
382
384
|
.remove_overridden_revisions
|
@@ -74,8 +74,15 @@ module PactBroker
|
|
74
74
|
def record_deployment(pacticipant:, version:, environment_name:)
|
75
75
|
puts "Recording deployment of #{pacticipant} version #{version} to #{environment_name}"
|
76
76
|
version_body = client.get("/pacticipants/#{encode(pacticipant)}/versions/#{encode(version)}").tap { |response| check_for_error(response) }.body
|
77
|
+
|
77
78
|
environment_relation = version_body["_links"]["pb:record-deployment"].find { |relation| relation["name"] == environment_name }
|
78
|
-
|
79
|
+
if environment_relation.nil?
|
80
|
+
available_environments = version_body["_links"]["pb:record-deployment"].collect{ | relation | relation["name"]}.join
|
81
|
+
puts "Environment with name #{environment_name} not found. Available environments: #{available_environments}"
|
82
|
+
else
|
83
|
+
client.post(environment_relation["href"], { replacedPreviousDeployedVersion: true }).tap { |response| check_for_error(response) }
|
84
|
+
end
|
85
|
+
|
79
86
|
separate
|
80
87
|
self
|
81
88
|
end
|
@@ -25,7 +25,6 @@ require "pact_broker/verifications/service"
|
|
25
25
|
require "pact_broker/tags/repository"
|
26
26
|
require "pact_broker/webhooks/repository"
|
27
27
|
require "pact_broker/certificates/certificate"
|
28
|
-
require "pact_broker/matrix/row"
|
29
28
|
require "pact_broker/deployments/environment_service"
|
30
29
|
require "pact_broker/deployments/deployed_version_service"
|
31
30
|
require "pact_broker/deployments/released_version_service"
|
@@ -260,6 +259,8 @@ module PactBroker
|
|
260
259
|
set_created_at_if_set(params[:created_at], :pact_versions, sha: @pact.pact_version_sha) if pact_versions_count_after > pact_versions_count_before
|
261
260
|
set_created_at_if_set(params[:created_at], :latest_pact_publication_ids_for_consumer_versions, consumer_version_id: @consumer_version.id)
|
262
261
|
@pact = PactBroker::Pacts::PactPublication.find(id: @pact.id).to_domain
|
262
|
+
consumer_version.reload
|
263
|
+
consumer_version.pact_publications.each{ | pp | pp.allow_lazy_load if pp.respond_to?(:allow_lazy_load) }
|
263
264
|
self
|
264
265
|
end
|
265
266
|
|
@@ -46,19 +46,22 @@ module PactBroker
|
|
46
46
|
end
|
47
47
|
|
48
48
|
get "/provider/:provider_name/consumer/:consumer_name" do
|
49
|
-
selectors = [
|
50
|
-
|
49
|
+
selectors = [
|
50
|
+
PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: params[:consumer_name]),
|
51
|
+
PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: params[:provider_name])
|
52
|
+
]
|
53
|
+
options = { latestby: "cvpv", limit: 100 }
|
51
54
|
lines = matrix_service.find(selectors, options)
|
52
55
|
lines = PactBroker::UI::ViewDomain::MatrixLines.new(lines, base_url: base_url)
|
53
|
-
locals =
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
locals = {
|
57
|
+
lines: lines,
|
58
|
+
consumer_name: params[:consumer_name],
|
59
|
+
provider_name: params[:provider_name],
|
60
|
+
selectors: create_selector_objects(selectors),
|
61
|
+
options: create_options_model(options),
|
62
|
+
badge_url: nil,
|
63
|
+
base_url: base_url
|
64
|
+
}
|
62
65
|
haml :'matrix/show', { locals: locals, layout: :'layouts/main', escape_html: true }
|
63
66
|
end
|
64
67
|
end
|
data/lib/pact_broker/version.rb
CHANGED
data/pact_broker.gemspec
CHANGED
@@ -73,7 +73,7 @@ Gem::Specification.new do |gem|
|
|
73
73
|
gem.add_runtime_dependency "dry-logic", "0.4.2" # Later version cases ArgumentError: wrong number of arguments
|
74
74
|
gem.add_runtime_dependency "table_print", "~> 1.5"
|
75
75
|
gem.add_runtime_dependency "semantic_logger", "~> 4.3"
|
76
|
-
gem.add_runtime_dependency "sanitize", "
|
76
|
+
gem.add_runtime_dependency "sanitize", "6.0"
|
77
77
|
gem.add_runtime_dependency "wisper", "~> 2.0"
|
78
78
|
gem.add_runtime_dependency "anyway_config", "~> 2.1"
|
79
79
|
gem.add_runtime_dependency "request_store", "~> 1.5"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.97.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bethany Skurrie
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-03-
|
13
|
+
date: 2022-03-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -346,22 +346,16 @@ dependencies:
|
|
346
346
|
name: sanitize
|
347
347
|
requirement: !ruby/object:Gem::Requirement
|
348
348
|
requirements:
|
349
|
-
- -
|
350
|
-
- !ruby/object:Gem::Version
|
351
|
-
version: 5.2.1
|
352
|
-
- - "~>"
|
349
|
+
- - '='
|
353
350
|
- !ruby/object:Gem::Version
|
354
|
-
version: '
|
351
|
+
version: '6.0'
|
355
352
|
type: :runtime
|
356
353
|
prerelease: false
|
357
354
|
version_requirements: !ruby/object:Gem::Requirement
|
358
355
|
requirements:
|
359
|
-
- -
|
360
|
-
- !ruby/object:Gem::Version
|
361
|
-
version: 5.2.1
|
362
|
-
- - "~>"
|
356
|
+
- - '='
|
363
357
|
- !ruby/object:Gem::Version
|
364
|
-
version: '
|
358
|
+
version: '6.0'
|
365
359
|
- !ruby/object:Gem::Dependency
|
366
360
|
name: wisper
|
367
361
|
requirement: !ruby/object:Gem::Requirement
|
@@ -689,6 +683,7 @@ files:
|
|
689
683
|
- lib/pact_broker/api/decorators/webhooks_decorator.rb
|
690
684
|
- lib/pact_broker/api/middleware/basic_auth.rb
|
691
685
|
- lib/pact_broker/api/middleware/configuration.rb
|
686
|
+
- lib/pact_broker/api/middleware/http_debug_logs.rb
|
692
687
|
- lib/pact_broker/api/pact_broker_urls.rb
|
693
688
|
- lib/pact_broker/api/paths.rb
|
694
689
|
- lib/pact_broker/api/renderers/html_pact_renderer.rb
|
@@ -918,11 +913,9 @@ files:
|
|
918
913
|
- lib/pact_broker/locale/en.yml
|
919
914
|
- lib/pact_broker/logging.rb
|
920
915
|
- lib/pact_broker/logging/default_formatter.rb
|
921
|
-
- lib/pact_broker/matrix/aggregated_row.rb
|
922
916
|
- lib/pact_broker/matrix/can_i_deploy_query_schema.rb
|
923
917
|
- lib/pact_broker/matrix/deployment_status_summary.rb
|
924
918
|
- lib/pact_broker/matrix/every_row.rb
|
925
|
-
- lib/pact_broker/matrix/head_row.rb
|
926
919
|
- lib/pact_broker/matrix/integration.rb
|
927
920
|
- lib/pact_broker/matrix/parse_can_i_deploy_query.rb
|
928
921
|
- lib/pact_broker/matrix/parse_query.rb
|
@@ -934,7 +927,6 @@ files:
|
|
934
927
|
- lib/pact_broker/matrix/reason.rb
|
935
928
|
- lib/pact_broker/matrix/repository.rb
|
936
929
|
- lib/pact_broker/matrix/resolved_selector.rb
|
937
|
-
- lib/pact_broker/matrix/row.rb
|
938
930
|
- lib/pact_broker/matrix/service.rb
|
939
931
|
- lib/pact_broker/matrix/unresolved_selector.rb
|
940
932
|
- lib/pact_broker/messages.rb
|
@@ -963,6 +955,7 @@ files:
|
|
963
955
|
- lib/pact_broker/pacts/pact_publication_selector_dataset_module.rb
|
964
956
|
- lib/pact_broker/pacts/pact_publication_wip_dataset_module.rb
|
965
957
|
- lib/pact_broker/pacts/pact_version.rb
|
958
|
+
- lib/pact_broker/pacts/pact_version_association_loaders.rb
|
966
959
|
- lib/pact_broker/pacts/pacts_for_verification_repository.rb
|
967
960
|
- lib/pact_broker/pacts/parse.rb
|
968
961
|
- lib/pact_broker/pacts/placeholder_pact.rb
|
@@ -1229,7 +1222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1229
1222
|
- !ruby/object:Gem::Version
|
1230
1223
|
version: '0'
|
1231
1224
|
requirements: []
|
1232
|
-
rubygems_version: 3.3.
|
1225
|
+
rubygems_version: 3.3.10
|
1233
1226
|
signing_key:
|
1234
1227
|
specification_version: 4
|
1235
1228
|
summary: See description
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require "forwardable"
|
2
|
-
require "pact_broker/verifications/repository"
|
3
|
-
|
4
|
-
# A collection of matrix rows with the same pact publication id
|
5
|
-
# It's basically a normalised view of a denormalised view :(
|
6
|
-
# A pact publication may be the overall latest, and/or the latest for a tag
|
7
|
-
module PactBroker
|
8
|
-
module Matrix
|
9
|
-
class AggregatedRow
|
10
|
-
extend Forwardable
|
11
|
-
|
12
|
-
delegate [:consumer, :consumer_name, :consumer_version, :consumer_version_number, :consumer_version_order, :consumer_version_tags] => :first_row
|
13
|
-
delegate [:provider, :provider_name, :provider_version, :provider_version_number, :provider_version_order, :provider_version_tags] => :first_row
|
14
|
-
delegate [:pact, :pact_version, :pact_revision_number, :webhooks, :latest_triggered_webhooks, :'<=>'] => :first_row
|
15
|
-
delegate [:verification_id, :verification] => :first_row
|
16
|
-
|
17
|
-
def initialize matrix_rows
|
18
|
-
@matrix_rows = matrix_rows
|
19
|
-
@first_row = matrix_rows.first
|
20
|
-
end
|
21
|
-
|
22
|
-
def overall_latest?
|
23
|
-
!!matrix_rows.find{ | row| row.consumer_version_tag_name.nil? }
|
24
|
-
end
|
25
|
-
|
26
|
-
# If this comes back nil, it won't be "cached", but it's a reasonably
|
27
|
-
# quick query, so it's probably ok.
|
28
|
-
# The collection of pacts that belong to the same tag can be considered
|
29
|
-
# a pseudo branch. Find the latest verification for each pseudo branch
|
30
|
-
# and return the most recent. If this pact is the most recent overall,
|
31
|
-
# and there were no verifications found for any of the tags, then
|
32
|
-
# return the most recent verification
|
33
|
-
def latest_verification_for_pseudo_branch
|
34
|
-
@latest_verification ||= begin
|
35
|
-
verification = matrix_rows.collect do | row|
|
36
|
-
row.verification || latest_verification_for_consumer_version_tag(row)
|
37
|
-
end.compact.sort_by(&:id).last
|
38
|
-
|
39
|
-
if !verification && overall_latest?
|
40
|
-
overall_latest_verification
|
41
|
-
else
|
42
|
-
verification
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def latest_verification_for_pact_version
|
48
|
-
@latest_verificaton_for_pact_version ||= begin
|
49
|
-
matrix_rows.collect(&:verification).compact.sort_by(&:id).last
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# The list of tag names for which this pact publication is the most recent with that tag
|
54
|
-
# There could, however, be a later consumer version that does't have a pact (perhaps because it was deleted)
|
55
|
-
# that has the same tag.
|
56
|
-
# TODO show a warning when the data is "corrupted" as above.
|
57
|
-
def consumer_head_tag_names
|
58
|
-
matrix_rows.collect(&:consumer_version_tag_name).compact
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
attr_reader :matrix_rows, :first_row
|
64
|
-
|
65
|
-
def latest_verification_for_consumer_version_tag row
|
66
|
-
row.latest_verification_for_consumer_version_tag if row.consumer_version_tag_name
|
67
|
-
end
|
68
|
-
|
69
|
-
def overall_latest_verification
|
70
|
-
# not eager loaded because it shouldn't be called that often
|
71
|
-
first_row.latest_verification_for_consumer_and_provider
|
72
|
-
end
|
73
|
-
|
74
|
-
def consumer_version_tag_names
|
75
|
-
matrix_rows.collect(&:consumer_version_tag_name)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require "pact_broker/matrix/row"
|
2
|
-
require "pact_broker/webhooks/webhook"
|
3
|
-
|
4
|
-
module PactBroker
|
5
|
-
module Matrix
|
6
|
-
# A row for each of the overall latest pacts, and a row for each of the latest tagged pacts
|
7
|
-
# Rows with a nil consumer_tag_name are the overall latest
|
8
|
-
class HeadRow < Row
|
9
|
-
set_dataset(:head_matrix)
|
10
|
-
|
11
|
-
# one_to_one :latest_verification_for_consumer_version_tag,
|
12
|
-
# :class => "PactBroker::Verifications::LatestVerificationForConsumerVersionTag",
|
13
|
-
# primary_key: [:provider_id, :consumer_id, :consumer_version_tag_name], key: [:provider_id, :consumer_id, :consumer_version_tag_name]
|
14
|
-
|
15
|
-
# Loading the latest_verification_for_consumer_version_tag objects this way is quicker than
|
16
|
-
# doing it using an inbult relation with primary_key/key, if we are loading the relation for
|
17
|
-
# the entire HeadRow table
|
18
|
-
# Using the inbuilt relation puts constraints on the columns that are not necessary and slow
|
19
|
-
# the query down.
|
20
|
-
# This relation relies on consumer_version_tags already being loaded
|
21
|
-
one_to_one :latest_verification_for_consumer_version_tag, :class => "PactBroker::Verifications::LatestVerificationForConsumerVersionTag", primary_keys: [], key: [], :eager_loader=>(proc do |eo_opts|
|
22
|
-
# create an index of provider_id/consumer_id/consumer_version_tag_name => row
|
23
|
-
tag_to_row = eo_opts[:rows].each_with_object({}) { | row, map | map[[row.provider_id, row.consumer_id, row.consumer_version_tag_name]] = row }
|
24
|
-
# Initialise the association with nil - not sure why?
|
25
|
-
eo_opts[:rows].each{|row| row.associations[:latest_verification_for_consumer_version_tag] = nil}
|
26
|
-
|
27
|
-
# Need the all then the each to ensure the eager loading works
|
28
|
-
PactBroker::Verifications::LatestVerificationForConsumerVersionTag.each do | verification |
|
29
|
-
key = [verification.provider_id, verification.consumer_id, verification.consumer_version_tag_name]
|
30
|
-
if tag_to_row[key]
|
31
|
-
tag_to_row[key].associations[:latest_verification_for_consumer_version_tag] = verification
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end)
|
35
|
-
|
36
|
-
# When viewing the index, every webhook in the database will match at least one of the rows, so
|
37
|
-
# it makes sense to load the entire table and match each webhook to the appropriate row.
|
38
|
-
# This will only work when using eager loading. The keys are just blanked out to avoid errors.
|
39
|
-
# I don't understand how they work at all.
|
40
|
-
# It would be nice to do this declaratively.
|
41
|
-
many_to_many :webhooks, class: :'PactBroker::Webhooks::Webhook', :left_key => [], left_primary_key: [], :eager_loader=>(proc do |eo_opts|
|
42
|
-
eo_opts[:rows].each do |row|
|
43
|
-
row.associations[:webhooks] = []
|
44
|
-
end
|
45
|
-
|
46
|
-
PactBroker::Webhooks::Webhook.each do | webhook |
|
47
|
-
eo_opts[:rows].each do | row |
|
48
|
-
if webhook.is_for?(row)
|
49
|
-
row.associations[:webhooks] << webhook
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Table: head_matrix
|
59
|
-
# Columns:
|
60
|
-
# consumer_id | integer |
|
61
|
-
# consumer_name | text |
|
62
|
-
# consumer_version_id | integer |
|
63
|
-
# consumer_version_number | text |
|
64
|
-
# consumer_version_order | integer |
|
65
|
-
# pact_publication_id | integer |
|
66
|
-
# pact_version_id | integer |
|
67
|
-
# pact_version_sha | text |
|
68
|
-
# pact_revision_number | integer |
|
69
|
-
# pact_created_at | timestamp without time zone |
|
70
|
-
# provider_id | integer |
|
71
|
-
# provider_name | text |
|
72
|
-
# provider_version_id | integer |
|
73
|
-
# provider_version_number | text |
|
74
|
-
# provider_version_order | integer |
|
75
|
-
# verification_id | integer |
|
76
|
-
# success | boolean |
|
77
|
-
# verification_number | integer |
|
78
|
-
# verification_executed_at | timestamp without time zone |
|
79
|
-
# verification_build_url | text |
|
80
|
-
# consumer_version_tag_name | text |
|