pact_broker 2.76.2 → 2.79.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +12 -0
  3. data/.github/workflows/release_gem.yml +1 -0
  4. data/.github/workflows/test-ruby-3.yml +19 -0
  5. data/.github/workflows/test.yml +16 -7
  6. data/.gitignore +3 -1
  7. data/CHANGELOG.md +53 -0
  8. data/DEVELOPER_DOCUMENTATION.md +13 -0
  9. data/DEVELOPER_SETUP.md +62 -3
  10. data/Dockerfile +1 -0
  11. data/ISSUES.md +7 -7
  12. data/config.ru +2 -1
  13. data/db/ddl_statements/head_pact_tags.rb +24 -1
  14. data/db/ddl_statements/latest_tagged_pact_consumer_version_orders.rb +11 -0
  15. data/db/ddl_statements/latest_tagged_pact_publications.rb +6 -0
  16. data/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb +13 -0
  17. data/db/migrations/20210117_add_branch_to_version.rb +9 -0
  18. data/db/migrations/20210202_add_created_at_to_head_pact_tags.rb +14 -0
  19. data/db/migrations/20210205_add_pacticipant_id_to_tag.rb +17 -0
  20. data/db/migrations/20210206_add_index_to_tags_and_versions.rb +27 -0
  21. data/db/migrations/20210207_optimise_latest_verification_ids_for_consumer_version_tags.rb +13 -0
  22. data/db/migrations/20210208_optimise_latest_tagged_pact_cv_orders.rb +13 -0
  23. data/db/migrations/20210210_create_environments_table.rb +16 -0
  24. data/docker-compose-dev-postgres.yml +9 -1
  25. data/lib/pact_broker/api.rb +7 -2
  26. data/lib/pact_broker/api/contracts/dry_validation_predicates.rb +8 -0
  27. data/lib/pact_broker/api/contracts/environment_schema.rb +49 -0
  28. data/lib/pact_broker/api/decorators/base_decorator.rb +11 -0
  29. data/lib/pact_broker/api/decorators/dashboard_decorator.rb +5 -1
  30. data/lib/pact_broker/api/decorators/environment_decorator.rb +30 -0
  31. data/lib/pact_broker/api/decorators/environments_decorator.rb +21 -0
  32. data/lib/pact_broker/api/decorators/matrix_decorator.rb +3 -1
  33. data/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator.rb +2 -0
  34. data/lib/pact_broker/api/decorators/version_decorator.rb +15 -2
  35. data/lib/pact_broker/api/pact_broker_urls.rb +8 -0
  36. data/lib/pact_broker/api/resources/default_base_resource.rb +18 -0
  37. data/lib/pact_broker/api/resources/environment.rb +76 -0
  38. data/lib/pact_broker/api/resources/environments.rb +75 -0
  39. data/lib/pact_broker/api/resources/index.rb +20 -0
  40. data/lib/pact_broker/api/resources/latest_version.rb +27 -0
  41. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +1 -0
  42. data/lib/pact_broker/api/resources/version.rb +15 -9
  43. data/lib/pact_broker/app.rb +1 -1
  44. data/lib/pact_broker/certificates/certificate.rb +1 -1
  45. data/lib/pact_broker/config/setting.rb +1 -1
  46. data/lib/pact_broker/config/space_delimited_integer_list.rb +25 -0
  47. data/lib/pact_broker/configuration.rb +22 -1
  48. data/lib/pact_broker/db/data_migrations/helpers.rb +4 -0
  49. data/lib/pact_broker/db/data_migrations/set_extra_columns_for_tags.rb +29 -0
  50. data/lib/pact_broker/db/migrate_data.rb +1 -0
  51. data/lib/pact_broker/db/seed_example_data.rb +13 -13
  52. data/lib/pact_broker/deployments/environment.rb +15 -0
  53. data/lib/pact_broker/deployments/environment_service.rb +39 -0
  54. data/lib/pact_broker/doc/views/index/environment.markdown +37 -0
  55. data/lib/pact_broker/doc/views/index/environments.markdown +53 -0
  56. data/lib/pact_broker/doc/views/index/latest-pact-versions.markdown +1 -1
  57. data/lib/pact_broker/doc/views/index/pacticipant-version-tag.markdown +1 -0
  58. data/lib/pact_broker/doc/views/index/pacticipant-version.markdown +13 -0
  59. data/lib/pact_broker/domain/index_item.rb +18 -4
  60. data/lib/pact_broker/domain/pacticipant.rb +9 -5
  61. data/lib/pact_broker/domain/tag.rb +131 -71
  62. data/lib/pact_broker/domain/verification.rb +3 -2
  63. data/lib/pact_broker/domain/version.rb +58 -23
  64. data/lib/pact_broker/domain/webhook.rb +6 -3
  65. data/lib/pact_broker/index/service.rb +55 -49
  66. data/lib/pact_broker/locale/en.yml +3 -1
  67. data/lib/pact_broker/matrix/quick_row.rb +8 -0
  68. data/lib/pact_broker/metrics/service.rb +1 -1
  69. data/lib/pact_broker/pacts/eager_loaders.rb +52 -0
  70. data/lib/pact_broker/pacts/latest_pact_publication_id_for_consumer_version.rb +18 -13
  71. data/lib/pact_broker/pacts/lazy_loaders.rb +14 -0
  72. data/lib/pact_broker/pacts/pact_publication.rb +38 -84
  73. data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +297 -0
  74. data/lib/pact_broker/pacts/pact_version.rb +1 -2
  75. data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +286 -0
  76. data/lib/pact_broker/pacts/repository.rb +5 -240
  77. data/lib/pact_broker/pacts/selected_pact.rb +4 -0
  78. data/lib/pact_broker/pacts/selector.rb +56 -1
  79. data/lib/pact_broker/pacts/selectors.rb +16 -0
  80. data/lib/pact_broker/pacts/service.rb +2 -6
  81. data/lib/pact_broker/pacts/squash_pacts_for_verification.rb +1 -4
  82. data/lib/pact_broker/pacts/verifiable_pact.rb +23 -2
  83. data/lib/pact_broker/pacts/verifiable_pact_messages.rb +56 -16
  84. data/lib/pact_broker/repositories/helpers.rb +4 -0
  85. data/lib/pact_broker/services.rb +9 -0
  86. data/lib/pact_broker/tags/eager_loaders.rb +47 -0
  87. data/lib/pact_broker/tags/repository.rb +3 -1
  88. data/lib/pact_broker/tags/service.rb +0 -3
  89. data/lib/pact_broker/tags/tag_with_latest_flag.rb +1 -0
  90. data/lib/pact_broker/test/http_test_data_builder.rb +23 -7
  91. data/lib/pact_broker/test/test_data_builder.rb +50 -3
  92. data/lib/pact_broker/ui/view_models/index_item.rb +19 -2
  93. data/lib/pact_broker/ui/view_models/matrix_line.rb +38 -2
  94. data/lib/pact_broker/ui/views/index/show-with-tags.haml +14 -6
  95. data/lib/pact_broker/ui/views/matrix/show.haml +12 -2
  96. data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +7 -5
  97. data/lib/pact_broker/version.rb +1 -1
  98. data/lib/pact_broker/versions/eager_loaders.rb +71 -0
  99. data/lib/pact_broker/versions/lazy_loaders.rb +13 -0
  100. data/lib/pact_broker/versions/repository.rb +22 -2
  101. data/lib/pact_broker/versions/service.rb +5 -1
  102. data/lib/pact_broker/webhooks/execution.rb +3 -2
  103. data/lib/pact_broker/webhooks/latest_triggered_webhook.rb +2 -0
  104. data/lib/pact_broker/webhooks/triggered_webhook.rb +11 -4
  105. data/lib/pact_broker/webhooks/webhook.rb +1 -1
  106. data/lib/pact_broker/webhooks/webhook_event.rb +1 -1
  107. data/lib/pact_broker/webhooks/webhook_execution_result.rb +6 -1
  108. data/lib/pact_broker/webhooks/webhook_request_logger.rb +7 -1
  109. data/lib/rack/pact_broker/set_base_url.rb +35 -5
  110. data/lib/sequel/plugins/upsert.rb +18 -4
  111. data/pact_broker.gemspec +1 -1
  112. data/public/javascripts/clipboard.js +8 -2
  113. data/public/stylesheets/index.css +26 -2
  114. data/public/stylesheets/matrix.css +0 -21
  115. data/regression/can_i_deploy_spec.rb +5 -4
  116. data/regression/index_spec.rb +26 -0
  117. data/regression/regression_helper.rb +29 -3
  118. data/regression/script/clear.sh +3 -0
  119. data/regression/script/run.sh +3 -0
  120. data/script/demonstrate-version-branches.rb +33 -0
  121. data/script/pry.rb +2 -2
  122. data/spec/features/create_environment_spec.rb +47 -0
  123. data/spec/features/create_tag_spec.rb +32 -0
  124. data/spec/features/create_version_spec.rb +70 -0
  125. data/spec/features/delete_environment_spec.rb +16 -0
  126. data/spec/features/end_deployment_spec.rb +29 -0
  127. data/spec/features/get_environment_spec.rb +19 -0
  128. data/spec/features/get_environments_spec.rb +20 -0
  129. data/spec/features/record_deployment_spec.rb +28 -0
  130. data/spec/features/update_environment_spec.rb +44 -0
  131. data/spec/fixtures/approvals/modifiable_resources.approved.json +6 -0
  132. data/spec/fixtures/dashboard.json +4 -2
  133. data/spec/lib/pact_broker/api/contracts/environment_schema_spec.rb +83 -0
  134. data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +4 -2
  135. data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +11 -6
  136. data/spec/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator_spec.rb +6 -0
  137. data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +18 -0
  138. data/spec/lib/pact_broker/api/resources/default_base_resource_approval_spec.rb +1 -1
  139. data/spec/lib/pact_broker/api/resources/provider_pacts_for_verification_spec.rb +4 -0
  140. data/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb +56 -0
  141. data/spec/lib/pact_broker/config/space_delimited_integer_list_spec.rb +47 -0
  142. data/spec/lib/pact_broker/configuration_spec.rb +12 -0
  143. data/spec/lib/pact_broker/domain/tag_spec.rb +101 -27
  144. data/spec/lib/pact_broker/domain/version_spec.rb +103 -15
  145. data/spec/lib/pact_broker/domain/webhook_spec.rb +1 -1
  146. data/spec/lib/pact_broker/index/service_spec.rb +89 -15
  147. data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +400 -0
  148. data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +434 -14
  149. data/spec/lib/pact_broker/pacts/repository_find_for_verification_fallback_spec.rb +1 -1
  150. data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +1 -1
  151. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_branch_spec.rb +224 -0
  152. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +20 -7
  153. data/spec/lib/pact_broker/pacts/selector_spec.rb +3 -2
  154. data/spec/lib/pact_broker/pacts/service_find_for_verification_spec.rb +2 -3
  155. data/spec/lib/pact_broker/pacts/service_spec.rb +2 -2
  156. data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +57 -10
  157. data/spec/lib/pact_broker/tags/repository_spec.rb +2 -0
  158. data/spec/lib/pact_broker/versions/repository_spec.rb +54 -0
  159. data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +8 -0
  160. data/spec/lib/rack/pact_broker/set_base_url_spec.rb +86 -0
  161. data/spec/lib/sequel/plugins/upsert_spec.rb +31 -3
  162. data/spec/migrations/change_migration_strategy_spec.rb +3 -3
  163. data/spec/service_consumers/hal_relation_proxy_app.rb +3 -1
  164. data/spec/service_consumers/provider_states_for_pact_broker_client.rb +16 -0
  165. data/spec/spec_helper.rb +17 -5
  166. data/spec/support/approvals.rb +24 -0
  167. data/spec/support/shared_examples_for_responses.rb +11 -0
  168. data/tasks/database.rb +1 -1
  169. data/tasks/db.rake +1 -0
  170. data/tasks/rspec.rake +1 -1
  171. data/vendor/hal-browser/styles.css +6 -0
  172. metadata +70 -11
