pact_broker 2.84.0 → 2.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/db/migrations/20210913_add_pending_to_verifications.rb +7 -0
  4. data/lib/pact/doc/markdown/consumer_contract_renderer.rb +3 -3
  5. data/lib/pact_broker/api/decorators/reason_decorator.rb +2 -2
  6. data/lib/pact_broker/api/decorators/verification_summary_decorator.rb +1 -2
  7. data/lib/pact_broker/api/middleware/configuration.rb +33 -0
  8. data/lib/pact_broker/api/pact_broker_urls.rb +5 -1
  9. data/lib/pact_broker/api/renderers/html_pact_renderer.rb +15 -11
  10. data/lib/pact_broker/api/resources/pact_versions_for_branch.rb +40 -0
  11. data/lib/pact_broker/api/resources/verifications.rb +5 -1
  12. data/lib/pact_broker/api.rb +1 -0
  13. data/lib/pact_broker/app.rb +2 -0
  14. data/lib/pact_broker/badges/service.rb +3 -1
  15. data/lib/pact_broker/configuration.rb +33 -29
  16. data/lib/pact_broker/domain/verification.rb +9 -0
  17. data/lib/pact_broker/domain/webhook.rb +22 -10
  18. data/lib/pact_broker/domain/webhook_request.rb +2 -2
  19. data/lib/pact_broker/index/service.rb +73 -22
  20. data/lib/pact_broker/locale/en.yml +2 -0
  21. data/lib/pact_broker/pacts/metadata.rb +4 -2
  22. data/lib/pact_broker/pacts/pact_publication.rb +37 -0
  23. data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +39 -0
  24. data/lib/pact_broker/pacts/repository.rb +2 -1
  25. data/lib/pact_broker/test/http_test_data_builder.rb +1 -1
  26. data/lib/pact_broker/test/test_data_builder.rb +5 -1
  27. data/lib/pact_broker/ui/app.rb +7 -1
  28. data/lib/pact_broker/ui/controllers/dashboard.rb +80 -0
  29. data/lib/pact_broker/ui/controllers/groups.rb +23 -8
  30. data/lib/pact_broker/ui/helpers/url_helper.rb +5 -1
  31. data/lib/pact_broker/ui/view_models/index_item.rb +49 -7
  32. data/lib/pact_broker/ui/view_models/matrix_branch.rb +1 -1
  33. data/lib/pact_broker/ui/view_models/matrix_tag.rb +0 -1
  34. data/lib/pact_broker/ui/views/dashboard/show.haml +195 -0
  35. data/lib/pact_broker/ui/views/groups/show.html.erb +60 -14
  36. data/lib/pact_broker/ui/views/index/_dashboard_navbar.haml +7 -0
  37. data/lib/pact_broker/ui/views/index/_navbar.haml +0 -7
  38. data/lib/pact_broker/ui/views/index/show-with-tags.haml +3 -1
  39. data/lib/pact_broker/ui/views/index/show.haml +35 -13
  40. data/lib/pact_broker/ui/views/matrix/show.haml +7 -3
  41. data/lib/pact_broker/verifications/pseudo_branch_status.rb +2 -0
  42. data/lib/pact_broker/verifications/service.rb +1 -0
  43. data/lib/pact_broker/version.rb +1 -1
  44. data/lib/pact_broker/webhooks/event_listener.rb +3 -3
  45. data/lib/pact_broker/webhooks/execution_configuration.rb +16 -0
  46. data/lib/pact_broker/webhooks/execution_configuration_creator.rb +3 -0
  47. data/lib/pact_broker/webhooks/job.rb +1 -1
  48. data/lib/pact_broker/webhooks/trigger_service.rb +2 -2
  49. data/lib/pact_broker/webhooks/webhook_execution_result.rb +3 -7
  50. data/lib/pact_broker/webhooks/webhook_request_logger.rb +4 -12
  51. data/lib/pact_broker/webhooks/webhook_request_template.rb +6 -8
  52. data/pact_broker.gemspec +4 -0
  53. data/public/javascripts/index.js +75 -68
  54. data/public/javascripts/pact.js +14 -14
  55. data/public/stylesheets/index.css +1 -2
  56. data/public/stylesheets/pact.css +11 -0
  57. data/script/data/auto-create-things-for-tags.rb +2 -0
  58. data/script/data/branches.rb +2 -2
  59. data/script/data/contract-published-requiring-verification.rb +1 -1
  60. data/script/data/environments.rb +0 -0
  61. data/script/data/pending.rb +26 -0
  62. data/script/data/tags.rb +35 -0
  63. data/script/data/webhook.rb +22 -0
  64. data/script/seed.rb +50 -89
  65. data/spec/features/delete_pact_versions_for_branch_spec.rb +34 -0
  66. data/spec/fixtures/approvals/modifiable_resources.approved.json +4 -0
  67. data/spec/integration/app_spec.rb +6 -6
  68. data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +2 -2
  69. data/spec/lib/pact_broker/api/decorators/reason_decorator_spec.rb +2 -2
  70. data/spec/lib/pact_broker/api/decorators/verification_summary_decorator_spec.rb +2 -0
  71. data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +1 -1
  72. data/spec/lib/pact_broker/api/middleware/configuration_spec.rb +43 -0
  73. data/spec/lib/pact_broker/api/resources/verifications_spec.rb +2 -3
  74. data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +1 -1
  75. data/spec/lib/pact_broker/badges/service_spec.rb +22 -0
  76. data/spec/lib/pact_broker/domain/webhook_request_spec.rb +2 -1
  77. data/spec/lib/pact_broker/domain/webhook_spec.rb +15 -5
  78. data/spec/lib/pact_broker/index/service_spec.rb +1 -5
  79. data/spec/lib/pact_broker/index/service_view_spec.rb +144 -0
  80. data/spec/lib/pact_broker/pacts/metadata_spec.rb +11 -2
  81. data/spec/lib/pact_broker/pacts/pact_publication_latest_verification_spec.rb +29 -0
  82. data/spec/lib/pact_broker/pacts/repository_spec.rb +15 -2
  83. data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +11 -8
  84. data/spec/lib/pact_broker/verifications/pseudo_branch_status_spec.rb +9 -1
  85. data/spec/lib/pact_broker/verifications/service_spec.rb +4 -2
  86. data/spec/lib/pact_broker/webhooks/job_spec.rb +4 -4
  87. data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +9 -5
  88. data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +6 -12
  89. data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +3 -2
  90. data/spec/support/generated_markdown.md +3 -3
  91. metadata +47 -4
  92. data/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb +0 -56
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d104329cabc691c2ec288acee11837621c8970181a6dddf7d4bf7e4c5d3f48fe
4
- data.tar.gz: d7c5c2a75605aa5f947495670d995d5d5500f487dff86ae676da3bd883c55510
3
+ metadata.gz: 78ca6573c59b514f1527988079ebeecc19f3fc33b66c7abe7fc9bf00b099c7a1
4
+ data.tar.gz: 742f05a5b5348b22aa1efd10dfe2068d76d1259182cfd533442beec8c06e764f
5
5
  SHA512:
