pact_broker 2.22.0 → 2.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/README.md +1 -0
  4. data/db/migrations/20180611_make_webhook_pacticipant_ids_optional.rb +11 -0
  5. data/example/config.ru +2 -0
  6. data/lib/pact_broker/api.rb +9 -3
  7. data/lib/pact_broker/api/contracts/webhook_contract.rb +36 -0
  8. data/lib/pact_broker/api/decorators/pact_decorator.rb +22 -1
  9. data/lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb +1 -26
  10. data/lib/pact_broker/api/decorators/triggered_webhook_decorator.rb +33 -0
  11. data/lib/pact_broker/api/decorators/triggered_webhooks_decorator.rb +19 -0
  12. data/lib/pact_broker/api/decorators/verification_decorator.rb +6 -0
  13. data/lib/pact_broker/api/decorators/webhook_decorator.rb +32 -18
  14. data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +27 -0
  15. data/lib/pact_broker/api/decorators/{webhook_request_decorator.rb → webhook_request_template_decorator.rb} +1 -1
  16. data/lib/pact_broker/api/pact_broker_urls.rb +21 -1
  17. data/lib/pact_broker/api/resources/all_webhooks.rb +82 -0
  18. data/lib/pact_broker/api/resources/base_resource.rb +18 -0
  19. data/lib/pact_broker/api/resources/error_handler.rb +5 -1
  20. data/lib/pact_broker/api/resources/pact_triggered_webhooks.rb +41 -0
  21. data/lib/pact_broker/api/resources/pact_webhooks.rb +2 -15
  22. data/lib/pact_broker/api/resources/pact_webhooks_status.rb +1 -1
  23. data/lib/pact_broker/api/resources/verification_triggered_webhooks.rb +45 -0
  24. data/lib/pact_broker/api/resources/webhook_execution.rb +1 -5
  25. data/lib/pact_broker/api/resources/webhooks.rb +69 -6
  26. data/lib/pact_broker/configuration.rb +5 -2
  27. data/lib/pact_broker/doc/controllers/app.rb +1 -2
  28. data/lib/pact_broker/doc/views/pact-webhooks.markdown +3 -0
  29. data/lib/pact_broker/doc/views/webhooks.markdown +53 -33
  30. data/lib/pact_broker/domain/pact.rb +4 -0
  31. data/lib/pact_broker/domain/webhook.rb +19 -3
  32. data/lib/pact_broker/domain/webhook_execution_result.rb +6 -1
  33. data/lib/pact_broker/domain/webhook_request.rb +87 -65
  34. data/lib/pact_broker/locale/en.yml +1 -0
  35. data/lib/pact_broker/matrix/repository.rb +3 -1
  36. data/lib/pact_broker/pacts/placeholder_pact.rb +17 -0
  37. data/lib/pact_broker/pacts/repository.rb +14 -0
  38. data/lib/pact_broker/pacts/service.rb +6 -2
  39. data/lib/pact_broker/ui/view_models/index_item.rb +1 -1
  40. data/lib/pact_broker/verifications/placeholder_verification.rb +23 -0
  41. data/lib/pact_broker/verifications/repository.rb +9 -0
  42. data/lib/pact_broker/verifications/service.rb +5 -1
  43. data/lib/pact_broker/version.rb +1 -1
  44. data/lib/pact_broker/webhooks/repository.rb +54 -4
  45. data/lib/pact_broker/webhooks/service.rb +37 -2
  46. data/lib/pact_broker/webhooks/webhook.rb +4 -3
  47. data/lib/pact_broker/webhooks/webhook_event.rb +8 -0
  48. data/lib/pact_broker/webhooks/webhook_request_template.rb +72 -0
  49. data/pact_broker.gemspec +1 -1
  50. data/script/seed.rb +32 -51
  51. data/spec/features/create_webhook_spec.rb +85 -36
  52. data/spec/features/execute_webhook_spec.rb +9 -18
  53. data/spec/features/get_triggered_webhooks_for_pact_spec.rb +20 -0
  54. data/spec/features/get_triggered_webhooks_for_verification_spec.rb +21 -0
  55. data/spec/fixtures/webhook_valid_with_pacticipants.json +23 -0
  56. data/spec/integration/webhooks/certificate_spec.rb +2 -2
  57. data/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +98 -2
  58. data/spec/lib/pact_broker/api/decorators/triggered_webhook_decorator_spec.rb +64 -0
  59. data/spec/lib/pact_broker/api/decorators/triggered_webhooks_decorator_spec.rb +28 -0
  60. data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +8 -0
  61. data/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +37 -1
  62. data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +34 -1
  63. data/spec/lib/pact_broker/api/decorators/{webhook_request_decorator_spec.rb → webhook_request_template_decorator_spec.rb} +7 -9
  64. data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +22 -0
  65. data/spec/lib/pact_broker/api/resources/{pact_webhooks_spec.rb → all_webhooks_spec.rb} +46 -80
  66. data/spec/lib/pact_broker/api/resources/error_handler_spec.rb +34 -0
  67. data/spec/lib/pact_broker/api/resources/pact_triggered_webhooks_spec.rb +54 -0
  68. data/spec/lib/pact_broker/api/resources/pacticipant_spec.rb +1 -6
  69. data/spec/lib/pact_broker/api/resources/tag_spec.rb +1 -6
  70. data/spec/lib/pact_broker/api/resources/verification_triggered_webhooks_spec.rb +68 -0
  71. data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +2 -8
  72. data/spec/lib/pact_broker/api/resources/webhooks_spec.rb +216 -21
  73. data/spec/lib/pact_broker/configuration_spec.rb +30 -0
  74. data/spec/lib/pact_broker/domain/webhook_request_spec.rb +20 -64
  75. data/spec/lib/pact_broker/domain/webhook_spec.rb +40 -11
  76. data/spec/lib/pact_broker/matrix/repository_spec.rb +33 -0
  77. data/spec/lib/pact_broker/pacts/pact_version_spec.rb +1 -0
  78. data/spec/lib/pact_broker/pacts/repository_spec.rb +39 -1
  79. data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +1 -1
  80. data/spec/lib/pact_broker/verifications/repository_spec.rb +37 -0
  81. data/spec/lib/pact_broker/verifications/service_spec.rb +2 -2
  82. data/spec/lib/pact_broker/webhooks/render_spec.rb +15 -0
  83. data/spec/lib/pact_broker/webhooks/repository_spec.rb +149 -30
  84. data/spec/lib/pact_broker/webhooks/service_spec.rb +84 -7
  85. data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +81 -0
  86. data/spec/service_consumers/pact_helper.rb +2 -0
  87. data/spec/service_consumers/provider_states_for_pact_broker_client.rb +8 -0
  88. data/spec/service_consumers/provider_states_for_pact_ruby.rb +132 -0
  89. data/spec/support/test_data_builder.rb +30 -7
  90. metadata +37 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 107e0313842be2bc851feb80d62920c27f320509
