Skip to content

Commit

Permalink
feat(consumer or provider webhooks): change pact webhook status URL
Browse files Browse the repository at this point in the history
/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
  • Loading branch information
bethesque committed Jun 16, 2018
1 parent 42bfa39 commit 2445b1e
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 14 deletions.
8 changes: 5 additions & 3 deletions lib/pact_broker/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/decorators/pact_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/decorators/webhook_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/pact_broker/api/pact_broker_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
1 change: 0 additions & 1 deletion lib/pact_broker/api/resources/pact_webhooks.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/resources/pact_webhooks_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/ui/view_models/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/ui/view_models/index_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2445b1e

Please sign in to comment.