pact_broker 2.59.1 → 2.62.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -0
  3. data/README.md +1 -1
  4. data/db/migrations/20200922_add_event_to_triggered_webhook.rb +5 -0
  5. data/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb +10 -3
  6. data/lib/pact_broker/api/contracts/verifiable_pacts_query_schema.rb +1 -0
  7. data/lib/pact_broker/api/decorators/triggered_webhook_decorator.rb +1 -0
  8. data/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +5 -5
  9. data/lib/pact_broker/api/pact_broker_urls.rb +9 -2
  10. data/lib/pact_broker/api/resources/all_webhooks.rb +1 -6
  11. data/lib/pact_broker/api/resources/can_i_deploy.rb +0 -4
  12. data/lib/pact_broker/api/resources/default_base_resource.rb +9 -0
  13. data/lib/pact_broker/api/resources/error_handler.rb +2 -4
  14. data/lib/pact_broker/api/resources/error_test.rb +4 -2
  15. data/lib/pact_broker/api/resources/group.rb +0 -4
  16. data/lib/pact_broker/api/resources/index.rb +11 -8
  17. data/lib/pact_broker/api/resources/integration.rb +0 -4
  18. data/lib/pact_broker/api/resources/integrations.rb +0 -4
  19. data/lib/pact_broker/api/resources/label.rb +0 -8
  20. data/lib/pact_broker/api/resources/latest_pact.rb +1 -5
  21. data/lib/pact_broker/api/resources/latest_pacts.rb +1 -5
  22. data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +0 -4
  23. data/lib/pact_broker/api/resources/matrix.rb +4 -0
  24. data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +4 -0
  25. data/lib/pact_broker/api/resources/metrics.rb +4 -0
  26. data/lib/pact_broker/api/resources/pact.rb +4 -8
  27. data/lib/pact_broker/api/resources/pact_content_diff.rb +4 -0
  28. data/lib/pact_broker/api/resources/pact_triggered_webhooks.rb +5 -1
  29. data/lib/pact_broker/api/resources/pact_versions.rb +5 -1
  30. data/lib/pact_broker/api/resources/pact_webhooks.rb +5 -1
  31. data/lib/pact_broker/api/resources/pact_webhooks_status.rb +5 -1
  32. data/lib/pact_broker/api/resources/pacticipant.rb +5 -9
  33. data/lib/pact_broker/api/resources/pacticipants.rb +0 -4
  34. data/lib/pact_broker/api/resources/pacticipants_for_label.rb +4 -0
  35. data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +4 -9
  36. data/lib/pact_broker/api/resources/provider_pacts.rb +1 -5
  37. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +8 -6
  38. data/lib/pact_broker/api/resources/relationships.rb +4 -2
  39. data/lib/pact_broker/api/resources/tag.rb +5 -5
  40. data/lib/pact_broker/api/resources/tagged_pact_versions.rb +5 -2
  41. data/lib/pact_broker/api/resources/triggered_webhook_logs.rb +7 -5
  42. data/lib/pact_broker/api/resources/verification.rb +5 -5
  43. data/lib/pact_broker/api/resources/verification_triggered_webhooks.rb +6 -12
  44. data/lib/pact_broker/api/resources/verifications.rb +5 -5
  45. data/lib/pact_broker/api/resources/version.rb +5 -5
  46. data/lib/pact_broker/api/resources/versions.rb +5 -2
  47. data/lib/pact_broker/api/resources/webhook.rb +4 -0
  48. data/lib/pact_broker/api/resources/webhook_execution.rb +4 -0
  49. data/lib/pact_broker/api/resources/webhooks.rb +5 -1
  50. data/lib/pact_broker/app.rb +1 -1
  51. data/lib/pact_broker/badges/service.rb +1 -1
  52. data/lib/pact_broker/certificates/service.rb +2 -2
  53. data/lib/pact_broker/configuration.rb +21 -1
  54. data/lib/pact_broker/db.rb +14 -0
  55. data/lib/pact_broker/db/table_dependency_calculator.rb +45 -0
  56. data/lib/pact_broker/doc/views/provider-pacts-for-verification.markdown +78 -0
  57. data/lib/pact_broker/domain/pact.rb +9 -0
  58. data/lib/pact_broker/domain/webhook_request.rb +3 -1
  59. data/lib/pact_broker/matrix/deployment_status_summary.rb +1 -1
  60. data/lib/pact_broker/pacts/build_verifiable_pact_notices.rb +7 -4
  61. data/lib/pact_broker/pacts/content.rb +30 -5
  62. data/lib/pact_broker/pacts/repository.rb +25 -31
  63. data/lib/pact_broker/pacts/selector.rb +8 -0
  64. data/lib/pact_broker/test/test_data_builder.rb +1 -1
  65. data/lib/pact_broker/version.rb +1 -1
  66. data/lib/pact_broker/webhooks/job.rb +8 -2
  67. data/lib/pact_broker/webhooks/repository.rb +3 -2
  68. data/lib/pact_broker/webhooks/service.rb +2 -2
  69. data/lib/pact_broker/webhooks/triggered_webhook.rb +1 -3
  70. data/lib/pact_broker/webhooks/webhook_event.rb +1 -2
  71. data/script/seed.rb +39 -17
  72. data/spec/features/get_provider_pacts_for_verification_spec.rb +8 -0
  73. data/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb +23 -4
  74. data/spec/lib/pact_broker/api/decorators/pact_webhooks_status_decorator_spec.rb +2 -1
  75. data/spec/lib/pact_broker/api/decorators/triggered_webhook_decorator_spec.rb +3 -1
  76. data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +15 -0
  77. data/spec/lib/pact_broker/api/resources/default_base_resource_spec.rb +10 -5
  78. data/spec/lib/pact_broker/api/resources/error_handler_spec.rb +18 -1
  79. data/spec/lib/pact_broker/api/resources/provider_pacts_for_verification_spec.rb +1 -1
  80. data/spec/lib/pact_broker/api/resources/verification_triggered_webhooks_spec.rb +0 -1
  81. data/spec/lib/pact_broker/badges/service_spec.rb +1 -1
  82. data/spec/lib/pact_broker/certificates/service_spec.rb +3 -3
  83. data/spec/lib/pact_broker/pacts/content_spec.rb +90 -0
  84. data/spec/lib/pact_broker/pacts/repository_find_for_verification_fallback_spec.rb +14 -0
  85. data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +62 -0
  86. data/spec/lib/pact_broker/webhooks/job_spec.rb +19 -1
  87. data/spec/lib/pact_broker/webhooks/repository_spec.rb +3 -2
  88. data/spec/lib/pact_broker/webhooks/service_spec.rb +2 -2
  89. data/spec/support/database_cleaner.rb +1 -5
  90. data/tasks/database.rb +1 -0
  91. data/tasks/database/table_dependency_calculator.rb +4 -41
  92. metadata +5 -2