4
- data.tar.gz: d411b036f55dc4d75544d13f607bcdd156485daf
3
+ metadata.gz: 8781ad53ce4869d80b5c2ad87288cd6d6e1561da
4
+ data.tar.gz: e83f9bc9fd4b337ac1d28a210402db80af340a5f
5
5
  SHA512:
6
- metadata.gz: c00e5f4e37da0f499641550cae06a874ae384065ab7afe3e0b44901e5ea87218b69715936d704b4701e3d310d1f66239395319ca111bbdca6ba488c57828e78c
7
- data.tar.gz: 2beb39b0a6fabee40acd5d7259437262f120ae8c0bf5273c32e79ad66be3fa32fd13b18629cfd94b9877f470c7a6ff2f62c71a478ac9a1a2fcee1baf1e02c123
6
+ metadata.gz: 3c424033d9cb8fa602a2344d11eea58722001df6fc6555e10d51a4af28b29e92f660156650da1b7fd511a7496e5e9b9d01afdec1b4d288569cf49a567ef9a818
7
+ data.tar.gz: f746b17398c51084398b6c4197a4c42b61ea91b7f8b95c210234cb00102fff4f82e9f4ac5e4c26136ee1b375c1147d23909e137ee40e7ec8a21eefbd30432994
@@ -1,3 +1,33 @@
1
+ <a name="v2.23.0"></a>
2
+ ### v2.23.0 (2018-06-20)
3
+
4
+
5
+ #### Features
6
+
7
+ * include test webhook request in execution response body ([7518098](/../../commit/7518098))
8
+ * use the latest matching pact or verification to test webhook execution, or a placeholder if either is not found ([273078b](/../../commit/273078b))
9
+ * add resource to view the triggered webhooks for a verification result ([c3e8df0](/../../commit/c3e8df0))
10
+ * add resource to view the triggered webhooks for a pact publication ([00f60c1](/../../commit/00f60c1))
11
+ * allow "global" webhooks (matching all consumers and providers) to be triggered by pact or verification publication ([19f7060](/../../commit/19f7060))
12
+ * allow webhook with optional consumer and/or provider to be created by posting to /webhooks ([b15ba85](/../../commit/b15ba85))
13
+ * add consumer and provider objects to webhook resource ([e60460e](/../../commit/e60460e))
14
+ * move $.message to $.error.message in error response body ([803c025](/../../commit/803c025))
15
+ * only show backtrace in error response for non production environments ([665ac23](/../../commit/665ac23))
16
+ * change version ordering to sort by date by default ([6552b46](/../../commit/6552b46))
17
+ * raise explicit error if a matrix query is done for a version with a tag that does not exist ([8f64288](/../../commit/8f64288))
18
+
19
+ * **consumer or provider webhooks**
20
+ * refactor webhooks resource classes and add consumer and provider webhook links to pact resource ([9321c73](/../../commit/9321c73))
21
+ * change pact webhook status URL ([2445b1e](/../../commit/2445b1e))
22
+ * allow a webhook to be defined for either a consumer OR provider ([37a62be](/../../commit/37a62be))
23
+
24
+
25
+ #### Bug Fixes
26
+
27
+ * ensure non utf-8 characters in the webook response do not cause an error in the Pact Broker response body ([a5ae5bf](/../../commit/a5ae5bf))
28
+ * update sintra to >= 2.0.2 to fix css vulnerability ([3023408](/../../commit/3023408))
29
+
30
+
1
31
  <a name="v2.22.0"></a>
