diff --git a/lib/pact_broker/api.rb b/lib/pact_broker/api.rb index ab246ad23..c504add46 100644 --- a/lib/pact_broker/api.rb +++ b/lib/pact_broker/api.rb @@ -55,15 +55,17 @@ module PactBroker add ['pacticipants', :pacticipant_name, 'labels', :label_name], Api::Resources::Label, {resource_name: "pacticipant_label"} # Webhooks - add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::PactWebhooks, {resource_name: "pact_webhooks"} + add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::PactWebhooks, {resource_name: "consumer_and_provider_webhooks"} add ['webhooks', 'provider', :provider_name], Api::Resources::PactWebhooks, {resource_name: "provider_webhooks"} add ['webhooks', 'consumer', :consumer_name], Api::Resources::PactWebhooks, {resource_name: "consumer_webhooks"} - add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name, 'status' ], Api::Resources::PactWebhooksStatus, {resource_name: "pact_webhooks_status"} + add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'webhooks'], Api::Resources::PactWebhooks, {resource_name: "pact_webhooks"} + add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'webhooks', 'status'], Api::Resources::PactWebhooksStatus, {resource_name: "pact_webhooks_status"} add ['webhooks', :uuid ], Api::Resources::Webhook, {resource_name: "webhook"} add ['webhooks', :uuid, 'trigger', :trigger_uuid, 'logs' ], Api::Resources::TriggeredWebhookLogs, {resource_name: "triggered_webhook_logs"} add ['webhooks', :uuid, 'execute' ], Api::Resources::WebhookExecution, {resource_name: "execute_webhook"} - add ['webhooks'], Api::Resources::Webhooks, {resource_name: "webhooks"} + add ['webhooks'], Api::Resources::AllWebhooks, {resource_name: "webhooks"} + add ['relationships'], Api::Resources::Relationships, {resource_name: "relationships"} add ['groups', :pacticipant_name], Api::Resources::Group, {resource_name: "group"} diff --git a/lib/pact_broker/api/decorators/pact_decorator.rb b/lib/pact_broker/api/decorators/pact_decorator.rb index 06bbbbde5..bd9b03456 100644 --- a/lib/pact_broker/api/decorators/pact_decorator.rb +++ b/lib/pact_broker/api/decorators/pact_decorator.rb @@ -102,7 +102,7 @@ def to_hash(options = {}) link :'pb:pact-webhooks' do | options | { title: "Webhooks for the pact between #{represented.consumer.name} and #{represented.provider.name}", - href: webhooks_for_pact_url(represented.consumer, represented.provider, options.fetch(:base_url)) + href: webhooks_for_consumer_and_provider_url(represented.consumer, represented.provider, options.fetch(:base_url)) } end diff --git a/lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb b/lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb index eec973e4b..2db45f3cf 100644 --- a/lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb +++ b/lib/pact_broker/api/decorators/pact_webhooks_status_decorator.rb @@ -63,7 +63,7 @@ class PactWebhooksStatusDecorator < BaseDecorator link :'pb:pact-webhooks' do | context | { title: "Webhooks for the pact between #{context[:consumer_name]} and #{context[:provider_name]}", - href: webhooks_for_pact_url(fake_consumer(context), fake_provider(context), context.fetch(:base_url)) + href: webhooks_for_consumer_and_provider_url(fake_consumer(context), fake_provider(context), context.fetch(:base_url)) } end diff --git a/lib/pact_broker/api/decorators/webhook_decorator.rb b/lib/pact_broker/api/decorators/webhook_decorator.rb index a6582e602..de79b3fde 100644 --- a/lib/pact_broker/api/decorators/webhook_decorator.rb +++ b/lib/pact_broker/api/decorators/webhook_decorator.rb @@ -61,7 +61,7 @@ class WebhookEventDecorator < BaseDecorator if represented.consumer && represented.provider { title: "All webhooks for consumer #{represented.consumer.name} and provider #{represented.provider.name}", - href: webhooks_for_pact_url(represented.consumer, represented.provider, options[:base_url]) + href: webhooks_for_consumer_and_provider_url(represented.consumer, represented.provider, options[:base_url]) } end end diff --git a/lib/pact_broker/api/pact_broker_urls.rb b/lib/pact_broker/api/pact_broker_urls.rb index 23dc99db5..429b8a31a 100644 --- a/lib/pact_broker/api/pact_broker_urls.rb +++ b/lib/pact_broker/api/pact_broker_urls.rb @@ -152,10 +152,14 @@ def webhook_execution_url webhook, base_url "#{base_url}/webhooks/#{webhook.uuid}/execute" end - def webhooks_for_pact_url consumer, provider, base_url = '' + def webhooks_for_consumer_and_provider_url consumer, provider, base_url = '' "#{base_url}/webhooks/provider/#{url_encode(provider.name)}/consumer/#{url_encode(consumer.name)}" end + def webhooks_for_pact_url consumer, provider, base_url = '' + "#{base_url}/pacts/provider/#{url_encode(provider.name)}/consumer/#{url_encode(consumer.name)}/webhooks" + end + def webhooks_status_url consumer, provider, base_url = '' "#{webhooks_for_pact_url(consumer, provider, base_url)}/status" end diff --git a/lib/pact_broker/api/resources/webhooks.rb b/lib/pact_broker/api/resources/all_webhooks.rb similarity index 93% rename from lib/pact_broker/api/resources/webhooks.rb rename to lib/pact_broker/api/resources/all_webhooks.rb index 70513ede4..4f54c7ec9 100644 --- a/lib/pact_broker/api/resources/webhooks.rb +++ b/lib/pact_broker/api/resources/all_webhooks.rb @@ -6,7 +6,7 @@ module PactBroker module Api module Resources - class Webhooks < BaseResource + class AllWebhooks < BaseResource def content_types_provided [["application/hal+json", :to_json]] diff --git a/lib/pact_broker/api/resources/pact_webhooks.rb b/lib/pact_broker/api/resources/pact_webhooks.rb index bd68ae2f8..26a219ae4 100644 --- a/lib/pact_broker/api/resources/pact_webhooks.rb +++ b/lib/pact_broker/api/resources/pact_webhooks.rb @@ -1,4 +1,3 @@ - require 'pact_broker/api/resources/base_resource' require 'pact_broker/api/decorators/webhook_decorator' require 'pact_broker/api/decorators/webhooks_decorator' diff --git a/lib/pact_broker/api/resources/pact_webhooks_status.rb b/lib/pact_broker/api/resources/pact_webhooks_status.rb index 307ea09ad..490858153 100644 --- a/lib/pact_broker/api/resources/pact_webhooks_status.rb +++ b/lib/pact_broker/api/resources/pact_webhooks_status.rb @@ -27,7 +27,7 @@ def to_json private def latest_triggered_webhooks - @latest_triggered_webhooks ||= webhook_service.find_latest_triggered_webhooks(consumer, provider) + @latest_triggered_webhooks ||= webhook_service.find_latest_triggered_webhooks_for_pact(pact) end def pact diff --git a/lib/pact_broker/ui/view_models/index_item.rb b/lib/pact_broker/ui/view_models/index_item.rb index b8aa124b7..c24c83463 100644 --- a/lib/pact_broker/ui/view_models/index_item.rb +++ b/lib/pact_broker/ui/view_models/index_item.rb @@ -93,7 +93,7 @@ def webhook_last_execution_date def webhook_url url = case @relationship.webhook_status when :none - PactBroker::Api::PactBrokerUrls.webhooks_for_pact_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider + PactBroker::Api::PactBrokerUrls.webhooks_for_consumer_and_provider_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider else PactBroker::Api::PactBrokerUrls.webhooks_status_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider end diff --git a/spec/lib/pact_broker/api/resources/webhooks_spec.rb b/spec/lib/pact_broker/api/resources/all_webhooks_spec.rb similarity index 93% rename from spec/lib/pact_broker/api/resources/webhooks_spec.rb rename to spec/lib/pact_broker/api/resources/all_webhooks_spec.rb index 578fff679..aa1c44638 100644 --- a/spec/lib/pact_broker/api/resources/webhooks_spec.rb +++ b/spec/lib/pact_broker/api/resources/all_webhooks_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -require 'pact_broker/api/resources/webhooks' +require 'pact_broker/api/resources/all_webhooks' module PactBroker::Api module Resources - describe Webhooks do + describe AllWebhooks do describe "GET" do diff --git a/spec/lib/pact_broker/ui/view_models/index_item_spec.rb b/spec/lib/pact_broker/ui/view_models/index_item_spec.rb index 355a14c8b..ec29f76cc 100644 --- a/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +++ b/spec/lib/pact_broker/ui/view_models/index_item_spec.rb @@ -92,7 +92,7 @@ module ViewDomain let(:webhook_status) { :success } its(:webhook_label) { is_expected.to eq "1 day ago" } its(:webhook_status) { is_expected.to eq "success" } - its(:webhook_url) { is_expected.to end_with "/webhooks/provider/Provider%20Name/consumer/Consumer%20Name/status"} + its(:webhook_url) { is_expected.to end_with "/pacts/provider/Provider%20Name/consumer/Consumer%20Name/webhooks/status"} end context "when the webhooks_status is :failure" do