@@ -56,6 +56,20 @@ module PactBroker
56
56
  it "sets the latest flag on the selector" do
57
57
  expect(find_by_consumer_version_number("1").selectors.first.latest).to be true
58
58
  end
59
+
60
+ context "when a consumer is specified" do
61
+ before do
62
+ td.create_pact_with_consumer_version_tag("Foo2", "3", "master", "Bar")
63
+ end
64
+
65
+ let(:selector) { Selector.new(tag: tag, fallback_tag: fallback_tag, latest: true, consumer: "Foo") }
66
+
67
+ it "only returns the pacts for the consumer" do
68
+ expect(subject.size).to eq 1
69
+ expect(subject.first.consumer.name).to eq "Foo"
70
+ expect(subject.first.selectors.first).to eq selector
71
+ end
72
+ end
59
73
  end
60
74
 
61
75
  context "when a pact does not exist for either tag or fallback_tag" do
@@ -40,6 +40,68 @@ module PactBroker
40
40
  end
41
41
  end
42
42
 
43
+ context "when the selector is latest: true" do
44
+ let(:pact_selector_1) { Selector.overall_latest }
45
+ let(:consumer_version_selectors) do
46
+ Selectors.new(pact_selector_1)
47
+ end
48
+
49
+ before do
50
+ td.create_pact_with_hierarchy("Foo1", "1", "Bar")
51
+ .create_pact_with_hierarchy("Foo1", "2", "Bar")
52
+ .create_pact_with_hierarchy("Foo2", "3", "Bar")
53
+ .create_pact_with_hierarchy("Foo2", "4", "Bar2")
54
+ end
55
+
56
+ it "returns the latest pact for each consumer" do
57
+ expect(subject.size).to eq 2
58
+ expect(find_by_consumer_name_and_consumer_version_number("Foo1", "2").selectors).to eq [Selector.overall_latest]
59
+ expect(find_by_consumer_name_and_consumer_version_number("Foo2", "3").selectors).to eq [Selector.overall_latest]
60
+ end
61
+ end
62
+
63
+ context "when the selector is latest: true for a particular consumer" do
64
+ let(:pact_selector_1) { Selector.latest_for_consumer("Foo1") }
65
+
66
+ let(:consumer_version_selectors) do
67
+ Selectors.new(pact_selector_1)
68
+ end
69
+
70
+ before do
71
+ td.create_pact_with_hierarchy("Foo1", "1", "Bar")
72
+ .create_pact_with_hierarchy("Foo1", "2", "Bar")
73
+ .create_pact_with_hierarchy("Foo2", "2", "Bar")
74
+ .create_pact_with_hierarchy("Foo2", "2", "Bar2")
75
+ end
76
+
77
+ it "returns the latest pact for each consumer" do
78
+ expect(subject.size).to eq 1
79
+ expect(find_by_consumer_name_and_consumer_version_number("Foo1", "2").selectors).to eq [pact_selector_1]
80
+ end
81
+ end
82
+
83
+ context "when the selector is latest: true, with a tag, for a particular consumer" do
84
+ let(:pact_selector_1) { Selector.latest_for_tag_and_consumer("prod", "Foo1") }
85
+
86
+ let(:consumer_version_selectors) do
87
+ Selectors.new(pact_selector_1)
88
+ end
89
+
90
+ before do
91
+ td.create_pact_with_hierarchy("Foo1", "1", "Bar")
92
+ .create_consumer_version_tag("prod")
93
+ .create_pact_with_hierarchy("Foo1", "2", "Bar")
94
+ .create_pact_with_hierarchy("Foo2", "2", "Bar")
95
+ .create_consumer_version_tag("prod")
96
+ .create_pact_with_hierarchy("Foo2", "2", "Bar2")
97
+ end
98
+
99
+ it "returns the latest pact for each consumer" do
100
+ expect(subject.size).to eq 1
101
+ expect(find_by_consumer_name_and_consumer_version_number("Foo1", "1").selectors).to eq [pact_selector_1]
102
+ end
103
+ end
104
+
43
105
  context "when the latest consumer tag names are specified" do