@@ -112,12 +112,17 @@
112
112
  %a{href: line.consumer_name_url}
113
113
  = line.consumer_name
114
114
  %td.consumer-version{'data-sort-value' => line.consumer_version_order, 'data-consumer-version-id' => line.consumer_version_id}
115
- %div.clippable
115
+ %div.clippable{'data-clippable': line.consumer_version_number}
116
116
  %a{href: line.consumer_version_number_url}
117
117
  = line.display_consumer_version_number
118
118
  - if line.display_consumer_version_number
119
119
  %button.clippy.invisible{ title: "Copy to clipboard" }
120
120
  %span.copy-icon
121
+ - if line.consumer_version_branch
122
+ .tag-parent{"title": line.consumer_version_branch_tooltip, "data-toggle": "tooltip", "data-placement": "right"}
123
+ - branch_class = line.consumer_version_latest_for_branch? ? "tag badge badge-dark" : "tag badge badge-secondary"
124
+ %div{"class": branch_class}
125
+ = "[" + line.consumer_version_branch + "]"
121
126
  - line.latest_consumer_version_tags.each do | tag |
122
127
  .tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
123
128
  %a{href: tag.url}
@@ -139,12 +144,17 @@
139
144
  %a{href: line.provider_name_url}
140
145
  = line.provider_name
