pact_broker 2.82.0 → 2.85.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +53 -0
- data/Dockerfile +1 -1
- data/db/migrations/20210815_add_provider_version_id_index_to_verifications.rb +7 -0
- data/db/migrations/20210816_create_branches_tables.rb +40 -0
- data/db/migrations/20210818_add_consumer_version_selectors_to_verification.rb +8 -0
- data/db/migrations/20210831_add_index_to_pact_publications.rb +7 -0
- data/db/migrations/20210908_add_auto_created.rb +24 -0
- data/db/migrations/20210913_add_pending_to_verifications.rb +7 -0
- data/issue-reproduction/Dockerfile-pact-broker +1 -1
- data/lib/pact/doc/markdown/consumer_contract_renderer.rb +3 -3
- data/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema.rb → pacts_for_verification_json_query_schema.rb} +1 -1
- data/lib/pact_broker/api/contracts/{verifiable_pacts_query_schema.rb → pacts_for_verification_query_string_schema.rb} +1 -1
- data/lib/pact_broker/api/decorators/branch_version_decorator.rb +20 -0
- data/lib/pact_broker/api/decorators/dashboard_decorator.rb +4 -2
- data/lib/pact_broker/api/decorators/embedded_branch_version_decorator.rb +21 -0
- data/lib/pact_broker/api/decorators/embedded_tag_decorator.rb +0 -5
- data/lib/pact_broker/api/decorators/matrix_decorator.rb +11 -2
- data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +8 -0
- data/lib/pact_broker/api/decorators/{verifiable_pacts_query_decorator.rb → pacts_for_verification_query_decorator.rb} +2 -2
- data/lib/pact_broker/api/decorators/reason_decorator.rb +2 -2
- data/lib/pact_broker/api/decorators/verification_summary_decorator.rb +1 -2
- data/lib/pact_broker/api/decorators/version_decorator.rb +1 -1
- data/lib/pact_broker/api/middleware/configuration.rb +33 -0
- data/lib/pact_broker/api/pact_broker_urls.rb +13 -1
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +15 -11
- data/lib/pact_broker/api/resources/branch_version.rb +48 -0
- data/lib/pact_broker/api/resources/index.rb +6 -0
- data/lib/pact_broker/api/resources/pact_versions_for_branch.rb +40 -0
- data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +6 -6
- data/lib/pact_broker/api/resources/verifications.rb +7 -2
- data/lib/pact_broker/api/resources/version.rb +0 -8
- data/lib/pact_broker/api.rb +2 -0
- data/lib/pact_broker/app.rb +2 -0
- data/lib/pact_broker/badges/service.rb +3 -1
- data/lib/pact_broker/config/runtime_configuration.rb +12 -0
- data/lib/pact_broker/configuration.rb +33 -29
- data/lib/pact_broker/contracts/service.rb +1 -1
- data/lib/pact_broker/db/clean/selector.rb +54 -0
- data/lib/pact_broker/db/clean.rb +7 -1
- data/lib/pact_broker/db/clean_incremental.rb +13 -5
- data/lib/pact_broker/db/data_migrations/create_branches.rb +97 -0
- data/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch.rb +2 -0
- data/lib/pact_broker/db/migrate_data.rb +1 -1
- data/lib/pact_broker/db/models.rb +6 -0
- data/lib/pact_broker/deployments/deployed_version.rb +4 -0
- data/lib/pact_broker/deployments/deployed_version_service.rb +4 -3
- data/lib/pact_broker/deployments/environment.rb +4 -0
- data/lib/pact_broker/deployments/environment_service.rb +13 -8
- data/lib/pact_broker/diagnostic/resources/base_resource.rb +4 -0
- data/lib/pact_broker/diagnostic/resources/dependencies.rb +1 -1
- data/lib/pact_broker/diagnostic/resources/heartbeat.rb +2 -3
- data/lib/pact_broker/doc/views/index/pacticipant-branch-version.markdown +14 -0
- data/lib/pact_broker/doc/views/webhooks.markdown +1 -0
- data/lib/pact_broker/domain/index_item.rb +15 -17
- data/lib/pact_broker/domain/pacticipant.rb +11 -0
- data/lib/pact_broker/domain/tag.rb +1 -2
- data/lib/pact_broker/domain/verification.rb +29 -14
- data/lib/pact_broker/domain/version.rb +112 -29
- data/lib/pact_broker/domain/webhook.rb +22 -10
- data/lib/pact_broker/domain/webhook_request.rb +2 -2
- data/lib/pact_broker/index/service.rb +83 -28
- data/lib/pact_broker/locale/en.yml +4 -0
- data/lib/pact_broker/matrix/quick_row.rb +6 -6
- data/lib/pact_broker/matrix/service.rb +4 -0
- data/lib/pact_broker/matrix/unresolved_selector.rb +3 -2
- data/lib/pact_broker/metrics/service.rb +7 -1
- data/lib/pact_broker/pacts/metadata.rb +7 -2
- data/lib/pact_broker/pacts/pact_publication.rb +59 -25
- data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +113 -33
- data/lib/pact_broker/pacts/pact_publication_selector_dataset_module.rb +18 -13
- data/lib/pact_broker/pacts/pact_publication_wip_dataset_module.rb +16 -4
- data/lib/pact_broker/pacts/pact_version.rb +13 -1
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +4 -10
- data/lib/pact_broker/pacts/repository.rb +6 -1
- data/lib/pact_broker/pacts/selected_pact.rb +20 -0
- data/lib/pact_broker/pacts/selector.rb +98 -33
- data/lib/pact_broker/pacts/service.rb +21 -0
- data/lib/pact_broker/repositories.rb +5 -0
- data/lib/pact_broker/services.rb +9 -0
- data/lib/pact_broker/test/http_test_data_builder.rb +35 -9
- data/lib/pact_broker/test/test_data_builder.rb +32 -26
- data/lib/pact_broker/ui/app.rb +7 -1
- data/lib/pact_broker/ui/controllers/dashboard.rb +80 -0
- data/lib/pact_broker/ui/controllers/groups.rb +23 -8
- data/lib/pact_broker/ui/helpers/url_helper.rb +5 -1
- data/lib/pact_broker/ui/view_models/index_item.rb +56 -3
- data/lib/pact_broker/ui/view_models/matrix_branch.rb +39 -0
- data/lib/pact_broker/ui/view_models/matrix_line.rb +11 -16
- data/lib/pact_broker/ui/view_models/matrix_tag.rb +0 -1
- data/lib/pact_broker/ui/views/dashboard/show.haml +195 -0
- data/lib/pact_broker/ui/views/groups/show.html.erb +60 -14
- data/lib/pact_broker/ui/views/index/_dashboard_navbar.haml +7 -0
- data/lib/pact_broker/ui/views/index/_navbar.haml +0 -7
- data/lib/pact_broker/ui/views/index/show-with-tags.haml +14 -11
- data/lib/pact_broker/ui/views/index/show.haml +35 -13
- data/lib/pact_broker/ui/views/matrix/show.haml +15 -11
- data/lib/pact_broker/verifications/pseudo_branch_status.rb +2 -0
- data/lib/pact_broker/verifications/repository.rb +6 -11
- data/lib/pact_broker/verifications/service.rb +11 -5
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/branch.rb +29 -0
- data/lib/pact_broker/versions/branch_head.rb +45 -0
- data/lib/pact_broker/versions/branch_service.rb +24 -0
- data/lib/pact_broker/versions/branch_version.rb +64 -0
- data/lib/pact_broker/versions/branch_version_repository.rb +34 -0
- data/lib/pact_broker/versions/eager_loaders.rb +0 -42
- data/lib/pact_broker/versions/repository.rb +25 -12
- data/lib/pact_broker/versions/service.rb +3 -22
- data/lib/pact_broker/webhooks/event_listener.rb +3 -3
- data/lib/pact_broker/webhooks/execution_configuration.rb +16 -0
- data/lib/pact_broker/webhooks/execution_configuration_creator.rb +3 -0
- data/lib/pact_broker/webhooks/job.rb +1 -1
- data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +20 -3
- data/lib/pact_broker/webhooks/trigger_service.rb +2 -2
- data/lib/pact_broker/webhooks/webhook_execution_result.rb +3 -7
- data/lib/pact_broker/webhooks/webhook_request_logger.rb +4 -12
- data/lib/pact_broker/webhooks/webhook_request_template.rb +6 -8
- data/lib/sequel/plugins/insert_ignore.rb +4 -0
- data/lib/sequel/plugins/upsert.rb +4 -0
- data/pact_broker.gemspec +4 -0
- data/public/javascripts/index.js +152 -50
- data/public/javascripts/pact.js +14 -14
- data/public/stylesheets/index.css +1 -2
- data/public/stylesheets/pact.css +11 -0
- data/scaffolding/templates/decorator.rb.erb +3 -1
- data/scaffolding/templates/migration.erb +1 -1
- data/scaffolding/templates/model.erb +2 -2
- data/scaffolding/templates/repository.rb.erb +2 -2
- data/scaffolding/templates/repository_spec.rb.erb +1 -1
- data/scaffolding/templates/resource.erb +2 -2
- data/scaffolding/templates/resource_spec.rb.erb +1 -1
- data/scaffolding/templates/service.rb.erb +3 -3
- data/scaffolding/templates/service_spec.rb.erb +1 -1
- data/script/data/auto-create-things-for-tags.rb +2 -0
- data/script/data/branches.rb +35 -0
- data/script/data/contract-published-requiring-verification.rb +1 -1
- data/script/data/environments.rb +0 -0
- data/script/data/issue-494.rb +25 -0
- data/script/data/pending.rb +26 -0
- data/script/data/tags.rb +35 -0
- data/script/data/webhook.rb +22 -0
- data/script/seed.rb +50 -89
- data/spec/features/create_branch_version_spec.rb +29 -0
- data/spec/features/create_tag_spec.rb +1 -1
- data/spec/features/create_version_spec.rb +2 -4
- data/spec/features/delete_pact_versions_for_branch_spec.rb +34 -0
- data/spec/features/get_branch_version_spec.rb +12 -0
- data/spec/features/publish_pact_all_in_one_spec.rb +0 -1
- data/spec/features/update_version_spec.rb +0 -55
- data/spec/fixtures/approvals/modifiable_resources.approved.json +7 -0
- data/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json +1 -2
- data/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json +1 -2
- data/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json +1 -2
- data/spec/fixtures/dashboard.json +4 -2
- data/spec/integration/app_spec.rb +6 -6
- data/spec/integration/ui/index_spec.rb +0 -2
- data/spec/integration/ui/matrix_spec.rb +0 -1
- data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +2 -2
- data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema_combinations_spec.rb → pacts_for_verification_json_query_schema_combinations_spec.rb} +6 -6
- data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema_spec.rb → pacts_for_verification_json_query_schema_spec.rb} +3 -3
- data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_query_schema_spec.rb → pacts_for_verification_query_string_schema_spec.rb} +3 -3
- data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +7 -7
- data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +19 -4
- data/spec/lib/pact_broker/api/decorators/{verifiable_pacts_query_decorator_spec.rb → pacts_for_verification_query_decorator_spec.rb} +3 -3
- data/spec/lib/pact_broker/api/decorators/reason_decorator_spec.rb +2 -2
- data/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb +2 -0
- data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +7 -3
- data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +1 -1
- data/spec/lib/pact_broker/api/middleware/configuration_spec.rb +43 -0
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +6 -4
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +1 -1
- data/spec/lib/pact_broker/badges/service_spec.rb +22 -0
- data/spec/lib/pact_broker/contracts/service_spec.rb +24 -3
- data/spec/lib/pact_broker/db/clean_spec.rb +2 -2
- data/spec/lib/pact_broker/db/data_migrations/create_branches_spec.rb +57 -0
- data/spec/lib/pact_broker/diagnostic/resources/dependencies_spec.rb +4 -4
- data/spec/lib/pact_broker/diagnostic/resources/heartbeat_spec.rb +3 -4
- data/spec/lib/pact_broker/domain/index_item_spec.rb +1 -1
- data/spec/lib/pact_broker/domain/version_spec.rb +127 -36
- data/spec/lib/pact_broker/domain/webhook_request_spec.rb +2 -1
- data/spec/lib/pact_broker/domain/webhook_spec.rb +15 -5
- data/spec/lib/pact_broker/index/service_spec.rb +1 -5
- data/spec/lib/pact_broker/index/service_view_spec.rb +144 -0
- data/spec/lib/pact_broker/matrix/service_spec.rb +10 -1
- data/spec/lib/pact_broker/metrics/service_spec.rb +4 -1
- data/spec/lib/pact_broker/pacts/metadata_spec.rb +11 -3
- data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +109 -10
- data/spec/lib/pact_broker/pacts/pact_publication_latest_verification_spec.rb +29 -0
- data/spec/lib/pact_broker/pacts/pact_publication_selector_dataset_module_spec.rb +3 -2
- data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +5 -5
- data/spec/lib/pact_broker/pacts/repository_find_for_currently_deployed_spec.rb +2 -2
- data/spec/lib/pact_broker/pacts/repository_find_for_currently_supported_releases_spec.rb +2 -2
- data/spec/lib/pact_broker/pacts/repository_spec.rb +15 -2
- data/spec/lib/pact_broker/pacts/selector_spec.rb +45 -3
- data/spec/lib/pact_broker/pacts/service_spec.rb +61 -0
- data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +5 -5
- data/spec/lib/pact_broker/relationships/groupify_spec.rb +0 -5
- data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +21 -6
- data/spec/lib/pact_broker/verifications/pseudo_branch_status_spec.rb +9 -1
- data/spec/lib/pact_broker/verifications/repository_spec.rb +39 -30
- data/spec/lib/pact_broker/verifications/service_spec.rb +9 -5
- data/spec/lib/pact_broker/versions/branch_service_spec.rb +71 -0
- data/spec/lib/pact_broker/versions/branch_version_repository_spec.rb +81 -0
- data/spec/lib/pact_broker/versions/branch_version_spec.rb +27 -0
- data/spec/lib/pact_broker/versions/repository_spec.rb +91 -6
- data/spec/lib/pact_broker/versions/service_spec.rb +4 -3
- data/spec/lib/pact_broker/webhooks/job_spec.rb +4 -4
- data/spec/lib/pact_broker/webhooks/render_spec.rb +6 -0
- data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +9 -5
- data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +6 -12
- data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +3 -2
- data/spec/lib/sequel/plugins/upsert_spec.rb +11 -5
- data/spec/migrations/44_add_provider_version_to_verification_spec.rb +6 -9
- data/spec/service_consumers/pact_helper.rb +2 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/generated_markdown.md +3 -3
- metadata +90 -17
- data/lib/pact_broker/versions/lazy_loaders.rb +0 -13
- data/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb +0 -56
@@ -115,6 +115,10 @@ module PactBroker
|
|
115
115
|
"#{base_url}/pacts/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}/tag/#{url_encode(tag)}"
|
116
116
|
end
|
117
117
|
|
118
|
+
def pact_versions_for_branch_url consumer_name, provider_name, branch_name, base_url = ""
|
119
|
+
"#{base_url}/pacts/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}/branch/#{url_encode(branch_name)}"
|
120
|
+
end
|
121
|
+
|
118
122
|
def integration_url consumer_name, provider_name, base_url = ""
|
119
123
|
"#{base_url}/integrations/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}"
|
120
124
|
end
|
@@ -199,10 +203,18 @@ module PactBroker
|
|
199
203
|
"#{tags_url(base_url, tag.version)}/#{url_encode(tag.name)}"
|
200
204
|
end
|
201
205
|
|
206
|
+
def branch_version_url(branch_version, base_url = "")
|
207
|
+
"#{pacticipant_url(base_url, branch_version.pacticipant)}/branches/#{url_encode(branch_version.branch_name)}/versions/#{url_encode(branch_version.version_number)}"
|
208
|
+
end
|
209
|
+
|
202
210
|
def templated_tag_url_for_pacticipant pacticipant_name, base_url = ""
|
203
211
|
pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/versions/{version}/tags/{tag}"
|
204
212
|
end
|
205
213
|
|
214
|
+
def templated_branch_version_url_for_pacticipant pacticipant_name, base_url = ""
|
215
|
+
pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/branches/{branch}/versions/{version}"
|
216
|
+
end
|
217
|
+
|
206
218
|
def templated_version_url_for_pacticipant pacticipant_name, base_url = ""
|
207
219
|
pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/versions/{version}"
|
208
220
|
end
|
@@ -303,7 +315,7 @@ module PactBroker
|
|
303
315
|
end
|
304
316
|
|
305
317
|
def group_url(pacticipant_name, base_url = "")
|
306
|
-
"#{base_url}/
|
318
|
+
"#{base_url}/pacticipants/#{url_encode(pacticipant_name)}"
|
307
319
|
end
|
308
320
|
|
309
321
|
def environments_url(base_url = "")
|
@@ -29,7 +29,7 @@ module PactBroker
|
|
29
29
|
"<html>
|
30
30
|
<head>#{head}</head>
|
31
31
|
<body>
|
32
|
-
#{pact_metadata}#{html}
|
32
|
+
#{breadcrumbs}#{pact_metadata}#{html}
|
33
33
|
</body>
|
34
34
|
</html>"
|
35
35
|
end
|
@@ -39,10 +39,10 @@ module PactBroker
|
|
39
39
|
def head
|
40
40
|
"<title>#{title}</title>
|
41
41
|
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/github.css'>
|
42
|
-
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/pact.css'>
|
43
42
|
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/github-json.css'>
|
44
43
|
<link rel='stylesheet' type='text/css' href='#{base_url}/css/bootstrap.min.css'>
|
45
44
|
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/material-menu.css'>
|
45
|
+
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/pact.css'>
|
46
46
|
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/jquery-confirm.min.css'>
|
47
47
|
<script src='#{base_url}/javascripts/highlight.pack.js'></script>
|
48
48
|
<script src='#{base_url}/javascripts/jquery-3.5.1.min.js'></script>
|
@@ -53,6 +53,17 @@ module PactBroker
|
|
53
53
|
<script>hljs.initHighlightingOnLoad();</script>"
|
54
54
|
end
|
55
55
|
|
56
|
+
def breadcrumbs
|
57
|
+
"
|
58
|
+
<nav aria-label=\"breadcrumb\">
|
59
|
+
<ol class=\"breadcrumb\" style=\"margin:0; margin-bottom:1rem\">
|
60
|
+
<li class=\"breadcrumb-item\" style=\"margin:0;\"><a href=\"#{base_url}/\">Home</a></li>
|
61
|
+
<li class=\"breadcrumb-item active\" aria-current=\"page\" style=\"margin:0;\">Pact</li>
|
62
|
+
</ol>
|
63
|
+
</nav>
|
64
|
+
"
|
65
|
+
end
|
66
|
+
|
56
67
|
def pact_metadata
|
57
68
|
"<div class='pact-metadata'>
|
58
69
|
<ul>
|
@@ -66,19 +77,12 @@ module PactBroker
|
|
66
77
|
<span class='name' title='#{published_date}'>Date published:</span>
|
67
78
|
<span class='value' title='#{published_date}'>#{published_date_in_words}</span>
|
68
79
|
</li>
|
69
|
-
<li>
|
70
|
-
<a href=\"#{json_url}\">View in API Browser</a>
|
71
|
-
</li>
|
72
|
-
<li>
|
73
|
-
<a href=\"#{matrix_url}\">View Matrix</a>
|
74
|
-
</li>
|
75
|
-
<li>
|
76
|
-
<a href=\"#{base_url}/\">Home</a>
|
77
|
-
</li>
|
78
80
|
<li>
|
79
81
|
<span data-consumer-name=\"#{consumer_name}\"
|
80
82
|
data-provider-name=\"#{provider_name}\"
|
81
83
|
data-consumer-version-number=\"#{consumer_version_number}\"
|
84
|
+
data-api-browser-url=\"#{json_url}\"
|
85
|
+
data-matrix-url=\"#{matrix_url}\"
|
82
86
|
data-pact-url=\"#{pact_url}\"
|
83
87
|
class='more-options kebab-horizontal'
|
84
88
|
aria-hidden='true'></span>
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "pact_broker/api/resources/base_resource"
|
2
|
+
require "pact_broker/api/decorators/branch_version_decorator"
|
3
|
+
|
4
|
+
module PactBroker
|
5
|
+
module Api
|
6
|
+
module Resources
|
7
|
+
class BranchVersion < BaseResource
|
8
|
+
def content_types_provided
|
9
|
+
[["application/hal+json", :to_json]]
|
10
|
+
end
|
11
|
+
|
12
|
+
def content_types_accepted
|
13
|
+
[["application/json", :from_json]]
|
14
|
+
end
|
15
|
+
|
16
|
+
def allowed_methods
|
17
|
+
["GET", "PUT", "OPTIONS"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def resource_exists?
|
21
|
+
!!branch_version
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json
|
25
|
+
decorator_class(:branch_version_decorator).new(branch_version).to_json(decorator_options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def from_json
|
29
|
+
already_existed = !!branch_version
|
30
|
+
@branch_version = branch_service.find_or_create_branch_version(identifier_from_path)
|
31
|
+
# Make it return a 201 by setting the Location header
|
32
|
+
response.headers["Location"] = branch_version_url(branch_version, base_url) unless already_existed
|
33
|
+
response.body = to_json
|
34
|
+
end
|
35
|
+
|
36
|
+
def policy_name
|
37
|
+
:'versions::branch_version'
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def branch_version
|
43
|
+
@branch_version ||= branch_service.find_branch_version(identifier_from_path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -116,6 +116,12 @@ module PactBroker
|
|
116
116
|
title: "Get, create or delete a tag for a pacticipant version",
|
117
117
|
templated: true
|
118
118
|
},
|
119
|
+
"pb:pacticipant-branch-version" =>
|
120
|
+
{
|
121
|
+
href: base_url + "/pacticipants/{pacticipant}/branches/{branch}/versions/{version}",
|
122
|
+
title: "Get or add/create a pacticipant version for a branch",
|
123
|
+
templated: true
|
124
|
+
},
|
119
125
|
"pb:pacticipant-version" =>
|
120
126
|
{
|
121
127
|
href: base_url + "/pacticipants/{pacticipant}/versions/{version}",
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "pact_broker/api/resources/base_resource"
|
2
|
+
require "pact_broker/configuration"
|
3
|
+
require "pact_broker/api/decorators/tagged_pact_versions_decorator"
|
4
|
+
require "pact_broker/api/resources/pact_resource_methods"
|
5
|
+
|
6
|
+
module PactBroker
|
7
|
+
module Api
|
8
|
+
module Resources
|
9
|
+
class PactVersionsForBranch < BaseResource
|
10
|
+
include PactResourceMethods
|
11
|
+
|
12
|
+
def content_types_provided
|
13
|
+
[["application/hal+json", :to_json]]
|
14
|
+
end
|
15
|
+
|
16
|
+
def allowed_methods
|
17
|
+
["DELETE", "OPTIONS"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def resource_exists?
|
21
|
+
consumer && provider
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_resource
|
25
|
+
pact_service.delete_all_pact_publications_between consumer_name, and: provider_name, branch_name: identifier_from_path[:branch_name]
|
26
|
+
set_post_deletion_response
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def policy_name
|
31
|
+
:'pacts::pacts'
|
32
|
+
end
|
33
|
+
|
34
|
+
def policy_pacticipant
|
35
|
+
consumer
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "pact_broker/api/resources/provider_pacts"
|
2
2
|
require "pact_broker/api/decorators/verifiable_pacts_decorator"
|
3
|
-
require "pact_broker/api/contracts/
|
4
|
-
require "pact_broker/api/decorators/
|
5
|
-
require "pact_broker/api/contracts/
|
3
|
+
require "pact_broker/api/contracts/pacts_for_verification_query_string_schema"
|
4
|
+
require "pact_broker/api/decorators/pacts_for_verification_query_decorator"
|
5
|
+
require "pact_broker/api/contracts/pacts_for_verification_json_query_schema"
|
6
6
|
require "pact_broker/hash_refinements"
|
7
7
|
|
8
8
|
module PactBroker
|
@@ -69,14 +69,14 @@ module PactBroker
|
|
69
69
|
|
70
70
|
def query_schema
|
71
71
|
if request.get?
|
72
|
-
PactBroker::Api::Contracts::
|
72
|
+
PactBroker::Api::Contracts::PactsForVerificationQueryStringSchema
|
73
73
|
else
|
74
|
-
PactBroker::Api::Contracts::
|
74
|
+
PactBroker::Api::Contracts::PactsForVerificationJSONQuerySchema
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
def parsed_query_params
|
79
|
-
@parsed_query_params ||= decorator_class(:
|
79
|
+
@parsed_query_params ||= decorator_class(:pacts_for_verification_query_decorator).new(OpenStruct.new).from_hash(query)
|
80
80
|
end
|
81
81
|
|
82
82
|
def query
|
@@ -51,7 +51,8 @@ module PactBroker
|
|
51
51
|
|
52
52
|
def from_json
|
53
53
|
handle_webhook_events do
|
54
|
-
|
54
|
+
verified_pacts = pact_service.find_for_verification_publication(pact_params, event_context[:consumer_version_selectors])
|
55
|
+
verification = verification_service.create(next_verification_number, verification_params, verified_pacts, event_context)
|
55
56
|
response.body = decorator_for(verification).to_json(decorator_options)
|
56
57
|
end
|
57
58
|
true
|
@@ -83,12 +84,16 @@ module PactBroker
|
|
83
84
|
metadata[:wip] == "true"
|
84
85
|
end
|
85
86
|
|
87
|
+
def pending?
|
88
|
+
metadata[:pending]
|
89
|
+
end
|
90
|
+
|
86
91
|
def event_context
|
87
92
|
metadata
|
88
93
|
end
|
89
94
|
|
90
95
|
def verification_params
|
91
|
-
params(symbolize_names: false).merge("wip" => wip?)
|
96
|
+
params(symbolize_names: false).merge("wip" => wip?, "pending" => pending?)
|
92
97
|
end
|
93
98
|
end
|
94
99
|
end
|
@@ -21,14 +21,6 @@ module PactBroker
|
|
21
21
|
["GET", "PUT", "PATCH", "DELETE", "OPTIONS"]
|
22
22
|
end
|
23
23
|
|
24
|
-
def is_conflict?
|
25
|
-
if (errors = version_service.conflict_errors(version, parsed_version, resource_url)).any?
|
26
|
-
set_json_validation_error_messages(errors)
|
27
|
-
else
|
28
|
-
false
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
24
|
def resource_exists?
|
33
25
|
!!version
|
34
26
|
end
|
data/lib/pact_broker/api.rb
CHANGED
@@ -32,6 +32,7 @@ module PactBroker
|
|
32
32
|
add ["pacts", "provider", :provider_name, "consumer", :consumer_name, "versions"], Api::Resources::PactVersions, {resource_name: "pact_publications"}
|
33
33
|
add ["pacts", "provider", :provider_name, "consumer", :consumer_name, "versions", :consumer_version_number], Api::Resources::Pact, {resource_name: "pact_publication", deprecated: true} # Not the standard URL, but keep for backwards compatibility
|
34
34
|
add ["pacts", "provider", :provider_name, "consumer", :consumer_name, "tag", :tag], Api::Resources::TaggedPactVersions, {resource_name: "tagged_pact_publications"}
|
35
|
+
add ["pacts", "provider", :provider_name, "consumer", :consumer_name, "branch", :branch_name], Api::Resources::PactVersionsForBranch, {resource_name: "pact_publications_for_branch"}
|
35
36
|
|
36
37
|
# Pacts
|
37
38
|
add ["pacts", "provider", :provider_name, "consumer", :consumer_name, "version", :consumer_version_number], Api::Resources::Pact, {resource_name: "pact_publication"}
|
@@ -87,6 +88,7 @@ module PactBroker
|
|
87
88
|
add ["pacticipants", :pacticipant_name, "latest-version"], Api::Resources::LatestVersion, {resource_name: "latest_pacticipant_version"}
|
88
89
|
add ["pacticipants", :pacticipant_name, "versions", :pacticipant_version_number, "tags", :tag_name], Api::Resources::Tag, {resource_name: "pacticipant_version_tag"}
|
89
90
|
add ["pacticipants", :pacticipant_name, "labels", :label_name], Api::Resources::Label, {resource_name: "pacticipant_label"}
|
91
|
+
add ["pacticipants", :pacticipant_name, "branches", :branch_name, "versions", :version_number], Api::Resources::BranchVersion, { resource_name: "branch_version" }
|
90
92
|
|
91
93
|
# Webhooks
|
92
94
|
add ["webhooks", "provider", :provider_name, "consumer", :consumer_name ], Api::Resources::PacticipantWebhooks, {resource_name: "pacticipant_webhooks"}
|
data/lib/pact_broker/app.rb
CHANGED
@@ -25,6 +25,7 @@ require "rack/pact_broker/reset_thread_data"
|
|
25
25
|
require "rack/pact_broker/add_vary_header"
|
26
26
|
require "rack/pact_broker/use_when"
|
27
27
|
require "sucker_punch"
|
28
|
+
require "pact_broker/api/middleware/configuration"
|
28
29
|
require "pact_broker/api/middleware/basic_auth"
|
29
30
|
require "pact_broker/config/basic_auth_configuration"
|
30
31
|
require "pact_broker/api/authorization/resource_access_policy"
|
@@ -51,6 +52,7 @@ module PactBroker
|
|
51
52
|
load_configuration_from_database
|
52
53
|
seed_example_data
|
53
54
|
print_startup_message
|
55
|
+
@configuration.freeze
|
54
56
|
end
|
55
57
|
|
56
58
|
# Allows middleware to be inserted at the bottom of the shared middlware stack
|
@@ -87,6 +87,7 @@ module PactBroker
|
|
87
87
|
case pseudo_branch_verification_status
|
88
88
|
when :success then "verified"
|
89
89
|
when :failed then "failed"
|
90
|
+
when :failed_pending then "failed (pending)"
|
90
91
|
when :stale then "changed"
|
91
92
|
else "unknown"
|
92
93
|
end
|
@@ -96,6 +97,7 @@ module PactBroker
|
|
96
97
|
case pseudo_branch_verification_status
|
97
98
|
when :success then "brightgreen"
|
98
99
|
when :failed then "red"
|
100
|
+
when :failed_pending then "red"
|
99
101
|
when :stale then "orange"
|
100
102
|
else "lightgrey"
|
101
103
|
end
|
@@ -151,7 +153,7 @@ module PactBroker
|
|
151
153
|
def static_svg pact, pseudo_branch_verification_status
|
152
154
|
file_name = case pseudo_branch_verification_status
|
153
155
|
when :success then "pact-verified-brightgreen.svg"
|
154
|
-
when :failed then "pact-failed-red.svg"
|
156
|
+
when :failed, :failed_pending then "pact-failed-red.svg"
|
155
157
|
when :stale then "pact-changed-orange.svg"
|
156
158
|
else "pact-unknown-lightgrey.svg"
|
157
159
|
end
|
@@ -8,6 +8,18 @@ require "pact_broker/string_refinements"
|
|
8
8
|
require "pact_broker/hash_refinements"
|
9
9
|
require "pact_broker/error"
|
10
10
|
|
11
|
+
module Anyway
|
12
|
+
module Tracing
|
13
|
+
class << self
|
14
|
+
# Override this method so that we get the real caller location, not the forwardable one from
|
15
|
+
# the `extend Forwardable` in the PactBroker::Configuration class.
|
16
|
+
def current_trace_source
|
17
|
+
source_stack.last || accessor_source(caller_locations(2, 2).find { | location | !location.path.end_with?("forwardable.rb") })
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
module PactBroker
|
12
24
|
module Config
|
13
25
|
class RuntimeConfiguration < Anyway::Config
|
@@ -4,10 +4,15 @@ require "semantic_logger"
|
|
4
4
|
require "forwardable"
|
5
5
|
require "pact_broker/config/runtime_configuration"
|
6
6
|
require "anyway/auto_cast"
|
7
|
+
require "request_store"
|
7
8
|
|
8
9
|
module PactBroker
|
9
10
|
def self.configuration
|
10
|
-
|
11
|
+
RequestStore.store[:pact_broker_configuration] ||= Configuration.default_configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.set_configuration(configuration)
|
15
|
+
RequestStore.store[:pact_broker_configuration] = configuration
|
11
16
|
end
|
12
17
|
|
13
18
|
def self.with_runtime_configuration_overrides(overrides, &block)
|
@@ -16,7 +21,7 @@ module PactBroker
|
|
16
21
|
|
17
22
|
# @private, for testing only
|
18
23
|
def self.reset_configuration
|
19
|
-
|
24
|
+
RequestStore.store[:pact_broker_configuration] = Configuration.default_configuration
|
20
25
|
end
|
21
26
|
|
22
27
|
class Configuration
|
@@ -83,12 +88,36 @@ module PactBroker
|
|
83
88
|
|
84
89
|
def with_runtime_configuration_overrides(overrides)
|
85
90
|
original_runtime_configuration = runtime_configuration
|
86
|
-
self.runtime_configuration = override_runtime_configuration(overrides
|
91
|
+
self.runtime_configuration = override_runtime_configuration!(overrides)
|
87
92
|
yield
|
88
93
|
ensure
|
89
94
|
self.runtime_configuration = original_runtime_configuration
|
90
95
|
end
|
91
96
|
|
97
|
+
def override_runtime_configuration!(overrides)
|
98
|
+
new_runtime_configuration = runtime_configuration.dup
|
99
|
+
valid_overrides = {}
|
100
|
+
invalid_overrides = {}
|
101
|
+
|
102
|
+
overrides.each do | key, value |
|
103
|
+
if new_runtime_configuration.respond_to?("#{key}=")
|
104
|
+
valid_overrides[key] = Anyway::AutoCast.call(value)
|
105
|
+
else
|
106
|
+
invalid_overrides[key] = Anyway::AutoCast.call(value)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
if logger.debug?
|
111
|
+
logger.debug("Overridding runtime configuration", payload: { overrides: valid_overrides, ignoring: invalid_overrides })
|
112
|
+
end
|
113
|
+
|
114
|
+
valid_overrides.each do | key, value |
|
115
|
+
new_runtime_configuration.public_send("#{key}=", value)
|
116
|
+
end
|
117
|
+
|
118
|
+
self.runtime_configuration = new_runtime_configuration
|
119
|
+
end
|
120
|
+
|
92
121
|
def logger_from_runtime_configuration
|
93
122
|
@logger_from_runtime_configuration ||= begin
|
94
123
|
runtime_configuration.validate_logging_attributes!
|
@@ -193,7 +222,7 @@ module PactBroker
|
|
193
222
|
end
|
194
223
|
|
195
224
|
def show_webhook_response?
|
196
|
-
webhook_host_whitelist
|
225
|
+
webhook_host_whitelist&.any?
|
197
226
|
end
|
198
227
|
|
199
228
|
def enable_badge_resources= enable_badge_resources
|
@@ -206,30 +235,5 @@ module PactBroker
|
|
206
235
|
require "pact_broker/config/load"
|
207
236
|
PactBroker::Config::Load.call(runtime_configuration)
|
208
237
|
end
|
209
|
-
|
210
|
-
private
|
211
|
-
|
212
|
-
def override_runtime_configuration(overrides, new_runtime_configuration)
|
213
|
-
valid_overrides = {}
|
214
|
-
invalid_overrides = {}
|
215
|
-
|
216
|
-
overrides.each do | key, value |
|
217
|
-
if new_runtime_configuration.respond_to?("#{key}=")
|
218
|
-
valid_overrides[key] = Anyway::AutoCast.call(value)
|
219
|
-
else
|
220
|
-
invalid_overrides[key] = Anyway::AutoCast.call(value)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
if logger.debug?
|
225
|
-
logger.debug("Overridding runtime configuration", payload: { overrides: valid_overrides, ignoring: invalid_overrides })
|
226
|
-
end
|
227
|
-
|
228
|
-
valid_overrides.each do | key, value |
|
229
|
-
new_runtime_configuration.public_send("#{key}=", value)
|
230
|
-
end
|
231
|
-
|
232
|
-
new_runtime_configuration
|
233
|
-
end
|
234
238
|
end
|
235
239
|
end
|