44
106
  before do
45
107
  td.create_pact_with_hierarchy("Foo", "foo-latest-prod-version", "Bar")
@@ -53,7 +53,25 @@ module PactBroker
53
53
 
54
54
  context "when an error occurs for the first time" do
55
55
  before do
56
- allow(PactBroker::Webhooks::Service).to receive(:execute_triggered_webhook_now).and_raise("an error")
56
+ allow(PactBroker::Webhooks::Service).to receive(:execute_triggered_webhook_now).and_raise(error)
57
+ end
58
+
59
+ let(:error) { "an error" }
60
+
61
+ context "when the error is HTTP related (most likely caused by a problem with the webhook or request itself)" do
62
+ let(:error) { Errno::ECONNREFUSED.new }
63
+
64
+ it "logs a message at info" do
65
+ expect(logger).to receive(:info).with(/Error executing/, error)
66
+ subject
67
+ end
68
+ end
69
+
70
+ context "when the error is not HTTP related (most likely caused by a code, platform or environment issue)" do
71
+ it "logs a message at warn" do
72
+ expect(logger).to receive(:warn).with(/Error executing/, instance_of(RuntimeError))
73
+ subject
74
+ end
57
75
  end
58
76
 
59
77
  it "reschedules the job in 10 seconds" do
@@ -386,7 +386,7 @@ module PactBroker
386
386
  .create_verification
387
387
  end
388
388
 
389
- subject { Repository.new.create_triggered_webhook '1234', td.webhook, td.pact, td.verification, 'publication' }
389
+ subject { Repository.new.create_triggered_webhook '1234', td.webhook, td.pact, td.verification, 'publication', 'some_event' }
390
390
 
391
391
  it "creates a TriggeredWebhook" do
392
392
  expect(subject.webhook_uuid ).to eq td.webhook.uuid
@@ -395,6 +395,7 @@ module PactBroker
395
395
  expect(subject.verification).to eq td.verification
396
396
  expect(subject.trigger_uuid).to eq '1234'
397
397
  expect(subject.trigger_type).to eq 'publication'
398
+ expect(subject.event_name).to eq 'some_event'
398
399
  end
399
400
 
400
401
  it "sets the webhook" do
@@ -418,7 +419,7 @@ module PactBroker
418
419
  end
419
420
 
420
421
  context "without a verification" do
421
- subject { Repository.new.create_triggered_webhook '1234', td.webhook, td.pact, nil, 'publication' }
422
+ subject { Repository.new.create_triggered_webhook '1234', td.webhook, td.pact, nil, 'publication', 'some_event' }
422
423
 
423
424
  it "does not set the verification" do
424
425
  expect(subject.verification).to be nil
@@ -233,8 +233,8 @@ module PactBroker
233
233
  end
234
234
 
235
235
  it "logs the error" do