141
146
  %td.provider-version{'data-sort-value' => line.provider_version_order, 'data-provider-version-id' => line.provider_version_id }
142
- %div.clippable
147
+ %div.clippable{'data-clippable': line.provider_version_number}
143
148
  %a{href: line.provider_version_number_url}
144
149
  = line.display_provider_version_number
145
150
  - if line.display_provider_version_number
146
151
  %button.clippy.invisible{ title: "Copy to clipboard" }
147
152
  %span.copy-icon
153
+ - if line.provider_version_branch
154
+ .tag-parent{"title": line.provider_version_branch_tooltip, "data-toggle": "tooltip", "data-placement": "right"}
155
+ - branch_class = line.provider_version_latest_for_branch? ? "tag badge badge-dark" : "tag badge badge-secondary"
156
+ %div{"class": branch_class}
157
+ = "[" + line.provider_version_branch + "]"
148
158
  - line.latest_provider_version_tags.each do | tag |
149
159
  .tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
150
160
  %a{href: tag.url}
@@ -16,12 +16,14 @@ module PactBroker
16
16
  end
17
17
 
18
18
  # Table: latest_verification_id_for_pact_version_and_provider_version
19
+ # Primary Key: (pact_version_id, provider_version_id)
19
20
  # Columns:
20
- # consumer_id | integer | NOT NULL
21
- # pact_version_id | integer | NOT NULL
22
- # provider_id | integer | NOT NULL
23
- # provider_version_id | integer | NOT NULL
24
- # verification_id | integer | NOT NULL
21
+ # consumer_id | integer | NOT NULL
22
+ # pact_version_id | integer | NOT NULL
23
+ # provider_id | integer | NOT NULL
24
+ # provider_version_id | integer | NOT NULL
25
+ # verification_id | integer | NOT NULL
26
+ # created_at | timestamp without time zone |
25
27
  # Indexes:
