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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +12 -0
- data/.github/workflows/release_gem.yml +1 -0
- data/.github/workflows/test-ruby-3.yml +19 -0
- data/.github/workflows/test.yml +16 -7
- data/.gitignore +3 -1
- data/CHANGELOG.md +53 -0
- data/DEVELOPER_DOCUMENTATION.md +13 -0
- data/DEVELOPER_SETUP.md +62 -3
- data/Dockerfile +1 -0
- data/ISSUES.md +7 -7
- data/config.ru +2 -1
- data/db/ddl_statements/head_pact_tags.rb +24 -1
- data/db/ddl_statements/latest_tagged_pact_consumer_version_orders.rb +11 -0
- data/db/ddl_statements/latest_tagged_pact_publications.rb +6 -0
- data/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb +13 -0
- data/db/migrations/20210117_add_branch_to_version.rb +9 -0
- data/db/migrations/20210202_add_created_at_to_head_pact_tags.rb +14 -0
- data/db/migrations/20210205_add_pacticipant_id_to_tag.rb +17 -0
- data/db/migrations/20210206_add_index_to_tags_and_versions.rb +27 -0
- data/db/migrations/20210207_optimise_latest_verification_ids_for_consumer_version_tags.rb +13 -0
- data/db/migrations/20210208_optimise_latest_tagged_pact_cv_orders.rb +13 -0
- data/db/migrations/20210210_create_environments_table.rb +16 -0
- data/docker-compose-dev-postgres.yml +9 -1
- data/lib/pact_broker/api.rb +7 -2
- data/lib/pact_broker/api/contracts/dry_validation_predicates.rb +8 -0
- data/lib/pact_broker/api/contracts/environment_schema.rb +49 -0
- data/lib/pact_broker/api/decorators/base_decorator.rb +11 -0
- data/lib/pact_broker/api/decorators/dashboard_decorator.rb +5 -1
- data/lib/pact_broker/api/decorators/environment_decorator.rb +30 -0
- data/lib/pact_broker/api/decorators/environments_decorator.rb +21 -0
- data/lib/pact_broker/api/decorators/matrix_decorator.rb +3 -1
- data/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator.rb +2 -0
- data/lib/pact_broker/api/decorators/version_decorator.rb +15 -2
- data/lib/pact_broker/api/pact_broker_urls.rb +8 -0
- data/lib/pact_broker/api/resources/default_base_resource.rb +18 -0
- data/lib/pact_broker/api/resources/environment.rb +76 -0
- data/lib/pact_broker/api/resources/environments.rb +75 -0
- data/lib/pact_broker/api/resources/index.rb +20 -0
- data/lib/pact_broker/api/resources/latest_version.rb +27 -0
- data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +1 -0
- data/lib/pact_broker/api/resources/version.rb +15 -9
- data/lib/pact_broker/app.rb +1 -1
- data/lib/pact_broker/certificates/certificate.rb +1 -1
- data/lib/pact_broker/config/setting.rb +1 -1
- data/lib/pact_broker/config/space_delimited_integer_list.rb +25 -0
- data/lib/pact_broker/configuration.rb +22 -1
- data/lib/pact_broker/db/data_migrations/helpers.rb +4 -0
- data/lib/pact_broker/db/data_migrations/set_extra_columns_for_tags.rb +29 -0
- data/lib/pact_broker/db/migrate_data.rb +1 -0
- data/lib/pact_broker/db/seed_example_data.rb +13 -13
- data/lib/pact_broker/deployments/environment.rb +15 -0
- data/lib/pact_broker/deployments/environment_service.rb +39 -0
- data/lib/pact_broker/doc/views/index/environment.markdown +37 -0
- data/lib/pact_broker/doc/views/index/environments.markdown +53 -0
- data/lib/pact_broker/doc/views/index/latest-pact-versions.markdown +1 -1
- data/lib/pact_broker/doc/views/index/pacticipant-version-tag.markdown +1 -0
- data/lib/pact_broker/doc/views/index/pacticipant-version.markdown +13 -0
- data/lib/pact_broker/domain/index_item.rb +18 -4
- data/lib/pact_broker/domain/pacticipant.rb +9 -5
- data/lib/pact_broker/domain/tag.rb +131 -71
- data/lib/pact_broker/domain/verification.rb +3 -2
- data/lib/pact_broker/domain/version.rb +58 -23
- data/lib/pact_broker/domain/webhook.rb +6 -3
- data/lib/pact_broker/index/service.rb +55 -49
- data/lib/pact_broker/locale/en.yml +3 -1
- data/lib/pact_broker/matrix/quick_row.rb +8 -0
- data/lib/pact_broker/metrics/service.rb +1 -1
- data/lib/pact_broker/pacts/eager_loaders.rb +52 -0
- data/lib/pact_broker/pacts/latest_pact_publication_id_for_consumer_version.rb +18 -13
- data/lib/pact_broker/pacts/lazy_loaders.rb +14 -0
- data/lib/pact_broker/pacts/pact_publication.rb +38 -84
- data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +297 -0
- data/lib/pact_broker/pacts/pact_version.rb +1 -2
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +286 -0
- data/lib/pact_broker/pacts/repository.rb +5 -240
- data/lib/pact_broker/pacts/selected_pact.rb +4 -0
- data/lib/pact_broker/pacts/selector.rb +56 -1
- data/lib/pact_broker/pacts/selectors.rb +16 -0
- data/lib/pact_broker/pacts/service.rb +2 -6
- data/lib/pact_broker/pacts/squash_pacts_for_verification.rb +1 -4
- data/lib/pact_broker/pacts/verifiable_pact.rb +23 -2
- data/lib/pact_broker/pacts/verifiable_pact_messages.rb +56 -16
- data/lib/pact_broker/repositories/helpers.rb +4 -0
- data/lib/pact_broker/services.rb +9 -0
- data/lib/pact_broker/tags/eager_loaders.rb +47 -0
- data/lib/pact_broker/tags/repository.rb +3 -1
- data/lib/pact_broker/tags/service.rb +0 -3
- data/lib/pact_broker/tags/tag_with_latest_flag.rb +1 -0
- data/lib/pact_broker/test/http_test_data_builder.rb +23 -7
- data/lib/pact_broker/test/test_data_builder.rb +50 -3
- data/lib/pact_broker/ui/view_models/index_item.rb +19 -2
- data/lib/pact_broker/ui/view_models/matrix_line.rb +38 -2
- data/lib/pact_broker/ui/views/index/show-with-tags.haml +14 -6
- data/lib/pact_broker/ui/views/matrix/show.haml +12 -2
- data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +7 -5
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/eager_loaders.rb +71 -0
- data/lib/pact_broker/versions/lazy_loaders.rb +13 -0
- data/lib/pact_broker/versions/repository.rb +22 -2
- data/lib/pact_broker/versions/service.rb +5 -1
- data/lib/pact_broker/webhooks/execution.rb +3 -2
- data/lib/pact_broker/webhooks/latest_triggered_webhook.rb +2 -0
- data/lib/pact_broker/webhooks/triggered_webhook.rb +11 -4
- data/lib/pact_broker/webhooks/webhook.rb +1 -1
- data/lib/pact_broker/webhooks/webhook_event.rb +1 -1
- data/lib/pact_broker/webhooks/webhook_execution_result.rb +6 -1
- data/lib/pact_broker/webhooks/webhook_request_logger.rb +7 -1
- data/lib/rack/pact_broker/set_base_url.rb +35 -5
- data/lib/sequel/plugins/upsert.rb +18 -4
- data/pact_broker.gemspec +1 -1
- data/public/javascripts/clipboard.js +8 -2
- data/public/stylesheets/index.css +26 -2
- data/public/stylesheets/matrix.css +0 -21
- data/regression/can_i_deploy_spec.rb +5 -4
- data/regression/index_spec.rb +26 -0
- data/regression/regression_helper.rb +29 -3
- data/regression/script/clear.sh +3 -0
- data/regression/script/run.sh +3 -0
- data/script/demonstrate-version-branches.rb +33 -0
- data/script/pry.rb +2 -2
- data/spec/features/create_environment_spec.rb +47 -0
- data/spec/features/create_tag_spec.rb +32 -0
- data/spec/features/create_version_spec.rb +70 -0
- data/spec/features/delete_environment_spec.rb +16 -0
- data/spec/features/end_deployment_spec.rb +29 -0
- data/spec/features/get_environment_spec.rb +19 -0
- data/spec/features/get_environments_spec.rb +20 -0
- data/spec/features/record_deployment_spec.rb +28 -0
- data/spec/features/update_environment_spec.rb +44 -0
- data/spec/fixtures/approvals/modifiable_resources.approved.json +6 -0
- data/spec/fixtures/dashboard.json +4 -2
- data/spec/lib/pact_broker/api/contracts/environment_schema_spec.rb +83 -0
- data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +4 -2
- data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +11 -6
- data/spec/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator_spec.rb +6 -0
- data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +18 -0
- data/spec/lib/pact_broker/api/resources/default_base_resource_approval_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/provider_pacts_for_verification_spec.rb +4 -0
- data/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb +56 -0
- data/spec/lib/pact_broker/config/space_delimited_integer_list_spec.rb +47 -0
- data/spec/lib/pact_broker/configuration_spec.rb +12 -0
- data/spec/lib/pact_broker/domain/tag_spec.rb +101 -27
- data/spec/lib/pact_broker/domain/version_spec.rb +103 -15
- data/spec/lib/pact_broker/domain/webhook_spec.rb +1 -1
- data/spec/lib/pact_broker/index/service_spec.rb +89 -15
- data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +400 -0
- data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +434 -14
- data/spec/lib/pact_broker/pacts/repository_find_for_verification_fallback_spec.rb +1 -1
- data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +1 -1
- data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_branch_spec.rb +224 -0
- data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +20 -7
- data/spec/lib/pact_broker/pacts/selector_spec.rb +3 -2
- data/spec/lib/pact_broker/pacts/service_find_for_verification_spec.rb +2 -3
- data/spec/lib/pact_broker/pacts/service_spec.rb +2 -2
- data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +57 -10
- data/spec/lib/pact_broker/tags/repository_spec.rb +2 -0
- data/spec/lib/pact_broker/versions/repository_spec.rb +54 -0
- data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +8 -0
- data/spec/lib/rack/pact_broker/set_base_url_spec.rb +86 -0
- data/spec/lib/sequel/plugins/upsert_spec.rb +31 -3
- data/spec/migrations/change_migration_strategy_spec.rb +3 -3
- data/spec/service_consumers/hal_relation_proxy_app.rb +3 -1
- data/spec/service_consumers/provider_states_for_pact_broker_client.rb +16 -0
- data/spec/spec_helper.rb +17 -5
- data/spec/support/approvals.rb +24 -0
- data/spec/support/shared_examples_for_responses.rb +11 -0
- data/tasks/database.rb +1 -1
- data/tasks/db.rake +1 -0
- data/tasks/rspec.rake +1 -1
- data/vendor/hal-browser/styles.css +6 -0
- 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}
|
data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb
CHANGED
@@ -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
|
21
|
-
# pact_version_id | integer
|
22
|
-
# provider_id | integer
|
23
|
-
# provider_version_id | integer
|
24
|
-
# verification_id | integer
|
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)
|
data/lib/pact_broker/version.rb
CHANGED
@@ -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).
|
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
|
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
|
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
|
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)
|
@@ -110,7 +110,7 @@ end
|
|
110
110
|
|
111
111
|
# Table: triggered_webhooks
|
112
112
|
# Columns:
|
113
|
-
# id | integer | PRIMARY KEY DEFAULT
|
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
|
127
|
-
# uq_triggered_webhook_ppi_wi
|
128
|
-
# uq_triggered_webhook_wi
|
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
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
4
|
+
X_FORWARDED_PATTERN = /_X_FORWARDED_/.freeze
|
5
|
+
|
6
|
+
def initialize app, base_urls
|
5
7
|
@app = app
|
6
|
-
@
|
8
|
+
@base_urls = base_urls
|
7
9
|
end
|
8
10
|
|
9
|
-
def call
|
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" =>
|
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, :
|
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.
|
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:
|
83
|
+
super.insert_conflict(update: values_to_update, target: self.class.upsert_plugin_identifying_columns)
|
82
84
|
elsif mysql?
|
83
|
-
columns_to_update =
|
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
|
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'
|