pact_broker 2.85.1 → 2.86.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release_gem.yml +1 -1
- data/.github/workflows/trigger_pact_docs_update.yml +22 -0
- data/CHANGELOG.md +10 -0
- data/DEVELOPER_DOCUMENTATION.md +0 -2
- data/db/migrations/20210914_add_labels_to_webhooks.rb +14 -0
- data/db/migrations/20210915_add_verified_by_to_verification.rb +6 -0
- data/docker-compose-ci-mysql.yml +1 -0
- data/docs/CONFIGURATION.md +255 -66
- data/docs/configuration.yml +166 -101
- data/lib/db.rb +0 -1
- data/lib/pact_broker/api/contracts/webhook_contract.rb +24 -2
- data/lib/pact_broker/api/decorators/verification_decorator.rb +4 -0
- data/lib/pact_broker/api/decorators/webhook_decorator.rb +27 -4
- data/lib/pact_broker/api/pact_broker_urls.rb +4 -0
- data/lib/pact_broker/api/resources/all_webhooks.rb +2 -2
- data/lib/pact_broker/config/runtime_configuration.rb +4 -0
- data/lib/pact_broker/config/runtime_configuration_database_methods.rb +1 -1
- data/lib/pact_broker/db/clean.rb +1 -2
- data/lib/pact_broker/doc/views/pacticipant/label.markdown +12 -0
- data/lib/pact_broker/doc/views/webhooks.markdown +17 -0
- data/lib/pact_broker/domain/pacticipant.rb +4 -0
- data/lib/pact_broker/domain/verification.rb +16 -4
- data/lib/pact_broker/domain/webhook.rb +5 -5
- data/lib/pact_broker/domain/webhook_pacticipant.rb +6 -0
- data/lib/pact_broker/locale/en.yml +1 -0
- data/lib/pact_broker/matrix/head_row.rb +1 -1
- data/lib/pact_broker/matrix/quick_row.rb +0 -1
- data/lib/pact_broker/matrix/repository.rb +0 -1
- data/lib/pact_broker/matrix/row.rb +2 -2
- data/lib/pact_broker/pacts/latest_pact_publication_id_for_consumer_version.rb +0 -1
- data/lib/pact_broker/pacts/pact_publication.rb +7 -0
- data/lib/pact_broker/pacts/pact_publication_clean_selector_dataset_module.rb +19 -0
- data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +30 -2
- data/lib/pact_broker/pacts/pact_version.rb +24 -1
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +2 -2
- data/lib/pact_broker/pacts/repository.rb +50 -47
- data/lib/pact_broker/test/http_test_data_builder.rb +37 -10
- data/lib/pact_broker/test/test_data_builder.rb +22 -5
- data/lib/pact_broker/verifications/repository.rb +5 -2
- data/lib/pact_broker/verifications/service.rb +4 -1
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/webhooks/event_listener.rb +4 -2
- data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +1 -0
- data/lib/pact_broker/webhooks/repository.rb +10 -4
- data/lib/pact_broker/webhooks/webhook.rb +66 -8
- data/script/data/verify-pact-for-multiple-selectors.rb +30 -0
- data/script/docs/generate-configuration-docs.rb +24 -3
- data/script/generate-erd +55 -0
- data/spec/features/create_webhook_spec.rb +55 -10
- data/spec/features/get_pact_spec.rb +2 -3
- data/spec/fixtures/verification.json +4 -0
- data/spec/integration/webhooks/pact_publication_spec.rb +51 -0
- data/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +50 -0
- data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +8 -1
- data/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb +3 -1
- data/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +4 -4
- data/spec/lib/pact_broker/config/runtime_configuration_documentation_spec.rb +30 -0
- data/spec/lib/pact_broker/deployments/environment_service_spec.rb +1 -1
- data/spec/lib/pact_broker/matrix/head_row_spec.rb +9 -5
- data/spec/lib/pact_broker/pacts/{latest_tagged_pact_publications_spec.rb → pact_publication_clean_selector_dataset_module_spec.rb} +7 -9
- data/spec/lib/pact_broker/pacts/pact_version_spec.rb +32 -0
- data/spec/lib/pact_broker/pacts/repository_spec.rb +33 -0
- data/spec/lib/pact_broker/verifications/service_spec.rb +16 -2
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +158 -15
- data/spec/lib/pact_broker/webhooks/webhook_spec.rb +8 -5
- metadata +16 -11
- data/lib/pact_broker/pacts/all_pact_publications.rb +0 -158
- data/lib/pact_broker/pacts/latest_pact_publications.rb +0 -48
- data/lib/pact_broker/pacts/latest_pact_publications_by_consumer_version.rb +0 -26
- data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +0 -45
- data/lib/pact_broker/verifications/latest_verification_for_pact_version.rb +0 -39
- data/spec/lib/pact_broker/verifications/latest_verification_for_pact_version_spec.rb +0 -18
@@ -1,6 +1,5 @@
|
|
1
1
|
require "sequel"
|
2
2
|
require "pact_broker/repositories/helpers"
|
3
|
-
require "pact_broker/verifications/latest_verification_for_pact_version"
|
4
3
|
require "pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version"
|
5
4
|
require "pact_broker/pacts/content"
|
6
5
|
|
@@ -16,6 +15,30 @@ module PactBroker
|
|
16
15
|
associate(:many_to_one, :consumer, class: "PactBroker::Domain::Pacticipant", key: :consumer_id, primary_key: :id)
|
17
16
|
associate(:many_to_many, :consumer_versions, class: "PactBroker::Domain::Version", join_table: :pact_publications, left_key: :pact_version_id, right_key: :consumer_version_id, order: :order)
|
18
17
|
|
18
|
+
one_to_one(:latest_main_branch_verification,
|
19
|
+
class: "PactBroker::Domain::Verification",
|
20
|
+
read_only: true,
|
21
|
+
dataset: lambda {
|
22
|
+
providers_join = {
|
23
|
+
Sequel[:providers][:id] => Sequel[:latest_verification_id_for_pact_version_and_provider_version][:provider_id]
|
24
|
+
}
|
25
|
+
|
26
|
+
branch_versions_join = {
|
27
|
+
Sequel[:latest_verification_id_for_pact_version_and_provider_version][:provider_version_id] => Sequel[:branch_versions][:version_id],
|
28
|
+
Sequel[:providers][:main_branch] => Sequel[:branch_versions][:branch_name]
|
29
|
+
}
|
30
|
+
max_verification_id_for_pact_version = PactBroker::Verifications::LatestVerificationIdForPactVersionAndProviderVersion
|
31
|
+
.join(:pacticipants, providers_join, { table_alias: :providers })
|
32
|
+
.join(:branch_versions, branch_versions_join)
|
33
|
+
.select(Sequel.function(:max, :verification_id))
|
34
|
+
.where(pact_version_id: id)
|
35
|
+
PactBroker::Domain::Verification.where(id: max_verification_id_for_pact_version)
|
36
|
+
},
|
37
|
+
key: :pact_version_id,
|
38
|
+
primary_key: :id,
|
39
|
+
eager_block: lambda { | ds | ds.from_provider_main_branch.latest_by_pact_version }
|
40
|
+
)
|
41
|
+
|
19
42
|
one_to_one(:latest_verification,
|
20
43
|
class: "PactBroker::Domain::Verification",
|
21
44
|
read_only: true,
|
@@ -154,8 +154,8 @@ module PactBroker
|
|
154
154
|
|
155
155
|
def find_pacts_for_which_the_latest_version_for_the_fallback_tag_is_required(provider_name, selectors)
|
156
156
|
selectors.collect do | selector |
|
157
|
-
query = scope_for(
|
158
|
-
query = query.
|
157
|
+
query = scope_for(PactPublication).for_provider_name(provider_name).for_latest_consumer_versions_with_tag(selector.fallback_tag)
|
158
|
+
query = query.for_consumer_name(selector.consumer) if selector.consumer
|
159
159
|
query.all
|
160
160
|
.collect do | latest_tagged_pact_publication |
|
161
161
|
pact_publication = unscoped(PactPublication).find(id: latest_tagged_pact_publication.id)
|
@@ -4,10 +4,6 @@ require "pact_broker/logging"
|
|
4
4
|
require "pact_broker/pacts/generate_sha"
|
5
5
|
require "pact_broker/pacts/pact_publication"
|
6
6
|
require "pact_broker/pacts/pact_version"
|
7
|
-
require "pact_broker/pacts/all_pact_publications"
|
8
|
-
require "pact_broker/pacts/latest_pact_publications_by_consumer_version"
|
9
|
-
require "pact_broker/pacts/latest_pact_publications"
|
10
|
-
require "pact_broker/pacts/latest_tagged_pact_publications"
|
11
7
|
require "pact/shared/json_differ"
|
12
8
|
require "pact_broker/domain"
|
13
9
|
require "pact_broker/pacts/parse"
|
@@ -177,17 +173,19 @@ module PactBroker
|
|
177
173
|
|
178
174
|
# Returns latest pact version for the consumer_version_number
|
179
175
|
def find_by_consumer_version consumer_name, consumer_version_number
|
180
|
-
scope_for(
|
181
|
-
.
|
182
|
-
.
|
176
|
+
scope_for(PactPublication)
|
177
|
+
.for_consumer_name_and_maybe_version_number(consumer_name, consumer_version_number)
|
178
|
+
.remove_overridden_revisions_from_complete_query
|
183
179
|
.collect(&:to_domain_with_content)
|
184
180
|
end
|
185
181
|
|
186
182
|
def find_by_version_and_provider version_id, provider_id
|
187
|
-
scope_for(
|
183
|
+
scope_for(PactPublication)
|
188
184
|
.eager(:tags)
|
189
185
|
.where(consumer_version_id: version_id, provider_id: provider_id)
|
190
|
-
.
|
186
|
+
.remove_overridden_revisions_from_complete_query
|
187
|
+
.limit(1)
|
188
|
+
.collect(&:to_domain_with_content)[0]
|
191
189
|
end
|
192
190
|
|
193
191
|
def find_latest_pacts
|
@@ -200,30 +198,35 @@ module PactBroker
|
|
200
198
|
end
|
201
199
|
|
202
200
|
def find_latest_pact(consumer_name, provider_name, tag = nil)
|
203
|
-
query = scope_for(
|
201
|
+
query = scope_for(PactPublication)
|
204
202
|
.select_all_qualified
|
205
|
-
.
|
206
|
-
.
|
203
|
+
.for_consumer_name(consumer_name)
|
204
|
+
.for_provider_name(provider_name)
|
205
|
+
.remove_overridden_revisions
|
207
206
|
if tag == :untagged
|
208
207
|
query = query.untagged
|
209
208
|
elsif tag
|
210
|
-
query = query.
|
209
|
+
query = query.for_consumer_version_tag_all_revisions(tag)
|
211
210
|
end
|
212
|
-
query.
|
211
|
+
query.latest_by_consumer_version_order.all.collect(&:to_domain_with_content)[0]
|
213
212
|
end
|
214
213
|
|
215
214
|
# Allows optional consumer_name and provider_name
|
216
215
|
def search_for_latest_pact(consumer_name, provider_name, tag = nil)
|
217
|
-
query = scope_for(
|
218
|
-
query = query.
|
219
|
-
query = query.
|
216
|
+
query = scope_for(PactPublication).select_all_qualified
|
217
|
+
query = query.for_consumer_name(consumer_name) if consumer_name
|
218
|
+
query = query.for_provider_name(provider_name) if provider_name
|
220
219
|
|
221
220
|
if tag == :untagged
|
222
221
|
query = query.untagged
|
223
222
|
elsif tag
|
224
|
-
query = query.
|
223
|
+
query = query.for_consumer_version_tag_all_revisions(tag)
|
225
224
|
end
|
226
|
-
query
|
225
|
+
query
|
226
|
+
.remove_overridden_revisions_from_complete_query
|
227
|
+
.latest_by_consumer_version_order
|
228
|
+
.all
|
229
|
+
.collect(&:to_domain_with_content)[0]
|
227
230
|
end
|
228
231
|
|
229
232
|
# rubocop: disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
@@ -279,34 +282,39 @@ module PactBroker
|
|
279
282
|
end
|
280
283
|
|
281
284
|
def find_previous_pact pact, tag = nil
|
282
|
-
query = scope_for(
|
285
|
+
query = scope_for(PactPublication)
|
286
|
+
.remove_overridden_revisions
|
283
287
|
.eager(:tags)
|
284
|
-
.
|
285
|
-
.
|
288
|
+
.for_consumer_name(pact.consumer.name)
|
289
|
+
.for_provider_name(pact.provider.name)
|
286
290
|
|
287
291
|
if tag == :untagged
|
288
292
|
query = query.untagged
|
289
293
|
elsif tag
|
290
|
-
query = query.
|
294
|
+
query = query.for_consumer_version_tag_all_revisions(tag)
|
291
295
|
end
|
292
296
|
|
293
|
-
query
|
294
|
-
|
297
|
+
query
|
298
|
+
.consumer_version_order_before(pact.consumer_version.order)
|
299
|
+
.latest_by_consumer_version_order
|
300
|
+
.collect(&:to_domain_with_content)[0]
|
295
301
|
end
|
296
302
|
|
297
303
|
def find_next_pact pact
|
298
|
-
scope_for(
|
304
|
+
scope_for(PactPublication)
|
299
305
|
.eager(:tags)
|
300
|
-
.
|
301
|
-
.
|
306
|
+
.for_consumer_name(pact.consumer.name)
|
307
|
+
.for_provider_name(pact.provider.name)
|
308
|
+
.remove_overridden_revisions
|
302
309
|
.consumer_version_order_after(pact.consumer_version.order)
|
303
|
-
.earliest
|
310
|
+
.earliest
|
311
|
+
.collect(&:to_domain_with_content)[0]
|
304
312
|
end
|
305
313
|
|
306
314
|
def find_previous_distinct_pact pact
|
307
315
|
previous, current = nil, pact
|
308
316
|
loop do
|
309
|
-
previous = find_previous_distinct_pact_by_sha
|
317
|
+
previous = find_previous_distinct_pact_by_sha(current)
|
310
318
|
return previous if previous.nil? || different?(current, previous)
|
311
319
|
current = previous
|
312
320
|
end
|
@@ -329,20 +337,14 @@ module PactBroker
|
|
329
337
|
private
|
330
338
|
|
331
339
|
def find_previous_distinct_pact_by_sha pact
|
332
|
-
|
333
|
-
|
334
|
-
.consumer(pact.consumer.name)
|
335
|
-
.provider(pact.provider.name)
|
336
|
-
.consumer_version_number(pact.consumer_version_number)
|
337
|
-
.limit(1)
|
338
|
-
|
339
|
-
scope_for(LatestPactPublicationsByConsumerVersion)
|
340
|
+
pact_version = PactVersion.for_pact_domain(pact)
|
341
|
+
scope_for(PactPublication)
|
340
342
|
.eager(:tags)
|
341
|
-
.
|
342
|
-
.
|
343
|
+
.for_consumer_name(pact.consumer.name)
|
344
|
+
.for_provider_name(pact.provider.name)
|
343
345
|
.consumer_version_order_before(pact.consumer_version.order)
|
344
|
-
.
|
345
|
-
.
|
346
|
+
.exclude(pact_version_id: pact_version.id)
|
347
|
+
.latest_by_consumer_version_order
|
346
348
|
.collect(&:to_domain_with_content)[0]
|
347
349
|
end
|
348
350
|
|
@@ -367,14 +369,15 @@ module PactBroker
|
|
367
369
|
).upsert
|
368
370
|
end
|
369
371
|
|
370
|
-
def find_all_database_versions_between(consumer_name, options
|
372
|
+
def find_all_database_versions_between(consumer_name, options)
|
371
373
|
provider_name = options.fetch(:and)
|
372
374
|
|
373
|
-
query = scope_for(
|
374
|
-
.
|
375
|
-
.
|
375
|
+
query = scope_for(PactPublication)
|
376
|
+
.for_consumer_name(consumer_name)
|
377
|
+
.for_provider_name(provider_name)
|
378
|
+
.remove_overridden_revisions
|
376
379
|
|
377
|
-
query = query.
|
380
|
+
query = query.for_consumer_version_tag_all_revisions(options[:tag]) if options[:tag]
|
378
381
|
query
|
379
382
|
end
|
380
383
|
|
@@ -102,6 +102,13 @@ module PactBroker
|
|
102
102
|
self
|
103
103
|
end
|
104
104
|
|
105
|
+
def create_label(name, label)
|
106
|
+
puts "Creating label '#{label}' for #{name}"
|
107
|
+
client.put("pacticipants/#{encode(name)}/labels/#{encode(label)}", {}).tap { |response| check_for_error(response) }
|
108
|
+
separate
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
105
112
|
def publish_contract(consumer: last_consumer_name, consumer_version:, provider: last_provider_name, content_id:, tag: nil, branch: nil)
|
106
113
|
content = generate_content(consumer, provider, content_id)
|
107
114
|
request_body_hash = {
|
@@ -206,26 +213,35 @@ module PactBroker
|
|
206
213
|
self
|
207
214
|
end
|
208
215
|
|
209
|
-
def create_global_webhook_for_event(
|
210
|
-
|
216
|
+
def create_global_webhook_for_event(**kwargs)
|
217
|
+
create_webhook_for_event(**kwargs)
|
218
|
+
end
|
219
|
+
|
220
|
+
def create_webhook_for_event(uuid: nil, url: "https://postman-echo.com/post", body: nil, provider: nil, consumer: nil, event_name:)
|
221
|
+
require "securerandom"
|
222
|
+
webhook_prefix = "global " if provider.nil? && consumer.nil?
|
223
|
+
puts "Creating #{webhook_prefix}webhook for contract changed event with uuid #{uuid}"
|
211
224
|
uuid ||= SecureRandom.uuid
|
212
225
|
default_body = {
|
213
|
-
"
|
214
|
-
"
|
226
|
+
"eventName" => "${pactbroker.eventName}",
|
227
|
+
"consumerName" => "${pactbroker.consumerName}",
|
215
228
|
"consumerVersionNumber" => "${pactbroker.consumerVersionNumber}",
|
216
|
-
"
|
229
|
+
"providerVersionBranch" => "${pactbroker.providerVersionBranch}",
|
230
|
+
"providerName" => "${pactbroker.providerName}",
|
231
|
+
"providerVersionNumber" => "${pactbroker.providerVersionNumber}",
|
232
|
+
"consumerVersionBranch" => "${pactbroker.consumerVersionBranch}",
|
217
233
|
}
|
218
234
|
request_body = {
|
219
|
-
"
|
220
|
-
"
|
221
|
-
|
222
|
-
}
|
235
|
+
"consumer" => consumer,
|
236
|
+
"provider" => provider,
|
237
|
+
"description" => webhook_description(consumer, provider),
|
238
|
+
"events" => Array(event_name).map { |name| {"name" => name} },
|
223
239
|
"request" => {
|
224
240
|
"method" => "POST",
|
225
241
|
"url" => url,
|
226
242
|
"body" => body || default_body
|
227
243
|
}
|
228
|
-
}
|
244
|
+
}.compact
|
229
245
|
path = "webhooks/#{uuid}"
|
230
246
|
client.put(path, request_body.to_json).tap { |response| check_for_error(response) }
|
231
247
|
separate
|
@@ -333,6 +349,17 @@ module PactBroker
|
|
333
349
|
|
334
350
|
private
|
335
351
|
|
352
|
+
def webhook_description(consumer, provider)
|
353
|
+
return "A webhook for all consumers and providers" if consumer.nil? && provider.nil?
|
354
|
+
|
355
|
+
suffix = {consumer: consumer, provider: provider}.compact.map do |name, pacticipant|
|
356
|
+
desc = pacticipant.compact.map { |k, v| "#{k}: '#{v}'"}.first
|
357
|
+
"#{name}s by #{desc}"
|
358
|
+
end
|
359
|
+
|
360
|
+
"A webhook for #{suffix.join(' and ')}"
|
361
|
+
end
|
362
|
+
|
336
363
|
def publish_verification_results(url_of_pact_to_verify, provider, provider_version, provider_version_tag, provider_version_branch, success)
|
337
364
|
[*provider_version_tag].each do | tag |
|
338
365
|
create_tag(pacticipant: provider, version: provider_version, tag: tag)
|
@@ -269,11 +269,10 @@ module PactBroker
|
|
269
269
|
self
|
270
270
|
end
|
271
271
|
|
272
|
-
# rubocop: disable Metrics/CyclomaticComplexity
|
273
272
|
def create_webhook parameters = {}
|
274
273
|
params = parameters.dup
|
275
|
-
consumer =
|
276
|
-
provider =
|
274
|
+
consumer, webhook_consumer = webhook_pacticipant(:consumer, params)
|
275
|
+
provider, webhook_provider = webhook_pacticipant(:provider, params)
|
277
276
|
uuid = params[:uuid] || PactBroker::Webhooks::Service.next_uuid
|
278
277
|
enabled = params.key?(:enabled) ? params.delete(:enabled) : true
|
279
278
|
event_params = if params[:event_names]
|
@@ -282,9 +281,17 @@ module PactBroker
|
|
282
281
|
params[:events] || [{ name: PactBroker::Webhooks::WebhookEvent::DEFAULT_EVENT_NAME }]
|
283
282
|
end
|
284
283
|
events = event_params.collect{ |e| PactBroker::Webhooks::WebhookEvent.new(e) }
|
285
|
-
template_params = { method: "POST", url: "http://example.org", headers: {"Content-Type" => "application/json"}, username: params[:username], password: params[:password]}
|
284
|
+
template_params = { method: "POST", url: "http://example.org", headers: {"Content-Type" => "application/json"}, username: params[:username], password: params[:password] }
|
286
285
|
request = PactBroker::Webhooks::WebhookRequestTemplate.new(template_params.merge(params))
|
287
|
-
|
286
|
+
new_webhook = PactBroker::Domain::Webhook.new(
|
287
|
+
request: request,
|
288
|
+
events: events,
|
289
|
+
description: params[:description],
|
290
|
+
enabled: enabled,
|
291
|
+
consumer: webhook_consumer,
|
292
|
+
provider: webhook_provider
|
293
|
+
)
|
294
|
+
@webhook = PactBroker::Webhooks::Repository.new.create uuid, new_webhook, consumer, provider
|
288
295
|
self
|
289
296
|
end
|
290
297
|
# rubocop: enable Metrics/CyclomaticComplexity
|
@@ -597,6 +604,16 @@ module PactBroker
|
|
597
604
|
"random" => rand
|
598
605
|
}.to_json
|
599
606
|
end
|
607
|
+
|
608
|
+
def webhook_pacticipant(name, params)
|
609
|
+
pacticipant = params.key?(name) ? params.delete(name) : instance_variable_get(:"@#{name}")
|
610
|
+
label = params.delete(:"#{name}_label")
|
611
|
+
if pacticipant
|
612
|
+
[pacticipant, Domain::WebhookPacticipant.new(name: pacticipant.name)]
|
613
|
+
elsif label
|
614
|
+
[nil, Domain::WebhookPacticipant.new(label: label)]
|
615
|
+
end
|
616
|
+
end
|
600
617
|
end
|
601
618
|
end
|
602
619
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require "sequel"
|
2
2
|
require "pact_broker/domain/verification"
|
3
|
-
require "pact_broker/verifications/latest_verification_for_pact_version"
|
4
3
|
require "pact_broker/verifications/sequence"
|
5
4
|
require "pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version"
|
6
5
|
|
@@ -61,6 +60,10 @@ module PactBroker
|
|
61
60
|
PactBroker::Pacts::PactPublication.where(id: pact.id).single_record.latest_verification
|
62
61
|
end
|
63
62
|
|
63
|
+
def find_latest_from_main_branch_for_pact(pact)
|
64
|
+
PactBroker::Pacts::PactPublication.where(id: pact.id).single_record.latest_main_branch_verification
|
65
|
+
end
|
66
|
+
|
64
67
|
def any_verifications?(consumer, provider)
|
65
68
|
PactBroker::Domain::Verification.where(consumer_id: consumer.id, provider_id: provider.id).any?
|
66
69
|
end
|
@@ -73,7 +76,7 @@ module PactBroker
|
|
73
76
|
end
|
74
77
|
|
75
78
|
def find_latest_verifications_for_consumer_version consumer_name, consumer_version_number
|
76
|
-
# Use
|
79
|
+
# Use remove_verifications_for_overridden_consumer_versions because we don't
|
77
80
|
# want verifications for shadowed revisions as it would be misleading.
|
78
81
|
PactBroker::Domain::Verification
|
79
82
|
.select_all_qualified
|
@@ -21,12 +21,13 @@ module PactBroker
|
|
21
21
|
using PactBroker::HashRefinements
|
22
22
|
extend PactBroker::Events::Publisher
|
23
23
|
|
24
|
-
delegate [:any_verifications
|
24
|
+
delegate [:any_verifications?, :find_latest_from_main_branch_for_pact] => :verification_repository
|
25
25
|
|
26
26
|
def next_number
|
27
27
|
verification_repository.next_number
|
28
28
|
end
|
29
29
|
|
30
|
+
# TODO use a decorator instead of passing in params, srsly, Beth
|
30
31
|
# verified_pacts is an array of SelectedPact objects
|
31
32
|
def create next_verification_number, params, verified_pacts, event_context
|
32
33
|
first_verified_pact = verified_pacts.first
|
@@ -37,6 +38,8 @@ module PactBroker
|
|
37
38
|
verification.wip = params.fetch("wip")
|
38
39
|
verification.pact_pending = params.fetch("pending")
|
39
40
|
verification.number = next_verification_number
|
41
|
+
verification.verified_by_implementation = params.dig("verifiedBy", "implementation")
|
42
|
+
verification.verified_by_version = params.dig("verifiedBy", "version")
|
40
43
|
verification.consumer_version_selector_hashes = event_context[:consumer_version_selectors]
|
41
44
|
pact_version = pact_repository.find_pact_version(first_verified_pact.consumer, first_verified_pact.provider, first_verified_pact.pact_version_sha)
|
42
45
|
verification = verification_repository.create(verification, provider_version_number, pact_version)
|
data/lib/pact_broker/version.rb
CHANGED
@@ -18,14 +18,16 @@ module PactBroker
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def contract_published(params)
|
21
|
-
|
21
|
+
main_branch_verification = verification_service.find_latest_from_main_branch_for_pact(params.fetch(:pact))
|
22
|
+
handle_event_for_webhook(PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED, { verification: main_branch_verification }.compact.merge(params))
|
22
23
|
if verification_service.calculate_required_verifications_for_pact(params.fetch(:pact)).any?
|
23
24
|
handle_event_for_webhook(PactBroker::Webhooks::WebhookEvent::CONTRACT_REQUIRING_VERIFICATION_PUBLISHED, params)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
def contract_content_changed(params)
|
28
|
-
|
29
|
+
main_branch_verification = verification_service.find_latest_from_main_branch_for_pact(params.fetch(:pact))
|
30
|
+
handle_event_for_webhook(PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, { verification: main_branch_verification }.compact.merge(params))
|
29
31
|
end
|
30
32
|
|
31
33
|
def contract_content_unchanged(params)
|
@@ -41,6 +41,7 @@ module PactBroker
|
|
41
41
|
CURRENTLY_DEPLOYED_PROVIDER_VERSION_NUMBER
|
42
42
|
]
|
43
43
|
|
44
|
+
# TODO change this verification to the latest main branch
|
44
45
|
def initialize(pact, trigger_verification, webhook_context)
|
45
46
|
@pact = pact
|
46
47
|
@verification = trigger_verification || (pact && pact.latest_verification)
|
@@ -17,8 +17,8 @@ module PactBroker
|
|
17
17
|
include Repositories
|
18
18
|
|
19
19
|
def create uuid, webhook, consumer, provider
|
20
|
-
consumer =
|
21
|
-
provider =
|
20
|
+
consumer = find_pacticipant_by_name(webhook.consumer) || consumer
|
21
|
+
provider = find_pacticipant_by_name(webhook.provider) || provider
|
22
22
|
db_webhook = Webhook.from_domain webhook, consumer, provider
|
23
23
|
db_webhook.uuid = uuid
|
24
24
|
db_webhook.save
|
@@ -36,8 +36,8 @@ module PactBroker
|
|
36
36
|
# policy applied at resource level
|
37
37
|
def update_by_uuid uuid, webhook
|
38
38
|
existing_webhook = deliberately_unscoped(Webhook).find(uuid: uuid)
|
39
|
-
existing_webhook.consumer_id =
|
40
|
-
existing_webhook.provider_id =
|
39
|
+
existing_webhook.consumer_id = find_pacticipant_by_name(webhook.consumer)&.id
|
40
|
+
existing_webhook.provider_id = find_pacticipant_by_name(webhook.provider)&.id
|
41
41
|
existing_webhook.update_from_domain(webhook).save
|
42
42
|
existing_webhook.events.collect(&:delete)
|
43
43
|
(webhook.events || []).each do | webhook_event |
|
@@ -187,6 +187,12 @@ module PactBroker
|
|
187
187
|
|
188
188
|
private
|
189
189
|
|
190
|
+
def find_pacticipant_by_name(pacticipant)
|
191
|
+
return unless pacticipant&.name
|
192
|
+
|
193
|
+
pacticipant_repository.find_by_name(pacticipant.name)
|
194
|
+
end
|
195
|
+
|
190
196
|
def deliberately_unscoped(scope)
|
191
197
|
scope
|
192
198
|
end
|