26
28
  # latest_v_id_for_pv_and_pv_pv_id_pv_id_unq | UNIQUE btree (pact_version_id, provider_version_id)
27
29
  # latest_v_id_for_pv_and_pv_v_id_unq | UNIQUE btree (verification_id)
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '2.76.2'
2
+ VERSION = '2.79.1'
3
3
  end
@@ -0,0 +1,71 @@
1
+ module PactBroker
2
+ module Versions
3
+ module EagerLoaders
4
+ class LatestVersionForBranch
5
+ def self.call(eo, **other)
6
+ initialize_association(eo[:rows])
7
+ populate_associations(eo[:rows])
8
+ end
9
+
10
+ def self.initialize_association(versions)
11
+ versions.each{|version| version.associations[:latest_version_for_branch] = nil }
12
+ end
13
+
14
+ def self.populate_associations(versions)
15
+ group_by_pacticipant_id(versions).each do | pacticipant, versions |
16
+ populate_associations_by_pacticipant(pacticipant, versions)
17
+ end
18
+ end
19
+
20
+ def self.group_by_pacticipant_id(versions)
21
+ versions.to_a.group_by(&:pacticipant_id)
22
+ end
23
+
24
+ def self.populate_associations_by_pacticipant(pacticipant_id, versions)
25
+ latest_versions_for_branches = latest_versions_for_pacticipant_branches(
26
+ pacticipant_id,
27
+ versions.collect(&:branch).uniq.compact,
28
+ versions.first.class
29
+ )
30
+ self.populate_versions_with_branches(versions, latest_versions_for_branches)
31
+ end
32
+
33
+ def self.populate_versions_with_branches(versions, latest_versions_for_branches)
34
+ versions.select(&:branch).each do | version |
35
+ version.associations[:latest_version_for_branch] = latest_versions_for_branches[[version.pacticipant_id, version.branch]]
36
+ end
37
+ end
38
+
39
+ def self.latest_versions_for_pacticipant_branches(pacticipant_id, branches, version_class)
40
+ version_class.latest_versions_for_pacticipant_branches(pacticipant_id, branches).each_with_object({}) do | row, hash |
41
+ hash[[row.pacticipant_id, row.branch]] = row
42
+ end
43
+ end
44
+ end
45
+
46
+ class LatestVersionForPacticipant
47
+ def self.call(eo, **other)
48
+ populate_associations(eo[:rows])
49
+ end
50
+
51
+ def self.populate_associations(versions)
52
+ group_by_pacticipant(versions).each do | pacticipant, versions |
53
+ populate_associations_by_pacticipant(pacticipant, versions)
54
+ end
55
+ end
56
+
57
+ def self.group_by_pacticipant(versions)
58
+ versions.to_a.group_by(&:pacticipant)
59
+ end
60
+
61
+ def self.populate_associations_by_pacticipant(pacticipant, versions)
62
+ latest_version = versions.first.class.latest_version_for_pacticipant(pacticipant).single_record
63
+
64
+ versions.each do | version |
65
+ version.associations[:latest_version_for_pacticipant] = latest_version
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,13 @@
1
+ module PactBroker
2
+ module Versions
3
+ module LazyLoaders
4
+ LATEST_VERSION_FOR_BRANCH = lambda {
5
+ self.class
6
+ .where(branch: branch, pacticipant_id: pacticipant_id)
7
+ .exclude(branch: nil)
8
+ .order(Sequel.desc(:order))
9
+ .limit(1)
10
+ }
11
+ end
12
+ end
13
+ end
@@ -9,6 +9,7 @@ module PactBroker
9
9
 
