Skip to content

Commit 2445b1e

Browse files
committed
feat(consumer or provider webhooks): change pact webhook status URL
/webhooks/provider/PROVIDER/consumer/CONSUMER/status is for webhooks that define both a consumer and provider /pacts/provider/PROVIDER/consumer/CONSUMER/webhooks/status will be for all the webhooks for a given pact, including those that only define a single consumer or a single provider
1 parent 42bfa39 commit 2445b1e

File tree

11 files changed

+19
-14
lines changed

11 files changed

+19
-14
lines changed

lib/pact_broker/api.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,17 @@ module PactBroker
5555
add ['pacticipants', :pacticipant_name, 'labels', :label_name], Api::Resources::Label, {resource_name: "pacticipant_label"}
5656

5757
# Webhooks
58-
add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::PactWebhooks, {resource_name: "pact_webhooks"}
58+
add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::PactWebhooks, {resource_name: "consumer_and_provider_webhooks"}
5959
add ['webhooks', 'provider', :provider_name], Api::Resources::PactWebhooks, {resource_name: "provider_webhooks"}
6060
add ['webhooks', 'consumer', :consumer_name], Api::Resources::PactWebhooks, {resource_name: "consumer_webhooks"}
61-
add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name, 'status' ], Api::Resources::PactWebhooksStatus, {resource_name: "pact_webhooks_status"}
61+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'webhooks'], Api::Resources::PactWebhooks, {resource_name: "pact_webhooks"}
62+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'webhooks', 'status'], Api::Resources::PactWebhooksStatus, {resource_name: "pact_webhooks_status"}
6263

6364
add ['webhooks', :uuid ], Api::Resources::Webhook, {resource_name: "webhook"}
6465
add ['webhooks', :uuid, 'trigger', :trigger_uuid, 'logs' ], Api::Resources::TriggeredWebhookLogs, {resource_name: "triggered_webhook_logs"}
6566
add ['webhooks', :uuid, 'execute' ], Api::Resources::WebhookExecution, {resource_name: "execute_webhook"}
66-
add ['webhooks'], Api::Resources::Webhooks, {resource_name: "webhooks"}
67+
add ['webhooks'], Api::Resources::AllWebhooks, {resource_name: "webhooks"}
68+
6769

6870
add ['relationships'], Api::Resources::Relationships, {resource_name: "relationships"}
6971
add ['groups', :pacticipant_name], Api::Resources::Group, {resource_name: "group"}

lib/pact_broker/api/decorators/pact_decorator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def to_hash(options = {})
102102
link :'pb:pact-webhooks' do | options |
103103
{
104104
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))
106106
}
107107
end
108108

lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class PactWebhooksStatusDecorator < BaseDecorator
6363
link :'pb:pact-webhooks' do | context |
6464
{
6565
title: "Webhooks for the pact between #{context[:consumer_name]} and #{context[:provider_name]}",
66-
href: webhooks_for_pact_url(fake_consumer(context), fake_provider(context), context.fetch(:base_url))
66+
href: webhooks_for_consumer_and_provider_url(fake_consumer(context), fake_provider(context), context.fetch(:base_url))
6767
}
6868
end
6969

lib/pact_broker/api/decorators/webhook_decorator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class WebhookEventDecorator < BaseDecorator
6161
if represented.consumer && represented.provider
6262
{
6363
title: "All webhooks for consumer #{represented.consumer.name} and provider #{represented.provider.name}",
64-
href: webhooks_for_pact_url(represented.consumer, represented.provider, options[:base_url])
64+
href: webhooks_for_consumer_and_provider_url(represented.consumer, represented.provider, options[:base_url])
6565
}
6666
end
6767
end

lib/pact_broker/api/pact_broker_urls.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,14 @@ def webhook_execution_url webhook, base_url
152152
"#{base_url}/webhooks/#{webhook.uuid}/execute"
153153
end
154154

155-
def webhooks_for_pact_url consumer, provider, base_url = ''
155+
def webhooks_for_consumer_and_provider_url consumer, provider, base_url = ''
156156
"#{base_url}/webhooks/provider/#{url_encode(provider.name)}/consumer/#{url_encode(consumer.name)}"
157157
end
158158

159+
def webhooks_for_pact_url consumer, provider, base_url = ''
160+
"#{base_url}/pacts/provider/#{url_encode(provider.name)}/consumer/#{url_encode(consumer.name)}/webhooks"
161+
end
162+
159163
def webhooks_status_url consumer, provider, base_url = ''
160164
"#{webhooks_for_pact_url(consumer, provider, base_url)}/status"
161165
end

lib/pact_broker/api/resources/webhooks.rb lib/pact_broker/api/resources/all_webhooks.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module PactBroker
66
module Api
77
module Resources
88

9-
class Webhooks < BaseResource
9+
class AllWebhooks < BaseResource
1010

1111
def content_types_provided
1212
[["application/hal+json", :to_json]]

lib/pact_broker/api/resources/pact_webhooks.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
require 'pact_broker/api/resources/base_resource'
32
require 'pact_broker/api/decorators/webhook_decorator'
43
require 'pact_broker/api/decorators/webhooks_decorator'

lib/pact_broker/api/resources/pact_webhooks_status.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def to_json
2727
private
2828

2929
def latest_triggered_webhooks
30-
@latest_triggered_webhooks ||= webhook_service.find_latest_triggered_webhooks(consumer, provider)
30+
@latest_triggered_webhooks ||= webhook_service.find_latest_triggered_webhooks_for_pact(pact)
3131
end
3232

3333
def pact

lib/pact_broker/ui/view_models/index_item.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def webhook_last_execution_date
9393
def webhook_url
9494
url = case @relationship.webhook_status
9595
when :none
96-
PactBroker::Api::PactBrokerUrls.webhooks_for_pact_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider
96+
PactBroker::Api::PactBrokerUrls.webhooks_for_consumer_and_provider_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider
9797
else
9898
PactBroker::Api::PactBrokerUrls.webhooks_status_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider
9999
end

spec/lib/pact_broker/api/resources/webhooks_spec.rb spec/lib/pact_broker/api/resources/all_webhooks_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
require 'spec_helper'
2-
require 'pact_broker/api/resources/webhooks'
2+
require 'pact_broker/api/resources/all_webhooks'
33

44
module PactBroker::Api
55

66
module Resources
77

8-
describe Webhooks do
8+
describe AllWebhooks do
99

1010
describe "GET" do
1111

spec/lib/pact_broker/ui/view_models/index_item_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module ViewDomain
9292
let(:webhook_status) { :success }
9393
its(:webhook_label) { is_expected.to eq "1 day ago" }
9494
its(:webhook_status) { is_expected.to eq "success" }
95-
its(:webhook_url) { is_expected.to end_with "/webhooks/provider/Provider%20Name/consumer/Consumer%20Name/status"}
95+
its(:webhook_url) { is_expected.to end_with "/pacts/provider/Provider%20Name/consumer/Consumer%20Name/webhooks/status"}
9696
end
9797

9898
context "when the webhooks_status is :failure" do

0 commit comments

Comments
 (0)