6
- metadata.gz: 7a973402c0c004acd5f94cc0c04efec0ded2039f43dfd3e2ca7ba014b853f958345b2ada02c05af05748416dbe466596920d8112c34efd71a5533c212ab6002c
7
- data.tar.gz: 9bf006fa32ad47353df1bb9704a8da05205de57da618273ca0c0cb3b487c570951caa1e0ab3624177aa82a12c329d63aeba11c07c87b1eaa1e368956edd72250
6
+ metadata.gz: af16f324d2022596b678ff7c53e1ab4bcae836e12cf376fd415e581fda38e874fbf33094a21bf04c6c8545c534edd78d181326e34d7865898c52bb1915df4d14
7
+ data.tar.gz: 1c33d08f629c7db7f2ef12589c0982a5e78a1896c24d400467e26bca8389912ecc305d67ca6ea174132ff8e7c03b67b0d4f3d14a241e3355e79e612cb8cb04c5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ <a name="v2.85.0"></a>
2
+ ### v2.85.0 (2021-09-13)
3
+
4
+ #### Features
5
+
6
+ * show in the UI whether or not a pact was pending when verification failed ([326c068e](/../../commit/326c068e))
7
+ * thread safe configuration overrides (#500) ([50900231](/../../commit/50900231))
8
+ * allow dashboard pacts to be viewed by branch, tag, environment or all ([1ec8fc82](/../../commit/1ec8fc82))
9
+ * support deleting pacts by branch in the UI ([bc8fef1d](/../../commit/bc8fef1d))
10
+ * update UI ([0ba5eda3](/../../commit/0ba5eda3))
11
+
1
12
  <a name="v2.84.0"></a>
2
13
  ### v2.84.0 (2021-09-10)
3
14
 
@@ -0,0 +1,7 @@
1
+ Sequel.migration do
2
+ change do
3
+ alter_table(:verifications) do
4
+ add_column(:pact_pending, TrueClass)
5
+ end
6
+ end
7
+ end
@@ -24,7 +24,7 @@ module Pact
24
24
  attr_reader :consumer_contract
25
25
 
26
26
  def title
27
- "### A pact between #{consumer_name} and #{provider_name}\n\n"
27
+ "# A pact between #{consumer_name} and #{provider_name}\n\n"
28
28
  end
29
29
 
30
30
  def interaction_renderers
@@ -32,11 +32,11 @@ module Pact
32
32
  end
33
33
 
34
34
  def summaries_title
35
- "#### Requests from #{consumer_name} to #{provider_name}\n\n"
35
+ "### Requests from #{consumer_name} to #{provider_name}\n\n"
36
36
  end
37
37
 
38
38
  def interactions_title
39
- "#### Interactions\n\n"
39
+ "### Interactions\n\n"
40
40
  end
41
41
 
42
42
  def summaries
@@ -45,9 +45,9 @@ module PactBroker
45
45
  when PactBroker::Matrix::IgnoreSelectorDoesNotExist
46
46
  "WARN: Cannot ignore #{reason.selector.description}"
47
47
  when PactBroker::Matrix::SelectorWithoutPacticipantVersionNumberSpecified
48
- "WARN: For production use of can-i-deploy, it is recommended to specify the version number (rather than latest tag or branch) of each pacticipant to avoid race conditions."
48
+ "WARN: It is recommended to specify the version number (rather than the tag or branch) of the pacticipant you wish to deploy to avoid race conditions. Without a version number, this result will not be reliable."
49
49
  when PactBroker::Matrix::NoEnvironmentSpecified
50
- "WARN: For production use of can-i-deploy, it is recommended to specify the environment into which you are deploying. Without the environment, this result will not be reliable."
50
+ "WARN: It is recommended to specify the environment into which you are deploying. Without the environment, this result will not be reliable."
51
51
  else
52
52
  reason
53
53
  end
@@ -6,9 +6,9 @@ require "ostruct"
6
6
  module PactBroker
7
7
  module Api
8
8
  module Decorators
9
-
10
9
  class VerificationSummaryDecorator < BaseDecorator
11
10
 
11
+ # TODO count pending failures?
12
12
  property :success
13
13
  property :provider_summary, as: :providerSummary do
14
14
  property :successful
@@ -30,7 +30,6 @@ module PactBroker
30
30
  successful: represented.select(&:success).collect(&:provider_name),
31
31
  failed: represented.select{|verification| !verification.success }.collect(&:provider_name))