10
10
  include PactBroker::Logging
11
11
  include PactBroker::Repositories::Helpers
12
+ include PactBroker::Repositories
12
13
 
13
14
  def find_by_pacticipant_id_and_number pacticipant_id, number
14
15
  PactBroker::Domain::Version.where(number: number, pacticipant_id: pacticipant_id).single_record
@@ -57,7 +58,26 @@ module PactBroker
57
58
  updated_at: Sequel.datetime_class.now
58
59
  }
59
60
 
60
- PactBroker::Domain::Version.new(version_params).insert_ignore
61
+ PactBroker::Domain::Version.new(version_params).upsert
62
+ end
63
+
64
+ def create_or_overwrite(pacticipant, version_number, open_struct_version)
65
+ saved_version = PactBroker::Domain::Version.new(
66
+ number: version_number,
67
+ pacticipant: pacticipant,
68
+ build_url: open_struct_version.build_url,
69
+ branch: open_struct_version.branch
70
+ ).upsert
71
+
72
+ if open_struct_version.tags
73
+ tag_repository.delete_by_version_id(saved_version.id)
74
+ open_struct_version.tags.collect do | open_struct_tag |
75
+ tag_repository.create(version: saved_version, name: open_struct_tag.name)
76
+ end
77
+ saved_version.refresh
78
+ end
79
+
80
+ saved_version
61
81
  end