236
- allow(Service.logger).to receive(:error)
237
- expect(Service.logger).to receive(:error).with(/an error/)
236
+ allow(Service.logger).to receive(:warn)
237
+ expect(Service.logger).to receive(:warn).with(/Error scheduling/, StandardError)
238
238
  subject
239
239
  end
240
240
  end
@@ -8,11 +8,7 @@ RSpec.configure do |config|
8
8
  config.before(:suite) do
9
9
  if defined?(::DB)
10
10
  DatabaseCleaner.strategy = :transaction
11
- if DB.mysql?
12
- DatabaseCleaner.clean_with :deletion
13
- else
14
- DatabaseCleaner.clean_with :truncation
15
- end
11
+ PactBroker::Database.truncate
16
12
  end
17
13
  end
18
14
 
@@ -1,6 +1,7 @@
1
1
  require 'pact_broker/project_root'
2
2
  require 'pact_broker/db/migrate'
3
3
  require 'pact_broker/db/version'
4
+ require 'pact_broker/db'
4
5
  require 'sequel'
5
6
  require 'yaml'
6
7
  require_relative 'database/table_dependency_calculator'
@@ -1,45 +1,8 @@
1
+ require 'pact_broker/db/table_dependency_calculator'
2
+
1
3
  module PactBroker
2
4
  module Database
3
-
4
- # Returns a list of the tables in the database in the order in which
5
- # they can be truncated or dropped
6
- class TableDependencyCalculator
7
-
8
- def self.call connection
9
- new(connection).call
10
- end
11
-
12
- def initialize connection
13
- @connection = connection
14
- end
15
-
16
- def call
17
- ordered_table_names = []
18
- dependencies = @connection
19
- .tables
20
- .collect{|it| @connection.foreign_key_list(it)
21
- .collect{|fk| {from: it, to: fk[:table]} } }
22
- .flatten
23
- .uniq
24
- table_names = @connection.tables - [:schema_migrations, :schema_info]
25
- check(table_names, dependencies, ordered_table_names)
26
- ordered_table_names
27
- end
28
-
29
- def deps_on table_name, deps
30
- deps.select{ | d| d[:to] == table_name }.collect{ |d| d[:from] }
31
- end
32
-
33
- def check table_names, deps, ordered_table_names
34
- return if table_names.size == 0
35
- remaining_dependencies = deps_on(table_names.first, deps) - ordered_table_names
36
- if remaining_dependencies.size == 0
37
- ordered_table_names << table_names.first
38
- check(table_names[1..-1], deps, ordered_table_names)
39
- else
40
- check((remaining_dependencies + table_names).uniq, deps, ordered_table_names)
41
- end
42
- end
43
- end
5
+ # For backwards compatibility
6
+ TableDependencyCalculator = PactBroker::DB::TableDependencyCalculator
44
7
  end
45
8
  end
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.59.1
4
+ version: 2.62.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: 2020-08-04 00:00:00.000000000 Z
13
+ date: 2020-09-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -517,6 +517,7 @@ files:
517
517
  - db/migrations/20191101_create_head_pact_tags.rb
518
518
  - db/migrations/20200318_add_created_at_to_latest_pact_publications.rb
519
519
  - db/migrations/20200319_add_created_at_to_latest_verifications.rb
520
+ - db/migrations/20200922_add_event_to_triggered_webhook.rb
520
521
  - db/migrations/migration_helper.rb
521
522
  - db/test/backwards_compatibility/.rspec
522
523
  - db/test/backwards_compatibility/Appraisals
@@ -722,6 +723,7 @@ files:
722
723
  - lib/pact_broker/db/seed/pact_2.json
723
724
  - lib/pact_broker/db/seed/pact_3.json
724
725
  - lib/pact_broker/db/seed_example_data.rb
726
+ - lib/pact_broker/db/table_dependency_calculator.rb
725
727
  - lib/pact_broker/db/validate_encoding.rb
726
728
  - lib/pact_broker/db/version.rb
727
729
  - lib/pact_broker/diagnostic/app.rb
@@ -760,6 +762,7 @@ files:
760
762
  - lib/pact_broker/doc/views/pact/tag-prod-version.markdown
761
763
  - lib/pact_broker/doc/views/pact/tag-version.markdown
762
764
  - lib/pact_broker/doc/views/pending-provider-pacts.markdown
765
+ - lib/pact_broker/doc/views/provider-pacts-for-verification.markdown
763
766
  - lib/pact_broker/doc/views/provider.markdown
764
767
  - lib/pact_broker/doc/views/version/latest-verification-results-where-pacticipant-is-consumer.markdown
765
768
  - lib/pact_broker/doc/views/webhooks.markdown