2
32
  ### v2.22.0 (2018-06-11)
3
33
 
data/README.md CHANGED
@@ -148,6 +148,7 @@ You can use the [Pact Broker Docker image][docker] or [Terraform on AWS][terrafo
148
148
  `
149
149
  * Please ensure you use `encoding: 'utf8'` in your Sequel options to avoid encoding issues.
150
150
  * For production usage, use a web application server like [Phusion Passenger](https://www.phusionpassenger.com) or [Nginx](http://nginx.org/) to serve the Pact Broker application. You'll need to read up on the documentation for these yourself as it is beyond the scope of this documentation. See the [wiki][reverse-proxy-docs] for instructions on using a reverse proxy with SSL.
151
+ * Ensure the environment variable `RACK_ENV` is set to `production`.
151
152
  * Deploy to your location of choice.
152
153
 
153
154
  ## Upgrading
@@ -0,0 +1,11 @@
1
+ Sequel.migration do
2
+ up do
3
+ alter_table(:webhooks) do
4
+ set_column_allow_null(:consumer_id)
5
+ set_column_allow_null(:provider_id)
6
+ end
7
+ end
8
+
9
+ down do
10
+ end
11
+ end
@@ -4,6 +4,8 @@ require 'sequel'
4
4
  # require 'pg' # for postgres
5
5
  require 'pact_broker'
6
6
 
7
+ ENV['RACK_ENV'] ||= 'production'
8
+
7
9
  # Create a real database, and set the credentials for it here
8
10
  # It is highly recommended to set the encoding to utf8
9
11
  DATABASE_CREDENTIALS = {adapter: "sqlite", database: "pact_broker_database.sqlite3", :encoding => 'utf8'}
@@ -22,6 +22,7 @@ module PactBroker
22
22
  # Verifications
23
23
  add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results'], Api::Resources::Verifications, {resource_name: "verification_results"}
24
24
  add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results', :verification_number], Api::Resources::Verification, {resource_name: "verification_result"}
25
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results', :verification_number, 'triggered-webhooks'], Api::Resources::VerificationTriggeredWebhooks, {resource_name: "verification_result_triggered_webhooks"}
25
26
  add ['verification-results', 'consumer', :consumer_name, 'version', :consumer_version_number,'latest'], Api::Resources::LatestVerificationsForConsumerVersion, {resource_name: "verification_results_for_consumer_version"}
26
27
 
27
28
  # Badges
@@ -55,13 +56,18 @@ module PactBroker
55
56
  add ['pacticipants', :pacticipant_name, 'labels', :label_name], Api::Resources::Label, {resource_name: "pacticipant_label"}
56
57
 
57
58
  # Webhooks
58
- add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::PactWebhooks, {resource_name: "pact_webhooks"}
59
- add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name, 'status' ], Api::Resources::PactWebhooksStatus, {resource_name: "pact_webhooks_status"}
59
+ add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::Webhooks, {resource_name: "consumer_and_provider_webhooks"}
60
+ add ['webhooks', 'provider', :provider_name], Api::Resources::Webhooks, {resource_name: "provider_webhooks"}
61
+ add ['webhooks', 'consumer', :consumer_name], Api::Resources::Webhooks, {resource_name: "consumer_webhooks"}
62
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'webhooks'], Api::Resources::PactWebhooks, {resource_name: "pact_webhooks"}
63
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'webhooks', 'status'], Api::Resources::PactWebhooksStatus, {resource_name: "pact_webhooks_status"}
64
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number, 'triggered-webhooks'], Api::Resources::PactTriggeredWebhooks, {resource_name: "pact_triggered_webhooks"}
60
65
 
61
66
  add ['webhooks', :uuid ], Api::Resources::Webhook, {resource_name: "webhook"}
62
67
  add ['webhooks', :uuid, 'trigger', :trigger_uuid, 'logs' ], Api::Resources::TriggeredWebhookLogs, {resource_name: "triggered_webhook_logs"}
63
68
  add ['webhooks', :uuid, 'execute' ], Api::Resources::WebhookExecution, {resource_name: "execute_webhook"}
64
- add ['webhooks'], Api::Resources::Webhooks, {resource_name: "webhooks"}
69
+ add ['webhooks'], Api::Resources::AllWebhooks, {resource_name: "webhooks"}
70
+
65
71
 
66
72
  add ['relationships'], Api::Resources::Relationships, {resource_name: "relationships"}
67
73
  add ['groups', :pacticipant_name], Api::Resources::Group, {resource_name: "group"}
@@ -2,6 +2,7 @@ require 'reform'
2
2
  require 'reform/form'
3
3
  require 'pact_broker/webhooks/check_host_whitelist'
4
4
  require 'pact_broker/webhooks/render'
5
+ require 'pact_broker/pacticipants/service'
5
6
 
6
7
  module PactBroker
7
8
  module Api
@@ -26,10 +27,45 @@ module PactBroker
26
27
  config.messages_file = File.expand_path("../../../locale/en.yml", __FILE__)
27
28
  end
28
29
 
30
+ optional(:consumer)
31
+ optional(:provider)
29
32
  required(:request).filled
30
33
  optional(:events).maybe(min_size?: 1)
31
34
  end
32
35
 
36
+ property :consumer do
37
+ property :name
38
+
39
+ validation do
40
+ configure do
41
+ config.messages_file = File.expand_path("../../../locale/en.yml", __FILE__)
42
+
43
+ def pacticipant_exists?(name)
44
+ !!PactBroker::Pacticipants::Service.find_pacticipant_by_name(name)
45
+ end
46
+ end
47
+
48
+ required(:name).filled(:pacticipant_exists?)
49
+ end
50
+
51
+ end
52
+
53
+ property :provider do
54
+ property :name
55
+
56
+ validation do
57
+ configure do
58
+ config.messages_file = File.expand_path("../../../locale/en.yml", __FILE__)
59
+
60
+ def pacticipant_exists?(name)
61
+ !!PactBroker::Pacticipants::Service.find_pacticipant_by_name(name)
62
+ end
63
+ end
64
+
65
+ required(:name).filled(:pacticipant_exists?)
66
+ end
67
+ end
68
+
33
69
  property :request do
34
70
  property :url
35
71
  property :http_method
@@ -102,7 +102,21 @@ module PactBroker
102
102
  link :'pb:pact-webhooks' do | options |
103
103
  {
104
104
  title: "Webhooks for the pact between #{represented.consumer.name} and #{represented.provider.name}",
105
- href: webhooks_for_pact_url(represented.consumer, represented.provider, options.fetch(:base_url))
105
+ href: webhooks_for_consumer_and_provider_url(represented.consumer, represented.provider, options.fetch(:base_url))
106
+ }
107
+ end
108
+
109
+ link :'pb:consumer-webhooks' do | options |
110
+ {
111
+ title: "Webhooks for all pacts with consumer #{represented.consumer.name}",
112
+ href: consumer_webhooks_url(represented.consumer, options.fetch(:base_url))
113
+ }
114
+ end
115
+
116
+ link :'pb:consumer-webhooks' do | options |
117
+ {
118
+ title: "Webhooks for all pacts with provider #{represented.provider.name}",
119
+ href: consumer_webhooks_url(represented.provider, options.fetch(:base_url))
106
120
  }
107
121
  end
108
122
 
@@ -127,6 +141,13 @@ module PactBroker
127
141
  }
128
142
  end
129
143
 
144
+ link :'pb:triggered-webhooks' do | options |
145
+ {
146
+ title: "Webhooks triggered by the publication of this pact",
147
+ href: pact_triggered_webhooks_url(represented, options.fetch(:base_url))
148
+ }
149
+ end
150
+
130
151
  curies do | options |
131
152
  [{
132
153
  name: :pb,
@@ -1,37 +1,12 @@
1
1
  require_relative 'base_decorator'
2
2
  require_relative 'timestamps'
3
3
  require_relative 'pact_version_decorator'
4
+ require_relative 'triggered_webhook_decorator'
4
5
 
5
6
  module PactBroker
6
7
  module Api
7
8
  module Decorators
8
9
 
9
- class TriggeredWebhookDecorator < BaseDecorator
10
- property :request_description, as: :name
11
- property :status
12
- property :number_of_attempts_made, as: :attemptsMade
13
- property :number_of_attempts_remaining, as: :attemptsRemaining
14
- property :trigger_type, as: :triggerType
15
-
16
- property :created_at, as: :triggeredAt
17
-
18
- link :logs do | context |
19
- {
20
- href: triggered_webhook_logs_url(represented, context[:base_url]),
21
- title: "Webhook execution logs",
22
- name: represented.request_description
23
- }
24
- end
25
-
26
- link :'pb:webhook' do | context |
27
- {
28
- href: webhook_url(represented.webhook_uuid, context[:base_url]),
29
- title: "Webhook",
30
- name: represented.request_description
31
- }
32
- end
33
- end
34
-
35
10
  class PactWebhooksStatusDecorator < BaseDecorator
36
11
 
37
12
  property :summary, exec_context: :decorator do
@@ -0,0 +1,33 @@
1
+ require_relative 'base_decorator'
2
+
3
+ module PactBroker
4
+ module Api
5
+ module Decorators
6
+ class TriggeredWebhookDecorator < BaseDecorator
7
+ property :request_description, as: :name
8
+ property :status
9
+ property :number_of_attempts_made, as: :attemptsMade
10
+ property :number_of_attempts_remaining, as: :attemptsRemaining
11
+ property :trigger_type, as: :triggerType
12
+
13
+ property :created_at, as: :triggeredAt
14
+
15
+ link :logs do | context |
16
+ {
17
+ href: triggered_webhook_logs_url(represented, context[:base_url]),
18
+ title: "Webhook execution logs",
19
+ name: represented.request_description
20
+ }
21
+ end
22
+
23
+ link :'pb:webhook' do | context |
24
+ {
25
+ href: webhook_url(represented.webhook_uuid, context[:base_url]),
26
+ title: "Webhook",
27
+ name: represented.request_description
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ require 'pact_broker/api/decorators/base_decorator'
2
+ require 'pact_broker/api/decorators/triggered_webhook_decorator'
3
+
4
+ module PactBroker
5
+ module Api
6
+ module Decorators
7
+ class TriggeredWebhooksDecorator < BaseDecorator
8
+ collection :entries, as: :triggeredWebhooks, embedded: true, :extend => PactBroker::Api::Decorators::TriggeredWebhookDecorator
9
+
10
+ link :self do | options |
11
+ {
12
+ title: options.fetch(:resource_title),
13
+ href: options.fetch(:resource_url)
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -28,6 +28,12 @@ module PactBroker
28
28
  }
29
29
  end
30
30
 
31
+ link 'pb:triggered-webhooks' do | options |
32
+ {
33
+ title: 'Webhooks triggered by the publication of this verification result',
34
+ href: verification_triggered_webhooks_url(represented, options.fetch(:base_url))
35
+ }
36
+ end
31
37
  end
32
38
  end
33
39
  end
@@ -1,7 +1,7 @@
1
1
  require_relative 'base_decorator'
2
- require 'pact_broker/api/decorators/webhook_request_decorator'
2
+ require 'pact_broker/api/decorators/webhook_request_template_decorator'
3
3
  require 'pact_broker/api/decorators/timestamps'
4
- require 'pact_broker/domain/webhook_request'
4
+ require 'pact_broker/webhooks/webhook_request_template'
5
5
  require 'pact_broker/webhooks/webhook_event'
6
6
  require 'pact_broker/api/decorators/basic_pacticipant_decorator'
7
7
  require_relative 'pact_pacticipant_decorator'
@@ -16,7 +16,15 @@ module PactBroker
16
16
  property :name
17
17
  end
18
18
 
19
- property :request, :class => PactBroker::Domain::WebhookRequest, extend: WebhookRequestDecorator
19
+ property :consumer, :class => PactBroker::Domain::Pacticipant do
20
+ property :name
21
+ end
22
+
23
+ property :provider, :class => PactBroker::Domain::Pacticipant do
24
+ property :name
25
+ end
26
+
27
+ property :request, :class => PactBroker::Webhooks::WebhookRequestTemplate, extend: WebhookRequestTemplateDecorator
20
28
  collection :events, :class => PactBroker::Webhooks::WebhookEvent, extend: WebhookEventDecorator
21
29
 
22
30
  include Timestamps
@@ -31,33 +39,39 @@ module PactBroker
31
39
 
32
40
  link :'pb:execute' do | options |
33
41
  {
34
- title: "Test the execution of the webhook by sending a POST request to this URL",
42
+ title: "Test the execution of the webhook with the latest matching pact or verification by sending a POST request to this URL",
35
43
  href: webhook_execution_url(represented, options[:base_url])
36
44
  }
37
45
  end
38
46
 
39
47
 
40
48
  link :'pb:consumer' do | options |
41
- {
42
- title: "Consumer",
43
- name: represented.consumer.name,
44
- href: pacticipant_url(options.fetch(:base_url), represented.consumer)
45
- }
49
+ if represented.consumer
50
+ {
51
+ title: "Consumer",
52
+ name: represented.consumer.name,
53
+ href: pacticipant_url(options.fetch(:base_url), represented.consumer)
54
+ }
55
+ end
46
56
  end
47
57
 
48
58
  link :'pb:provider' do | options |
49
- {
50
- title: "Provider",
51
- name: represented.provider.name,
52
- href: pacticipant_url(options.fetch(:base_url), represented.provider)
53
- }
59
+ if represented.provider
60
+ {
61
+ title: "Provider",
62
+ name: represented.provider.name,
63
+ href: pacticipant_url(options.fetch(:base_url), represented.provider)
64
+ }
65
+ end
54
66
  end
55
67
 
56
68
  link :'pb:pact-webhooks' do | options |
57
- {
58
- title: "All webhooks for consumer #{represented.consumer.name} and provider #{represented.provider.name}",
59
- href: webhooks_for_pact_url(represented.consumer, represented.provider, options[:base_url])
60
- }
69
+ if represented.consumer && represented.provider
70
+ {
71
+ title: "All webhooks for consumer #{represented.consumer.name} and provider #{represented.provider.name}",
72
+ href: webhooks_for_consumer_and_provider_url(represented.consumer, represented.provider, options[:base_url])
73
+ }
74
+ end
61
75
  end
62
76
 
63
77
  link :'pb:webhooks' do | options |
@@ -11,6 +11,32 @@ module PactBroker
11
11
  property :backtrace
12
12
  end
13
13
 
14
+ class HTTPRequestDecorator < BaseDecorator
15
+ property :headers, exec_context: :decorator
16
+ property :body, exec_context: :decorator
17
+ property :url, exec_context: :decorator
18
+
19
+ def headers
20
+ headers_hash = represented.to_hash
21
+ headers_hash.keys.each_with_object({}) do | name, new_headers_hash|
22
+ new_headers_hash[name] = headers_hash[name].join(", ")
23
+ end
24
+ end
25
+
26
+ def body
27
+ begin
28
+ ::JSON.parse(represented.body)
29
+ rescue StandardError => e
30
+ represented.body
31
+ end
32
+ end
33
+
34
+ def url
35
+ (represented.uri || represented.path).to_s
36
+ end
37
+ end
38
+
39
+
14
40
  class HTTPResponseDecorator < BaseDecorator
15
41
  property :status, :getter => lambda { |_| code.to_i }
16
42
  property :headers, exec_context: :decorator
@@ -33,6 +59,7 @@ module PactBroker
33
59
  end
34
60
 
35
61
  property :error, :extend => ErrorDecorator, if: lambda { |context| context[:options][:user_options][:show_response] }
62
+ property :request, :extend => HTTPRequestDecorator
36
63
  property :response, :extend => HTTPResponseDecorator, if: lambda { |context| context[:options][:user_options][:show_response] }
37
64
  property :response_hidden_message, as: :message, exec_context: :decorator, if: lambda { |context| !context[:options][:user_options][:show_response] }
38
65
 
@@ -3,7 +3,7 @@ require_relative 'base_decorator'
3
3
  module PactBroker
4
4
  module Api
5
5
  module Decorators
6
- class WebhookRequestDecorator < BaseDecorator
6
+ class WebhookRequestTemplateDecorator < BaseDecorator
7
7
 
8
8
  property :method
9
9
  property :url
@@ -120,6 +120,10 @@ module PactBroker
120
120
  "#{base_url}/verification-results/consumer/#{url_encode(version.pacticipant.name)}/version/#{version.number}/latest"
121
121
  end
122
122
 
123
+ def verification_triggered_webhooks_url verification, base_url = ''
124
+ "#{verification_url(verification, base_url)}/triggered-webhooks"
125
+ end
126
+
123
127
  def verification_publication_url pact, base_url
124
128
  "#{pactigration_base_url(base_url, pact)}/pact-version/#{pact.pact_version_sha}/verification-results"
125
129
  end
@@ -152,14 +156,30 @@ module PactBroker
152
156
  "#{base_url}/webhooks/#{webhook.uuid}/execute"
153
157
  end
154
158
 
155
- def webhooks_for_pact_url consumer, provider, base_url = ''
159
+ def webhooks_for_consumer_and_provider_url consumer, provider, base_url = ''
156
160
  "#{base_url}/webhooks/provider/#{url_encode(provider.name)}/consumer/#{url_encode(consumer.name)}"
157
161
  end
158
162
 
163
+ def consumer_webhooks_url consumer, base_url = ''
164
+ "#{base_url}/webhooks/consumer/#{url_encode(consumer.name)}"
165
+ end
166
+
167
+ def provider_webhooks_url provider, base_url = ''
168
+ "#{base_url}/webhooks/provider/#{url_encode(provider.name)}"
169
+ end
170
+
171
+ def webhooks_for_pact_url consumer, provider, base_url = ''
172
+ "#{base_url}/pacts/provider/#{url_encode(provider.name)}/consumer/#{url_encode(consumer.name)}/webhooks"
173
+ end
174
+
159
175
  def webhooks_status_url consumer, provider, base_url = ''
160
176
  "#{webhooks_for_pact_url(consumer, provider, base_url)}/status"
161
177
  end
162
178
 
179
+ def pact_triggered_webhooks_url pact, base_url = ''
180
+ "#{pact_url(base_url, pact)}/triggered-webhooks"
181
+ end
182
+
163
183
  def triggered_webhook_logs_url triggered_webhook, base_url
164
184
  "#{base_url}/webhooks/#{triggered_webhook.webhook_uuid}/trigger/#{triggered_webhook.trigger_uuid}/logs"
165
185
  end