62
82
 
63
83
  def find_by_pacticipant_id_and_number_or_create pacticipant_id, number
@@ -79,7 +99,7 @@ module PactBroker
79
99
  version_ids_to_keep = (version_ids_with_pact_publications + version_ids_with_verifications).uniq
80
100
 
81
101
  PactBroker::Domain::Version
82
- .where(pacticipant_id: [consumer.id, provider.id])
102
+ .where(Sequel[:versions][:pacticipant_id] => [consumer.id, provider.id])
83
103
  .exclude(id: (version_ids_with_pact_publications + version_ids_with_verifications).uniq)
84
104
  .delete
85
105
  end
@@ -1,7 +1,6 @@
1
1
  require 'pact_broker/repositories'
2
2
 
3
3
  module PactBroker
4
-
5
4
  module Versions
6
5
  class Service
7
6
 
@@ -19,6 +18,11 @@ module PactBroker
19
18
  version_repository.find_by_pacticipant_name_and_latest_tag(pacticipant_name, tag)
20
19
  end
21
20
 
21
+ def self.create_or_overwrite(pacticipant_name, version_number, version)
22
+ pacticipant = pacticipant_repository.find_by_name_or_create(pacticipant_name)
23
+ version_repository.create_or_overwrite(pacticipant, version_number, version)
24
+ end
25
+
22
26
  def self.delete version
23
27
  tag_repository.delete_by_version_id version.id
24
28
  webhook_repository.delete_triggered_webhooks_by_version_id version.id
@@ -32,13 +32,14 @@ end
32
32
 
33
33
  # Table: webhook_executions
34
34
  # Columns:
35
- # id | integer | PRIMARY KEY DEFAULT nextval('webhook_executions_id_seq'::regclass)
35
+ # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
36
36
  # triggered_webhook_id | integer |
37
37
  # success | boolean | NOT NULL
38
38
  # logs | text |
39
39
  # created_at | timestamp without time zone | NOT NULL
40
40
  # Indexes:
41
- # webhook_executions_pkey | PRIMARY KEY btree (id)
41
+ # webhook_executions_pkey | PRIMARY KEY btree (id)
42
+ # webhook_executions_triggered_webhook_id_index | btree (triggered_webhook_id)
42
43
  # Foreign key constraints:
43
44
  # webhook_executions_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id)
44
45
  # webhook_executions_pact_publication_id_fkey | (pact_publication_id) REFERENCES pact_publications(id)
@@ -21,3 +21,5 @@ end
21
21
  # status | text |
22
22
  # created_at | timestamp without time zone |
23
23
  # updated_at | timestamp without time zone |
24
+ # verification_id | integer |
25
+ # event_name | text |
@@ -110,7 +110,7 @@ end
110
110
 
111
111
  # Table: triggered_webhooks
112
112
  # Columns:
113
- # id | integer | PRIMARY KEY DEFAULT nextval('triggered_webhooks_id_seq'::regclass)
113
+ # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
114
114
  # trigger_uuid | text | NOT NULL
115
115
  # trigger_type | text | NOT NULL
116
116
  # pact_publication_id | integer | NOT NULL
@@ -122,10 +122,17 @@ end
122
122
  # created_at | timestamp without time zone | NOT NULL
123
123
  # updated_at | timestamp without time zone | NOT NULL
124
124
  # verification_id | integer |
125
+ # event_name | text |
126
+ # event_context | text |
125
127
  # Indexes:
