pact_broker 2.84.0 → 2.87.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/trigger_pact_docs_update.yml +22 -0
- data/CHANGELOG.md +63 -0
- data/DEVELOPER_DOCUMENTATION.md +0 -2
- data/db/migrations/20210913_add_pending_to_verifications.rb +7 -0
- data/db/migrations/20210914_add_labels_to_webhooks.rb +14 -0
- data/db/migrations/20210915_add_verified_by_to_verification.rb +6 -0
- data/db/migrations/20210929_increase_event_context_column_size.rb +14 -0
- data/docker-compose-ci-mysql.yml +1 -0
- data/docker-compose-test.yml +2 -0
- data/docs/CONFIGURATION.md +255 -66
- data/docs/configuration.yml +166 -101
- data/lib/db.rb +0 -1
- data/lib/pact/doc/interaction_view_model.rb +2 -2
- data/lib/pact/doc/markdown/consumer_contract_renderer.rb +4 -4
- data/lib/pact_broker/api/contracts/configuration.rb +33 -0
- data/lib/pact_broker/api/contracts/publish_contracts_schema.rb +35 -16
- data/lib/pact_broker/api/contracts/webhook_contract.rb +24 -2
- data/lib/pact_broker/api/decorators/matrix_decorator.rb +3 -1
- data/lib/pact_broker/api/decorators/reason_decorator.rb +2 -2
- data/lib/pact_broker/api/decorators/verification_decorator.rb +9 -3
- data/lib/pact_broker/api/decorators/verification_summary_decorator.rb +1 -2
- data/lib/pact_broker/api/decorators/webhook_decorator.rb +27 -4
- data/lib/pact_broker/api/middleware/configuration.rb +33 -0
- data/lib/pact_broker/api/pact_broker_urls.rb +35 -7
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +15 -11
- data/lib/pact_broker/api/resources/all_webhooks.rb +2 -2
- data/lib/pact_broker/api/resources/default_base_resource.rb +4 -0
- data/lib/pact_broker/api/resources/environment.rb +1 -1
- data/lib/pact_broker/api/resources/environments.rb +1 -1
- data/lib/pact_broker/api/resources/index.rb +7 -1
- data/lib/pact_broker/api/resources/pact_versions_for_branch.rb +40 -0
- data/lib/pact_broker/api/resources/publish_contracts.rb +1 -1
- data/lib/pact_broker/api/resources/verification.rb +5 -2
- data/lib/pact_broker/api/resources/verifications.rb +5 -1
- data/lib/pact_broker/api/resources/webhook_execution_methods.rb +23 -17
- data/lib/pact_broker/api.rb +2 -0
- data/lib/pact_broker/app.rb +2 -0
- data/lib/pact_broker/application_context.rb +5 -0
- data/lib/pact_broker/badges/service.rb +3 -1
- 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/configuration.rb +33 -29
- data/lib/pact_broker/db/clean.rb +1 -2
- data/lib/pact_broker/db/delete_overwritten_data.rb +41 -23
- data/lib/pact_broker/deployments/deployed_version.rb +1 -0
- data/lib/pact_broker/deployments/deployed_version_service.rb +1 -0
- data/lib/pact_broker/deployments/environment_service.rb +4 -1
- data/lib/pact_broker/deployments/released_version_service.rb +1 -0
- data/lib/pact_broker/doc/controllers/app.rb +1 -0
- data/lib/pact_broker/doc/views/can-i-deploy.markdown +2 -1
- data/lib/pact_broker/doc/views/index/publish-contracts.markdown +38 -9
- 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/index_item.rb +9 -0
- data/lib/pact_broker/domain/pacticipant.rb +4 -0
- data/lib/pact_broker/domain/verification.rb +28 -4
- data/lib/pact_broker/domain/webhook.rb +27 -15
- data/lib/pact_broker/domain/webhook_pacticipant.rb +6 -0
- data/lib/pact_broker/domain/webhook_request.rb +2 -2
- data/lib/pact_broker/index/service.rb +77 -26
- data/lib/pact_broker/locale/en.yml +6 -1
- data/lib/pact_broker/matrix/head_row.rb +1 -1
- data/lib/pact_broker/matrix/parse_can_i_deploy_query.rb +5 -3
- 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/pacticipants/repository.rb +1 -1
- data/lib/pact_broker/pacts/latest_pact_publication_id_for_consumer_version.rb +0 -1
- data/lib/pact_broker/pacts/metadata.rb +11 -3
- data/lib/pact_broker/pacts/pact_publication.rb +44 -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 +68 -1
- data/lib/pact_broker/pacts/pact_version.rb +24 -1
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +5 -4
- data/lib/pact_broker/pacts/repository.rb +52 -48
- data/lib/pact_broker/pacts/service.rb +5 -5
- data/lib/pact_broker/string_refinements.rb +1 -1
- data/lib/pact_broker/test/http_test_data_builder.rb +40 -11
- data/lib/pact_broker/test/test_data_builder.rb +27 -6
- data/lib/pact_broker/ui/app.rb +7 -1
- data/lib/pact_broker/ui/controllers/dashboard.rb +80 -0
- data/lib/pact_broker/ui/controllers/groups.rb +23 -8
- data/lib/pact_broker/ui/helpers/url_helper.rb +17 -1
- data/lib/pact_broker/ui/view_models/index_item.rb +64 -8
- data/lib/pact_broker/ui/view_models/index_item_branch_head.rb +39 -0
- data/lib/pact_broker/ui/view_models/index_item_provider_branch_head.rb +39 -0
- data/lib/pact_broker/ui/view_models/matrix_branch.rb +1 -1
- data/lib/pact_broker/ui/view_models/matrix_tag.rb +0 -1
- data/lib/pact_broker/ui/views/dashboard/show.haml +202 -0
- data/lib/pact_broker/ui/views/groups/show.html.erb +60 -14
- data/lib/pact_broker/ui/views/index/_dashboard_navbar.haml +7 -0
- data/lib/pact_broker/ui/views/index/_navbar.haml +0 -7
- data/lib/pact_broker/ui/views/index/show-with-tags.haml +3 -1
- data/lib/pact_broker/ui/views/index/show.haml +35 -13
- data/lib/pact_broker/ui/views/matrix/show.haml +7 -3
- data/lib/pact_broker/verifications/pseudo_branch_status.rb +2 -0
- data/lib/pact_broker/verifications/repository.rb +5 -2
- data/lib/pact_broker/verifications/service.rb +8 -4
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/branch_head.rb +0 -2
- data/lib/pact_broker/versions/branch_version.rb +1 -0
- data/lib/pact_broker/versions/repository.rb +0 -1
- data/lib/pact_broker/webhooks/event_listener.rb +7 -5
- data/lib/pact_broker/webhooks/execution_configuration.rb +16 -0
- data/lib/pact_broker/webhooks/execution_configuration_creator.rb +3 -0
- data/lib/pact_broker/webhooks/job.rb +1 -1
- data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +18 -3
- data/lib/pact_broker/webhooks/repository.rb +10 -4
- data/lib/pact_broker/webhooks/trigger_service.rb +3 -3
- data/lib/pact_broker/webhooks/webhook.rb +71 -8
- data/lib/pact_broker/webhooks/webhook_execution_result.rb +3 -7
- data/lib/pact_broker/webhooks/webhook_request_logger.rb +4 -12
- data/lib/pact_broker/webhooks/webhook_request_template.rb +6 -8
- data/pact_broker.gemspec +4 -0
- data/public/javascripts/index.js +75 -68
- data/public/javascripts/pact.js +14 -14
- data/public/stylesheets/index.css +6 -2
- data/public/stylesheets/pact.css +11 -0
- data/script/data/auto-create-things-for-tags.rb +3 -0
- data/script/data/branches.rb +2 -2
- data/script/data/contract-published-requiring-verification.rb +0 -1
- data/script/data/environments.rb +0 -0
- data/script/data/pending.rb +26 -0
- data/script/data/tags.rb +35 -0
- data/script/data/verify-pact-for-multiple-selectors.rb +30 -0
- data/script/data/webhook.rb +22 -0
- data/script/docs/generate-configuration-docs.rb +24 -3
- data/script/generate-erd +55 -0
- data/script/seed.rb +50 -89
- data/spec/features/create_webhook_spec.rb +55 -10
- data/spec/features/delete_pact_versions_for_branch_spec.rb +34 -0
- data/spec/features/get_pact_spec.rb +2 -3
- data/spec/fixtures/approvals/modifiable_resources.approved.json +4 -0
- data/spec/fixtures/invalid-publish-contract-body.json +38 -0
- data/spec/fixtures/verification.json +4 -0
- data/spec/integration/app_spec.rb +6 -6
- data/spec/integration/webhooks/contract_publication_spec.rb +68 -0
- data/spec/integration/webhooks/contract_requiring_verification_published_spec.rb +67 -0
- data/spec/integration/webhooks/pact_publication_spec.rb +51 -0
- data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +2 -2
- data/spec/lib/pact_broker/api/contracts/publish_contracts_schema_spec.rb +13 -0
- data/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +50 -0
- data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +1 -1
- data/spec/lib/pact_broker/api/decorators/reason_decorator_spec.rb +2 -2
- data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +15 -7
- data/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb +6 -2
- data/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +4 -4
- data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +1 -1
- data/spec/lib/pact_broker/api/middleware/configuration_spec.rb +43 -0
- data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +18 -0
- data/spec/lib/pact_broker/api/resources/triggered_webhook_logs_spec.rb +6 -5
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +2 -3
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +1 -1
- data/spec/lib/pact_broker/badges/service_spec.rb +22 -0
- 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/domain/webhook_request_spec.rb +2 -1
- data/spec/lib/pact_broker/domain/webhook_spec.rb +15 -5
- data/spec/lib/pact_broker/index/service_spec.rb +1 -5
- data/spec/lib/pact_broker/index/service_view_spec.rb +144 -0
- data/spec/lib/pact_broker/matrix/head_row_spec.rb +9 -5
- data/spec/lib/pact_broker/matrix/parse_can_i_deploy_query_spec.rb +13 -0
- data/spec/lib/pact_broker/pacts/metadata_spec.rb +11 -2
- 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_publication_latest_verification_spec.rb +29 -0
- data/spec/lib/pact_broker/pacts/pact_version_spec.rb +32 -0
- data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +4 -5
- data/spec/lib/pact_broker/pacts/repository_spec.rb +48 -2
- data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +12 -9
- data/spec/lib/pact_broker/verifications/pseudo_branch_status_spec.rb +9 -1
- data/spec/lib/pact_broker/verifications/service_spec.rb +24 -8
- data/spec/lib/pact_broker/webhooks/job_spec.rb +4 -4
- data/spec/lib/pact_broker/webhooks/render_spec.rb +3 -2
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +158 -15
- data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +9 -5
- data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +6 -12
- data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +3 -2
- data/spec/lib/pact_broker/webhooks/webhook_spec.rb +8 -5
- data/spec/support/generated_markdown.md +3 -3
- data/tasks/db.rake +4 -1
- metadata +72 -14
- 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/api/resources/webhook_execution_result_spec.rb +0 -56
- data/spec/lib/pact_broker/verifications/latest_verification_for_pact_version_spec.rb +0 -18
@@ -23,6 +23,8 @@ module PactBroker
|
|
23
23
|
let(:webhook) { Domain::Webhook.new(request: request, events: events) }
|
24
24
|
let(:consumer) { td.create_pacticipant("Consumer").and_return(:pacticipant) }
|
25
25
|
let(:provider) { td.create_pacticipant("Provider").and_return(:pacticipant) }
|
26
|
+
let(:webhook_consumer) { Domain::WebhookPacticipant.new(name: consumer.name) }
|
27
|
+
let(:webhook_provider) { Domain::WebhookPacticipant.new(name: provider.name) }
|
26
28
|
let(:uuid) { "the-uuid" }
|
27
29
|
let(:created_webhook_record) { ::DB::PACT_BROKER_DB[:webhooks].order(:id).last }
|
28
30
|
let(:created_events) { ::DB::PACT_BROKER_DB[:webhook_events].where(webhook_id: created_webhook_record[:id]).order(:name).all }
|
@@ -57,13 +59,13 @@ module PactBroker
|
|
57
59
|
end
|
58
60
|
|
59
61
|
context "when consumer and provider domain objects are set on the object rather than passed in" do
|
60
|
-
let(:webhook) { Domain::Webhook.new(request: request, events: events, consumer:
|
62
|
+
let(:webhook) { Domain::Webhook.new(request: request, events: events, consumer: webhook_consumer, provider: webhook_provider) }
|
61
63
|
|
62
64
|
subject { Repository.new.create(uuid, webhook, nil, nil) }
|
63
65
|
|
64
66
|
it "sets the consumer and provider relationships" do
|
65
|
-
expect(subject.consumer.
|
66
|
-
expect(subject.provider.
|
67
|
+
expect(subject.consumer.name).to eq consumer.name
|
68
|
+
expect(subject.provider.name).to eq provider.name
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
@@ -185,12 +187,10 @@ module PactBroker
|
|
185
187
|
end
|
186
188
|
|
187
189
|
it "returns a webhook with the consumer set" do
|
188
|
-
expect(subject.consumer.id).to eq consumer.id
|
189
190
|
expect(subject.consumer.name).to eq consumer.name
|
190
191
|
end
|
191
192
|
|
192
193
|
it "returns a webhook with the provider set" do
|
193
|
-
expect(subject.provider.id).to eq provider.id
|
194
194
|
expect(subject.provider.name).to eq provider.name
|
195
195
|
end
|
196
196
|
|
@@ -286,7 +286,7 @@ module PactBroker
|
|
286
286
|
let(:new_event) do
|
287
287
|
PactBroker::Webhooks::WebhookEvent.new(name: "something_else")
|
288
288
|
end
|
289
|
-
let(:new_consumer) {
|
289
|
+
let(:new_consumer) { Domain::WebhookPacticipant.new(name: "Foo2") }
|
290
290
|
let(:new_webhook) do
|
291
291
|
PactBroker::Domain::Webhook.new(
|
292
292
|
consumer: new_consumer,
|
@@ -423,11 +423,13 @@ module PactBroker
|
|
423
423
|
subject { Repository.new.find_webhooks_to_trigger(consumer: td.consumer, provider: td.provider, event_name: "contract_published") }
|
424
424
|
|
425
425
|
it "does not use a policy" do
|
426
|
-
td.create_webhook(event_names: ["contract_published"], enabled: enabled)
|
426
|
+
td.create_webhook(event_names: ["contract_published"], enabled: enabled, description: "Enabled webhook")
|
427
427
|
.create_consumer("Foo")
|
428
428
|
.create_provider("Bar")
|
429
429
|
expect(PactBroker).to_not receive(:policy_scope!)
|
430
|
-
|
430
|
+
is_expected.to contain_exactly(
|
431
|
+
have_attributes(description: "Enabled webhook")
|
432
|
+
)
|
431
433
|
end
|
432
434
|
|
433
435
|
context "when the webhook is disabled" do
|
@@ -437,21 +439,25 @@ module PactBroker
|
|
437
439
|
.create_provider("Bar")
|
438
440
|
end
|
439
441
|
let(:enabled) { false }
|
440
|
-
|
442
|
+
|
443
|
+
it "finds no webhooks to trigger" do
|
444
|
+
is_expected.to be_empty
|
445
|
+
end
|
441
446
|
end
|
442
447
|
|
443
448
|
context "when the webhook is specified for a consumer and all providers" do
|
444
449
|
before do
|
445
450
|
td.create_consumer("Foo1")
|
446
451
|
.create_provider("Bar1")
|
447
|
-
.create_webhook(provider: nil, event_names: ["contract_published"])
|
452
|
+
.create_webhook(provider: nil, event_names: ["contract_published"], description: "Right webhook")
|
448
453
|
end
|
449
454
|
|
450
|
-
|
455
|
+
let(:webhook_consumer) { Domain::WebhookPacticipant.new(name: td.consumer.name) }
|
451
456
|
|
452
|
-
it "
|
453
|
-
|
454
|
-
|
457
|
+
it "finds one webhook to trigger" do
|
458
|
+
is_expected.to contain_exactly(
|
459
|
+
have_attributes(description: "Right webhook")
|
460
|
+
)
|
455
461
|
end
|
456
462
|
end
|
457
463
|
|
@@ -463,7 +469,144 @@ module PactBroker
|
|
463
469
|
.create_provider("Bar3")
|
464
470
|
end
|
465
471
|
|
466
|
-
|
472
|
+
it "finds no webhooks to trigger" do
|
473
|
+
is_expected.to be_empty
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
context "when the webhook is specified for matching consumer label" do
|
478
|
+
before do
|
479
|
+
td.create_webhook(
|
480
|
+
event_names: ["contract_published"],
|
481
|
+
consumer_label: "my_label",
|
482
|
+
description: "Labeled webhook"
|
483
|
+
)
|
484
|
+
.create_consumer("Consumer")
|
485
|
+
.create_label("my_label")
|
486
|
+
.create_provider("Provider")
|
487
|
+
end
|
488
|
+
|
489
|
+
it "finds one webhook to trigger" do
|
490
|
+
is_expected.to contain_exactly(
|
491
|
+
have_attributes(description: "Labeled webhook")
|
492
|
+
)
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
context "when the webhook is specified for matching consumer label and specific provider" do
|
497
|
+
before do
|
498
|
+
td.create_provider("Provider")
|
499
|
+
.create_webhook(
|
500
|
+
event_names: ["contract_published"],
|
501
|
+
consumer_label: "my_label",
|
502
|
+
description: "Labeled webhook"
|
503
|
+
)
|
504
|
+
.create_consumer("Consumer")
|
505
|
+
.create_label("my_label")
|
506
|
+
end
|
507
|
+
|
508
|
+
it "finds one webhook to trigger" do
|
509
|
+
is_expected.to contain_exactly(
|
510
|
+
have_attributes(description: "Labeled webhook")
|
511
|
+
)
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
context "when the webhook is specified for consumer label that does not match" do
|
516
|
+
before do
|
517
|
+
td.create_webhook(event_names: ["contract_published"], consumer_label: "my_label")
|
518
|
+
.create_consumer("Consumer")
|
519
|
+
.create_label("other_label")
|
520
|
+
.create_provider("Provider")
|
521
|
+
end
|
522
|
+
|
523
|
+
it "finds no webhooks to trigger" do
|
524
|
+
is_expected.to be_empty
|
525
|
+
end
|
526
|
+
end
|
527
|
+
|
528
|
+
context "when the webhook is specified for matching provider label" do
|
529
|
+
before do
|
530
|
+
td.create_webhook(
|
531
|
+
event_names: ["contract_published"],
|
532
|
+
provider_label: "my_label",
|
533
|
+
description: "Labeled webhook"
|
534
|
+
)
|
535
|
+
.create_consumer("Consumer")
|
536
|
+
.create_provider("Provider")
|
537
|
+
.create_label("my_label")
|
538
|
+
end
|
539
|
+
|
540
|
+
it "finds one webhook to trigger" do
|
541
|
+
is_expected.to contain_exactly(
|
542
|
+
have_attributes(description: "Labeled webhook")
|
543
|
+
)
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
context "when the webhook is specified for matching provider label and specific consumer" do
|
548
|
+
before do
|
549
|
+
td.create_consumer("Consumer")
|
550
|
+
.create_webhook(
|
551
|
+
event_names: ["contract_published"],
|
552
|
+
provider_label: "my_label",
|
553
|
+
description: "Labeled webhook"
|
554
|
+
)
|
555
|
+
.create_provider("Provider")
|
556
|
+
.create_label("my_label")
|
557
|
+
end
|
558
|
+
|
559
|
+
it "finds one webhook to trigger" do
|
560
|
+
is_expected.to contain_exactly(
|
561
|
+
have_attributes(description: "Labeled webhook")
|
562
|
+
)
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
context "when the webhook is specified for provider label that does not match" do
|
567
|
+
before do
|
568
|
+
td.create_webhook(event_names: ["contract_published"], provider_label: "my_label")
|
569
|
+
.create_consumer("Consumer")
|
570
|
+
.create_provider("Provider")
|
571
|
+
.create_label("other_label")
|
572
|
+
end
|
573
|
+
|
574
|
+
it "find no webhooks to trigger" do
|
575
|
+
is_expected.to be_empty
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
context "when the webhook is specified for consumer and provider label" do
|
580
|
+
before do
|
581
|
+
td.create_webhook(
|
582
|
+
event_names: ["contract_published"],
|
583
|
+
consumer_label: "clabel",
|
584
|
+
provider_label: "plabel",
|
585
|
+
description: "Labeled webhook"
|
586
|
+
)
|
587
|
+
.create_webhook(
|
588
|
+
event_names: ["contract_published"],
|
589
|
+
consumer_label: "clabel",
|
590
|
+
provider_label: "plabel2",
|
591
|
+
description: "Labeled consumer webhook"
|
592
|
+
)
|
593
|
+
.create_webhook(
|
594
|
+
event_names: ["contract_published"],
|
595
|
+
consumer_label: "clabel2",
|
596
|
+
provider_label: "plabel",
|
597
|
+
description: "Labeled provider webhook"
|
598
|
+
)
|
599
|
+
.create_consumer("Consumer")
|
600
|
+
.create_label("clabel")
|
601
|
+
.create_provider("Provider")
|
602
|
+
.create_label("plabel")
|
603
|
+
end
|
604
|
+
|
605
|
+
it "finds one webhook to trigger" do
|
606
|
+
is_expected.to contain_exactly(
|
607
|
+
have_attributes(description: "Labeled webhook")
|
608
|
+
)
|
609
|
+
end
|
467
610
|
end
|
468
611
|
end
|
469
612
|
|
@@ -340,6 +340,9 @@ module PactBroker
|
|
340
340
|
let(:webhook_execution_configuration) do
|
341
341
|
PactBroker::Webhooks::ExecutionConfiguration.new
|
342
342
|
.with_webhook_context(base_url: "http://example.org")
|
343
|
+
.with_retry_schedule([10, 60, 120, 300, 600, 1200])
|
344
|
+
.with_http_success_codes([200])
|
345
|
+
.with_user_agent("Pact Broker")
|
343
346
|
.with_show_response(true)
|
344
347
|
end
|
345
348
|
let(:event_context) { { some: "data", base_url: "http://example.org" }}
|
@@ -361,7 +364,7 @@ module PactBroker
|
|
361
364
|
.and_return(:pact)
|
362
365
|
end
|
363
366
|
|
364
|
-
let(:triggered_webhooks) { PactBroker::Webhooks::TriggerService.create_triggered_webhooks_for_event(pact, td.verification, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, event_context) }
|
367
|
+
let!(:triggered_webhooks) { PactBroker::Webhooks::TriggerService.create_triggered_webhooks_for_event(pact, td.verification, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, event_context) }
|
365
368
|
|
366
369
|
subject { PactBroker::Webhooks::TriggerService.schedule_webhooks(triggered_webhooks, options) }
|
367
370
|
|
@@ -375,10 +378,6 @@ module PactBroker
|
|
375
378
|
subject
|
376
379
|
end
|
377
380
|
|
378
|
-
it "saves the triggered webhook" do
|
379
|
-
expect { subject }.to change { PactBroker::Webhooks::TriggeredWebhook.count }.by(1)
|
380
|
-
end
|
381
|
-
|
382
381
|
it "saves the execution" do
|
383
382
|
expect { subject }.to change { PactBroker::Webhooks::Execution.count }.by(1)
|
384
383
|
end
|
@@ -387,6 +386,11 @@ module PactBroker
|
|
387
386
|
subject
|
388
387
|
expect(TriggeredWebhook.first.status).to eq TriggeredWebhook::STATUS_SUCCESS
|
389
388
|
end
|
389
|
+
|
390
|
+
it "does not call the PactBroker.configuration as it will have been reset after the end of the request" do
|
391
|
+
expect(PactBroker).to_not receive(:configuration)
|
392
|
+
subject
|
393
|
+
end
|
390
394
|
end
|
391
395
|
end
|
392
396
|
end
|
@@ -16,7 +16,7 @@ module PactBroker
|
|
16
16
|
|
17
17
|
let(:logger) { double("logger").as_null_object }
|
18
18
|
let(:uuid) { "uuid" }
|
19
|
-
let(:options) { { failure_log_message: "oops", show_response: show_response } }
|
19
|
+
let(:options) { { failure_log_message: "oops", show_response: show_response, http_code_success: [200] } }
|
20
20
|
let(:show_response) { true }
|
21
21
|
let(:username) { nil }
|
22
22
|
let(:password) { nil }
|
@@ -54,8 +54,9 @@ module PactBroker
|
|
54
54
|
let(:webhook_context) { { consumer_version_number: "123", base_url: base_url } }
|
55
55
|
|
56
56
|
let(:webhook_request_logger) { WebhookRequestLogger.new(options) }
|
57
|
+
let(:success) { true }
|
57
58
|
|
58
|
-
subject(:logs) { webhook_request_logger.log(uuid, webhook_request, response, error, webhook_context) }
|
59
|
+
subject(:logs) { webhook_request_logger.log(uuid, webhook_request, response, success, error, webhook_context) }
|
59
60
|
|
60
61
|
describe "application logs" do
|
61
62
|
it "logs the request" do
|
@@ -129,16 +130,8 @@ module PactBroker
|
|
129
130
|
end
|
130
131
|
end
|
131
132
|
|
132
|
-
context "when the
|
133
|
-
let(:
|
134
|
-
|
135
|
-
it "not successful, code '100' not in 'webhook_http_code_success'" do
|
136
|
-
expect(logs).to include "oops"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context "when the response code is not successful" do
|
141
|
-
let(:status) { 400 }
|
133
|
+
context "when the status is not successful" do
|
134
|
+
let(:success) { false }
|
142
135
|
|
143
136
|
it "logs the failure_log_message" do
|
144
137
|
expect(logs).to include "oops"
|
@@ -174,6 +167,7 @@ module PactBroker
|
|
174
167
|
end
|
175
168
|
|
176
169
|
let(:response) { nil }
|
170
|
+
let(:success) { false }
|
177
171
|
let(:error) do
|
178
172
|
err = WebhookTestError.new("blah")
|
179
173
|
allow(err).to receive(:backtrace).and_return([])
|
@@ -23,7 +23,8 @@ module PactBroker
|
|
23
23
|
password: "passwordBUILT",
|
24
24
|
uuid: "1234",
|
25
25
|
body: built_body,
|
26
|
-
headers: {"headername" => "headervalueBUILT"}
|
26
|
+
headers: {"headername" => "headervalueBUILT"},
|
27
|
+
user_agent: "Pact Broker"
|
27
28
|
}
|
28
29
|
end
|
29
30
|
|
@@ -45,7 +46,7 @@ module PactBroker
|
|
45
46
|
|
46
47
|
let(:params_hash) { double("params hash") }
|
47
48
|
|
48
|
-
subject { WebhookRequestTemplate.new(attributes).build(params_hash) }
|
49
|
+
subject { WebhookRequestTemplate.new(attributes).build(params_hash, "Pact Broker") }
|
49
50
|
|
50
51
|
it "renders the url template" do
|
51
52
|
expect(PactBroker::Webhooks::Render).to receive(:call).with(url, params_hash) do | content, pact, verification, &block |
|
@@ -6,6 +6,7 @@ module PactBroker
|
|
6
6
|
before do
|
7
7
|
td.create_consumer("Foo")
|
8
8
|
.create_provider("Bar")
|
9
|
+
.create_label("label1")
|
9
10
|
.create_consumer_version
|
10
11
|
.create_pact
|
11
12
|
.create_global_webhook
|
@@ -13,11 +14,13 @@ module PactBroker
|
|
13
14
|
.create_provider_webhook
|
14
15
|
.create_provider("Wiffle")
|
15
16
|
.create_provider_webhook
|
17
|
+
.create_webhook(provider: nil, consumer: nil, provider_label: "label1")
|
18
|
+
.create_webhook(provider: nil, consumer: nil, consumer_label: "label2", provider_label: "label1")
|
16
19
|
end
|
17
20
|
|
18
21
|
let(:consumer) { PactBroker::Domain::Pacticipant.find(name: "Foo") }
|
19
22
|
let(:provider) { PactBroker::Domain::Pacticipant.find(name: "Bar") }
|
20
|
-
let(:pact) {
|
23
|
+
let(:pact) { PactBroker::Pacts::PactPublication.find(id: td.pact.id) }
|
21
24
|
|
22
25
|
describe "#is_for?" do
|
23
26
|
let(:matching_webhook_uuids) { Webhooks::Webhook.find_by_consumer_and_or_provider(consumer, provider).collect(&:uuid) }
|
@@ -25,10 +28,10 @@ module PactBroker
|
|
25
28
|
let(:non_matching_webhooks) { Webhooks::Webhook.exclude(uuid: matching_webhook_uuids) }
|
26
29
|
|
27
30
|
it "matches the implementation of Webhook::Repository#find_by_consumer_and_or_provider" do
|
28
|
-
expect(matching_webhooks
|
29
|
-
expect(non_matching_webhooks
|
30
|
-
expect(matching_webhooks.
|
31
|
-
expect(non_matching_webhooks.
|
31
|
+
expect(matching_webhooks).not_to be_empty
|
32
|
+
expect(non_matching_webhooks).not_to be_empty
|
33
|
+
expect(matching_webhooks.reject{|w| w.is_for?(pact)}).to be_empty
|
34
|
+
expect(non_matching_webhooks.reject{|w| !w.is_for?(pact)}).to be_empty
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
|
1
|
+
# A pact between Some Consumer and Some Provider
|
2
2
|
|
3
|
-
|
3
|
+
### Requests from Some Consumer to Some Provider
|
4
4
|
|
5
5
|
* [A request for alligators in Brüssel](#a_request_for_alligators_in_Brüssel_given_alligators_exist) given alligators exist
|
6
6
|
|
7
7
|
* [A request for polar bears](#a_request_for_polar_bears)
|
8
8
|
|
9
|
-
|
9
|
+
### Interactions
|
10
10
|
|
11
11
|
<a name="a_request_for_alligators_in_Brüssel_given_alligators_exist"></a>
|
12
12
|
Given **alligators exist**, upon receiving **a request for alligators in Brüssel** from Some Consumer, with
|
data/tasks/db.rake
CHANGED
@@ -95,7 +95,10 @@ namespace :db do
|
|
95
95
|
PactBroker::Database.ensure_database_dir_exists
|
96
96
|
end
|
97
97
|
|
98
|
-
desc "Annotate the Sequel domain classes with schema information
|
98
|
+
desc "Annotate the Sequel domain classes with schema information.
|
99
|
+
Start the postgres db with script/docker/db-start.sh first and run
|
100
|
+
INSTALL_PG=true bundle exec rake db:annotate
|
101
|
+
"
|
99
102
|
task :annotate do
|
100
103
|
begin
|
101
104
|
raise "Need to set INSTALL_PG=true" unless ENV["INSTALL_PG"] == "true"
|