32
32
  end
33
-
34
33
  end
35
34
  end
36
35
  end
@@ -0,0 +1,33 @@
1
+ require "pact_broker/logging"
2
+
3
+ module PactBroker
4
+ module Api
5
+ module Middleware
6
+ class Configuration
7
+ include PactBroker::Logging
8
+
9
+ def initialize(app, configuration)
10
+ @app = app
11
+ @configuration = configuration
12
+ end
13
+
14
+ def call(env)
15
+ if (overrides = env["pactbroker.configuration_overrides"])&.any?
16
+ dupped_configuration = configuration.dup
17
+ dupped_configuration.override_runtime_configuration!(overrides)
18
+ dupped_configuration.freeze
19
+ PactBroker.set_configuration(dupped_configuration)
20
+ app.call(env)
21
+ else
22
+ PactBroker.set_configuration(configuration)
23
+ app.call(env)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :app, :configuration
30
+ end
31
+ end
32
+ end
33
+ end
@@ -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
@@ -311,7 +315,7 @@ module PactBroker
311
315
  end
312
316
 
313
317
  def group_url(pacticipant_name, base_url = "")
314
- "#{base_url}/groups/#{url_encode(pacticipant_name)}"
318
+ "#{base_url}/pacticipants/#{url_encode(pacticipant_name)}"
315
319
  end