126
- # triggered_webhooks_pkey | PRIMARY KEY btree (id)
127
- # uq_triggered_webhook_ppi_wi | UNIQUE btree (pact_publication_id, webhook_id, trigger_uuid)
128
- # uq_triggered_webhook_wi | UNIQUE btree (webhook_id, trigger_uuid)
128
+ # triggered_webhooks_pkey | PRIMARY KEY btree (id)
129
+ # uq_triggered_webhook_ppi_wi | UNIQUE btree (pact_publication_id, webhook_id, trigger_uuid)
130
+ # uq_triggered_webhook_wi | UNIQUE btree (webhook_id, trigger_uuid)
131
+ # triggered_webhooks_consumer_id_index | btree (consumer_id)
132
+ # triggered_webhooks_pact_publication_id_index | btree (pact_publication_id)
133
+ # triggered_webhooks_provider_id_index | btree (provider_id)
134
+ # triggered_webhooks_verification_id_index | btree (verification_id)
135
+ # triggered_webhooks_webhook_id_index | btree (webhook_id)
129
136
  # Foreign key constraints:
130
137
  # triggered_webhooks_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id)
131
138
  # triggered_webhooks_pact_publication_id_fkey | (pact_publication_id) REFERENCES pact_publications(id)
@@ -94,7 +94,7 @@ end
94
94
 
95
95
  # Table: webhooks
96
96
  # Columns:
97
- # id | integer | PRIMARY KEY DEFAULT nextval('webhooks_id_seq'::regclass)
97
+ # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
98
98
  # uuid | text | NOT NULL
99
99
  # method | text | NOT NULL
100
100
  # url | text | NOT NULL
@@ -44,7 +44,7 @@ end
44
44
 
45
45
  # Table: webhook_events
46
46
  # Columns:
47
- # id | integer | PRIMARY KEY DEFAULT nextval('webhook_events_id_seq'::regclass)
47
+ # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
48
48
  # webhook_id | integer |
49
49
  # name | text |
50
50
  # created_at | timestamp without time zone | NOT NULL
@@ -14,7 +14,12 @@ module PactBroker
14
14
  end
15
15
 
16
16
  def success?
17
- !response.nil? && response.code.to_i < 300
17
+ if response
18
+ # Response HTTP Code must be in success list otherwise it is false
19
+ PactBroker.configuration.webhook_http_code_success.include? response.code.to_i
20
+ else
21
+ false
22
+ end
18
23
  end
19
24
  end
20
25
  end
@@ -117,8 +117,14 @@ module PactBroker
117
117
  end
118
118
 
119
119
  def success?(response)
120
- !response.nil? && response.code.to_i < 300
120
+ if response
121
+ # Response HTTP Code must be in success list otherwise it is false
122
+ PactBroker.configuration.webhook_http_code_success.include? response.code.to_i
123
+ else
124
+ false
125
+ end
121
126
  end
127
+
122
128
  end
123
129
  end
124
130
  end
@@ -1,22 +1,52 @@
1
1
  module Rack
2
2
  module PactBroker
3
3
  class SetBaseUrl
4
- def initialize app, base_url
4
+ X_FORWARDED_PATTERN = /_X_FORWARDED_/.freeze
5
+
6
+ def initialize app, base_urls
5
7
  @app = app
6
- @base_url = base_url
8
+ @base_urls = base_urls
7
9
  end
8
10
 
9
- def call env
11
+ def call(env)
10
12
  if env["pactbroker.base_url"]
11
13
  app.call(env)
12
14
  else
13
- app.call(env.merge("pactbroker.base_url" => base_url))
15
+ app.call(env.merge("pactbroker.base_url" => select_matching_base_url(env)))
14
16
  end
15
17
  end
16
18
 
17
19
  private
18
20
 
