pact_broker 2.76.1 → 2.79.0
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 +50 -0
- data/DEVELOPER_DOCUMENTATION.md +13 -0
- data/DEVELOPER_SETUP.md +62 -3
- data/Dockerfile +1 -0
- data/ISSUES.md +12 -4
- 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/docker-compose-issue-repro-with-pact-broker-docker-image.yml +16 -5
- 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/verifications.rb +5 -2
- data/lib/pact_broker/api/resources/version.rb +15 -9
- data/lib/pact_broker/api/resources/webhook_execution.rb +1 -1
- 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 +12 -9
- data/lib/pact_broker/hash_refinements.rb +4 -0
- 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 +6 -8
- 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 +86 -25
- 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/verifications/service.rb +2 -1
- 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/pact_and_verification_parameters.rb +10 -3
- data/lib/pact_broker/webhooks/service.rb +8 -7
- data/lib/pact_broker/webhooks/trigger_service.rb +56 -23
- data/lib/pact_broker/webhooks/triggered_webhook.rb +14 -5
- 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/public/javascripts/clipboard.js +8 -2
- data/public/stylesheets/index.css +22 -1
- 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/script/reproduce-issue-starting-up.rb +13 -23
- data/script/reproduce-issue.rb +2 -1
- data/script/trigger-release.sh +1 -1
- data/script/webhook-server.ru +5 -5
- 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/verifications_spec.rb +2 -5
- data/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb +56 -0
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +3 -2
- 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 +7 -7
- 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 +9 -7
- 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/verifications/service_spec.rb +4 -1
- data/spec/lib/pact_broker/versions/repository_spec.rb +54 -0
- data/spec/lib/pact_broker/webhooks/render_spec.rb +6 -5
- data/spec/lib/pact_broker/webhooks/service_spec.rb +13 -9
- data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +60 -18
- 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/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
- metadata +68 -4
- data/docker-compose-issue-repro.yml +0 -22
@@ -4,6 +4,7 @@ require 'pact_broker/date_helper'
|
|
4
4
|
require 'pact_broker/ui/view_models/matrix_tag'
|
5
5
|
require 'pact_broker/versions/abbreviate_number'
|
6
6
|
require 'pact_broker/messages'
|
7
|
+
require 'forwardable'
|
7
8
|
|
8
9
|
module PactBroker
|
9
10
|
module UI
|
@@ -11,6 +12,9 @@ module PactBroker
|
|
11
12
|
class MatrixLine
|
12
13
|
include PactBroker::Api::PactBrokerUrls
|
13
14
|
include PactBroker::Messages
|
15
|
+
extend Forwardable
|
16
|
+
|
17
|
+
delegate [:consumer_version_branch, :provider_version_branch] => :line
|
14
18
|
|
15
19
|
def initialize line, options = {}
|
16
20
|
@line = line
|
@@ -97,27 +101,47 @@ module PactBroker
|
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
104
|
+
def consumer_version_branch_tooltip
|
105
|
+
branch_tooltip(consumer_name, consumer_version_branch, consumer_version_latest_for_branch?)
|
106
|
+
end
|
107
|
+
|
108
|
+
def consumer_version_latest_for_branch?
|
109
|
+
@line.consumer_version.latest_for_branch?
|
110
|
+
end
|
111
|
+
|
112
|
+
def provider_version_branch_tooltip
|
113
|
+
branch_tooltip(provider_name, provider_version_branch, provider_version_latest_for_branch?)
|
114
|
+
end
|
115
|
+
|
116
|
+
def provider_version_latest_for_branch?
|
117
|
+
@line.provider_version.latest_for_branch?
|
118
|
+
end
|
119
|
+
|
100
120
|
def latest_consumer_version_tags
|
101
121
|
@line.consumer_version_tags
|
102
122
|
.select(&:latest)
|
123
|
+
.sort_by(&:created_at)
|
103
124
|
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: consumer_name, version_number: consumer_version_number)) }
|
104
125
|
end
|
105
126
|
|
106
127
|
def other_consumer_version_tags
|
107
128
|
@line.consumer_version_tags
|
108
129
|
.reject(&:latest)
|
130
|
+
.sort_by(&:created_at)
|
109
131
|
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: consumer_name, version_number: consumer_version_number)) }
|
110
132
|
end
|
111
133
|
|
112
134
|
def latest_provider_version_tags
|
113
135
|
@line.provider_version_tags
|
114
136
|
.select(&:latest)
|
137
|
+
.sort_by(&:created_at)
|
115
138
|
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: provider_name, version_number: provider_version_number)) }
|
116
139
|
end
|
117
140
|
|
118
141
|
def other_provider_version_tags
|
119
142
|
@line.provider_version_tags
|
120
143
|
.reject(&:latest)
|
144
|
+
.sort_by(&:created_at)
|
121
145
|
.collect{ | tag | MatrixTag.new(tag.to_hash.merge(pacticipant_name: provider_name, version_number: provider_version_number)) }
|
122
146
|
end
|
123
147
|
|
@@ -164,8 +188,8 @@ module PactBroker
|
|
164
188
|
|
165
189
|
def verification_status_class
|
166
190
|
case @line.success
|
167
|
-
when true then 'success'
|
168
|
-
when false then 'danger'
|
191
|
+
when true then 'table-success'
|
192
|
+
when false then 'table-danger'
|
169
193
|
else ''
|
170
194
|
end
|
171
195
|
end
|
@@ -187,6 +211,18 @@ module PactBroker
|
|
187
211
|
def base_url
|
188
212
|
@options[:base_url]
|
189
213
|
end
|
214
|
+
|
215
|
+
private
|
216
|
+
|
217
|
+
attr_reader :line
|
218
|
+
|
219
|
+
def branch_tooltip(pacticipant_name, branch, latest)
|
220
|
+
if latest
|
221
|
+
"This is the latest version of #{pacticipant_name} from branch \"#{branch}\"."
|
222
|
+
else
|
223
|
+
"A more recent version of #{pacticipant_name} from branch \"#{branch}\" exists."
|
224
|
+
end
|
225
|
+
end
|
190
226
|
end
|
191
227
|
end
|
192
228
|
end
|
@@ -39,14 +39,18 @@
|
|
39
39
|
%a{:href => index_item.consumer_group_url }
|
40
40
|
= index_item.consumer_name
|
41
41
|
%td.consumer-version-number{"data-text": index_item.consumer_version_order}
|
42
|
-
%div.clippable
|
43
|
-
= index_item.
|
44
|
-
- if index_item.
|
42
|
+
%div.clippable{"data-clippable": index_item.consumer_version_number}
|
43
|
+
= index_item.display_consumer_version_number
|
44
|
+
- if index_item.display_consumer_version_number
|
45
45
|
%button.clippy.invisible{ title: "Copy to clipboard" }
|
46
46
|
%span.copy-icon
|
47
47
|
- if index_item.latest?
|
48
48
|
.tag.badge.badge-success
|
49
49
|
latest
|
50
|
+
- if index_item.consumer_version_branch
|
51
|
+
- branch_class = index_item.latest_for_branch? ? "tag badge badge-dark" : "tag badge badge-secondary"
|
52
|
+
%div{"class": branch_class}
|
53
|
+
= "[" + index_item.consumer_version_branch + "]"
|
50
54
|
- index_item.consumer_version_latest_tag_names.each do | tag_name |
|
51
55
|
.tag.badge.badge-primary
|
52
56
|
= tag_name
|
@@ -59,11 +63,15 @@
|
|
59
63
|
%a{ href: index_item.provider_group_url }
|
60
64
|
= index_item.provider_name
|
61
65
|
%td.provider-version-number
|
62
|
-
%div.clippable
|
63
|
-
= index_item.
|
64
|
-
- if index_item.
|
66
|
+
%div.clippable{"data-clippable": index_item.provider_version_number}
|
67
|
+
= index_item.display_provider_version_number
|
68
|
+
- if index_item.display_provider_version_number
|
65
69
|
%button.clippy.invisible{ title: "Copy to clipboard" }
|
66
70
|
%span.copy-icon
|
71
|
+
- if index_item.provider_version_branch
|
72
|
+
- branch_class = "tag badge badge-dark"
|
73
|
+
%div{"class": branch_class}
|
74
|
+
= "[" + index_item.provider_version_branch + "]"
|
67
75
|
- index_item.provider_version_latest_tag_names.each do | tag_name |
|
68
76
|
.tag.badge.badge-primary
|
69
77
|
= tag_name
|
@@ -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)
|
@@ -20,7 +20,7 @@ module PactBroker
|
|
20
20
|
verification_repository.next_number
|
21
21
|
end
|
22
22
|
|
23
|
-
def create next_verification_number, params, pact, webhook_options
|
23
|
+
def create next_verification_number, params, pact, event_context, webhook_options
|
24
24
|
logger.info "Creating verification #{next_verification_number} for pact_id=#{pact.id}", payload: params.reject{ |k,_| k == "testResults"}
|
25
25
|
verification = PactBroker::Domain::Verification.new
|
26
26
|
provider_version_number = params.fetch('providerApplicationVersion')
|
@@ -35,6 +35,7 @@ module PactBroker
|
|
35
35
|
webhook_trigger_service.trigger_webhooks_for_verification_results_publication(
|
36
36
|
pact,
|
37
37
|
verification,
|
38
|
+
event_context.merge(provider_version_tags: verification.provider_version_tag_names),
|
38
39
|
webhook_options.deep_merge(webhook_execution_configuration: execution_configuration)
|
39
40
|
)
|
40
41
|
verification
|
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)
|
@@ -13,6 +13,7 @@ module PactBroker
|
|
13
13
|
BITBUCKET_VERIFICATION_STATUS = 'pactbroker.bitbucketVerificationStatus'
|
14
14
|
CONSUMER_LABELS = 'pactbroker.consumerLabels'
|
15
15
|
PROVIDER_LABELS = 'pactbroker.providerLabels'
|
16
|
+
EVENT_NAME = 'pactbroker.eventName'
|
16
17
|
|
17
18
|
ALL = [
|
18
19
|
CONSUMER_NAME,
|
@@ -26,7 +27,8 @@ module PactBroker
|
|
26
27
|
GITHUB_VERIFICATION_STATUS,
|
27
28
|
BITBUCKET_VERIFICATION_STATUS,
|
28
29
|
CONSUMER_LABELS,
|
29
|
-
PROVIDER_LABELS
|
30
|
+
PROVIDER_LABELS,
|
31
|
+
EVENT_NAME
|
30
32
|
]
|
31
33
|
|
32
34
|
def initialize(pact, trigger_verification, webhook_context)
|
@@ -49,7 +51,8 @@ module PactBroker
|
|
49
51
|
GITHUB_VERIFICATION_STATUS => github_verification_status,
|
50
52
|
BITBUCKET_VERIFICATION_STATUS => bitbucket_verification_status,
|
51
53
|
CONSUMER_LABELS => pacticipant_labels(pact && pact.consumer),
|
52
|
-
PROVIDER_LABELS => pacticipant_labels(pact && pact.provider)
|
54
|
+
PROVIDER_LABELS => pacticipant_labels(pact && pact.provider),
|
55
|
+
EVENT_NAME => event_name
|
53
56
|
}
|
54
57
|
end
|
55
58
|
|
@@ -116,6 +119,10 @@ module PactBroker
|
|
116
119
|
def pacticipant_labels pacticipant
|
117
120
|
pacticipant && pacticipant.labels ? pacticipant.labels.collect(&:name).join(", ") : ""
|
118
121
|
end
|
122
|
+
|
123
|
+
def event_name
|
124
|
+
webhook_context.fetch(:event_name)
|
125
|
+
end
|
119
126
|
end
|
120
127
|
end
|
121
|
-
end
|
128
|
+
end
|
@@ -87,7 +87,7 @@ module PactBroker
|
|
87
87
|
webhook_repository.find_all
|
88
88
|
end
|
89
89
|
|
90
|
-
def self.test_execution webhook, execution_configuration
|
90
|
+
def self.test_execution webhook, event_context, execution_configuration
|
91
91
|
merged_options = execution_configuration.with_failure_log_message("Webhook execution failed").to_hash
|
92
92
|
|
93
93
|
verification = nil
|
@@ -96,7 +96,7 @@ module PactBroker
|
|
96
96
|
end
|
97
97
|
|
98
98
|
pact = pact_service.search_for_latest_pact(consumer_name: webhook.consumer_name, provider_name: webhook.provider_name) || PactBroker::Pacts::PlaceholderPact.new
|
99
|
-
webhook.execute(pact, verification, merged_options)
|
99
|
+
webhook.execute(pact, verification, event_context.merge(event_name: "test"), merged_options)
|
100
100
|
end
|
101
101
|
|
102
102
|
def self.execute_triggered_webhook_now triggered_webhook, webhook_execution_configuration_hash
|
@@ -121,23 +121,24 @@ module PactBroker
|
|
121
121
|
webhook_repository.find_by_consumer_and_provider consumer, provider
|
122
122
|
end
|
123
123
|
|
124
|
-
def self.trigger_webhooks pact, verification, event_name, options
|
124
|
+
def self.trigger_webhooks pact, verification, event_name, event_context, options
|
125
125
|
webhooks = webhook_repository.find_by_consumer_and_or_provider_and_event_name pact.consumer, pact.provider, event_name
|
126
126
|
|
127
127
|
if webhooks.any?
|
128
128
|
webhook_execution_configuration = options.fetch(:webhook_execution_configuration).with_webhook_context(event_name: event_name)
|
129
|
-
|
129
|
+
# bit messy to merge in base_url here, but easier than a big refactor
|
130
|
+
base_url = options.fetch(:webhook_execution_configuration).webhook_context.fetch(:base_url)
|
131
|
+
run_later(webhooks, pact, verification, event_name, event_context.merge(event_name: event_name, base_url: base_url), options.merge(webhook_execution_configuration: webhook_execution_configuration))
|
130
132
|
else
|
131
133
|
logger.info "No enabled webhooks found for consumer \"#{pact.consumer.name}\" and provider \"#{pact.provider.name}\" and event #{event_name}"
|
132
134
|
end
|
133
135
|
end
|
134
136
|
|
135
|
-
def self.run_later webhooks, pact, verification, event_name, options
|
137
|
+
def self.run_later webhooks, pact, verification, event_name, event_context, options
|
136
138
|
trigger_uuid = next_uuid
|
137
139
|
webhooks.each do | webhook |
|
138
140
|
begin
|
139
|
-
|
140
|
-
triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, webhook, pact, verification, RESOURCE_CREATION, event_name, webhook_context)
|
141
|
+
triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, webhook, pact, verification, RESOURCE_CREATION, event_name, event_context)
|
141
142
|
logger.info "Scheduling job for webhook with uuid #{webhook.uuid}"
|
142
143
|
logger.debug "Schedule webhook with options #{options}"
|
143
144
|
job_data = { triggered_webhook: triggered_webhook }.deep_merge(options)
|