316
320
 
317
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,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
@@ -84,12 +84,16 @@ module PactBroker
84
84
  metadata[:wip] == "true"
85
85
  end
86
86
 
87
+ def pending?
88
+ metadata[:pending]
89
+ end
90
+
87
91
  def event_context
88
92
  metadata
89
93
  end
90
94
 
91
95
  def verification_params
92
- params(symbolize_names: false).merge("wip" => wip?)
96
+ params(symbolize_names: false).merge("wip" => wip?, "pending" => pending?)
93
97
  end
94
98
  end
95
99
  end
@@ -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"}
@@ -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
@@ -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
- @@configuration ||= Configuration.default_configuration
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
- @@configuration = Configuration.default_configuration
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, original_runtime_configuration.dup)
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.any?
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
@@ -206,6 +206,15 @@ module PactBroker
206
206
  @pact_content_with_test_results = PactBroker::Pacts::Content.from_json(pact_version.content).with_test_results(test_results)
207
207
  end
208
208
 
209
+ # Whether the pact content was pending at the time the verification was run
210
+ def pact_pending?
211
+ pact_pending
212
+ end
213
+
214
+ def failed_and_pact_pending?
215
+ !success && pact_pending
216
+ end
217
+
209
218
  # So consumer_version_tag_name can be accessed by method name
210
219
  def method_missing(m, *args, &block)
211
220
  if values.key?(m) && args.size == 0
@@ -50,17 +50,12 @@ module PactBroker
50
50
  def execute pact, verification, event_context, options
51
51
  logger.info "Executing #{self} event_context=#{event_context}"
52
52
  template_params = template_parameters(pact, verification, event_context, options)
53
- webhook_request = request.build(template_params)
53
+ webhook_request = request.build(template_params, options.fetch(:user_agent))
54
54
  http_response, error = execute_request(webhook_request)
55
-
56
- logs = generate_logs(webhook_request, http_response, error, event_context, options.fetch(:logging_options))
55
+ success = success?(http_response, options)
57
56
  http_request = webhook_request.http_request
58
- PactBroker::Webhooks::WebhookExecutionResult.new(
59
- http_request,
60
- http_response,
61
- logs,
62
- error
63
- )
57
+ logs = generate_logs(webhook_request, http_response, success, error, event_context, options.fetch(:logging_options))
58
+ result(http_request, http_response, success, logs, error)
64
59
  end
65
60
 
66
61
  def to_s
@@ -116,16 +111,33 @@ module PactBroker
116
111
  PactBroker::Webhooks::PactAndVerificationParameters.new(pact, verification, event_context).to_hash
117
112
  end
118
113
 
119
- def generate_logs(webhook_request, http_response, error, event_context, logging_options)
114
+ def success?(http_response, options)
115
+ !http_response.nil? && options.fetch(:http_success_codes).include?(http_response.code.to_i)
116
+ end
117
+
118
+ # rubocop: disable Metrics/ParameterLists
119
+ def generate_logs(webhook_request, http_response, success, error, event_context, logging_options)
120
120
  webhook_request_logger = PactBroker::Webhooks::WebhookRequestLogger.new(logging_options)
121
121
  webhook_request_logger.log(
122
122
  uuid,
123
123
  webhook_request,
124
124
  http_response,
125
+ success,
125
126
  error,
126
127
  event_context
127
128
  )
128
129
  end
130
+ # robocop: enable Metrics/ParameterLists
131
+
132
+ def result(http_request, http_response, success, logs, error)
133
+ PactBroker::Webhooks::WebhookExecutionResult.new(
134
+ http_request,
135
+ http_response,
136
+ success,
137
+ logs,
138
+ error
139
+ )
140
+ end
129
141
  end
130
142
  end
131
143
  end