19
- attr_reader :app, :base_url
21
+ attr_reader :app, :base_urls
22
+
23
+ def select_matching_base_url(env)
24
+ if base_urls.size > 1
25
+ return matching_base_url_considering_x_forwarded_headers(env) ||
26
+ matching_base_url_not_considering_x_forwarded_headers(env) ||
27
+ default_base_url
28
+ end
29
+ default_base_url
30
+ end
31
+
32
+ def default_base_url
33
+ base_urls.first
34
+ end
35
+
36
+ def matching_base_url_considering_x_forwarded_headers(env)
37
+ matching_base_url(env)
38
+ end
39
+
40
+ def matching_base_url_not_considering_x_forwarded_headers(env)
41
+ matching_base_url(env.reject{ |k, _| k =~ X_FORWARDED_PATTERN} )
42
+ end
43
+
44
+ def matching_base_url(env)
45
+ request_base_url = Rack::Request.new(env).base_url
46
+ if base_urls.include?(request_base_url)
47
+ request_base_url
48
+ end
49
+ end
20
50
  end
21
51
  end
22
52
  end
@@ -5,11 +5,12 @@ module Sequel
5
5
  def self.configure(model, opts=OPTS)
6
6
  model.instance_exec do
7
7
  @upsert_plugin_identifying_columns = opts.fetch(:identifying_columns)
8
+ @upsert_plugin_ignore_columns_on_update = opts[:ignore_columns_on_update]
8
9
  end
9
10
  end
10
11
 
11
12
  module ClassMethods
12
- attr_reader :upsert_plugin_identifying_columns
13
+ attr_reader :upsert_plugin_identifying_columns, :upsert_plugin_ignore_columns_on_update
13
14
  end
14
15
 
15
16
  module InstanceMethods
@@ -67,7 +68,8 @@ module Sequel
67
68
  query = values.select{ |k, _| self.class.upsert_plugin_identifying_columns.include?(k) }
68
69
  existing_record = model.where(query).single_record
69
70
  if existing_record
70
- existing_record.update(values)
71
+ existing_record.set(values_to_update)
72
+ existing_record.save(opts)
71
73
  else
72
74
  save(opts)
73
75
  end
@@ -78,9 +80,9 @@ module Sequel
78
80
  def _insert_dataset
79
81
  if upsert_plugin_upserting
80
82
  if postgres?
81
- super.insert_conflict(update: values, target: self.class.upsert_plugin_identifying_columns)
83
+ super.insert_conflict(update: values_to_update, target: self.class.upsert_plugin_identifying_columns)
82
84
  elsif mysql?
83
- columns_to_update = values.keys - self.class.upsert_plugin_identifying_columns
85
+ columns_to_update = values_to_update.keys - self.class.upsert_plugin_identifying_columns
84
86
  super.on_duplicate_key_update(*columns_to_update)
85
87
  else
86
88
  super
@@ -97,6 +99,18 @@ module Sequel
97
99
  def postgres?
98
100
  model.db.adapter_scheme.to_s == "postgres"
99
101
  end
102
+
103
+ def values_to_update
104
+ columns_with_nil_values.merge(values).reject{ |k, _| columns_to_not_update_when_exists.include?(k) }
105
+ end
106
+
107
+ def columns_with_nil_values
108
+ self.class.columns.each_with_object({}) {|key, hash| hash[key] = nil }
109
+ end
110
+
111
+ def columns_to_not_update_when_exists
112
+ @columns_to_not_update ||= self.class.upsert_plugin_ignore_columns_on_update || (self.class.upsert_plugin_identifying_columns + [:created_at, self.class.primary_key]).flatten
113
+ end
100
114
  end
101
115
  end
102
116
  end
data/pact_broker.gemspec CHANGED
@@ -46,7 +46,7 @@ Gem::Specification.new do |gem|
46
46
  gem.add_runtime_dependency 'httparty', '~> 0.14'
47
47
  gem.add_runtime_dependency 'json', '~> 2.3'
48
48
  gem.add_runtime_dependency 'roar', '~> 1.1'
49
- gem.add_runtime_dependency 'reform', '~> 2.3','>= 2.3.1'
49
+ gem.add_runtime_dependency 'reform', '~> 2.3.3'
50
50
  gem.add_runtime_dependency 'dry-validation', '~> 0.10.5'
51
51
  gem.add_runtime_dependency 'sequel', '~> 5.28'
52
52
  gem.add_runtime_dependency 'webmachine', '1.5.0'