Skip to content

Commit a240852

Browse files
committed
feat: allow dashboard resource to be filtered by consumer/provider
1 parent 0166930 commit a240852

File tree

7 files changed

+48
-3
lines changed

7 files changed

+48
-3
lines changed

lib/pact_broker/api.rb

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module PactBroker
8484
add ['matrix'], Api::Resources::Matrix, {resource_name: "matrix"}
8585

8686
add ['dashboard'], Api::Resources::Dashboard, {resource_name: "dashboard"}
87+
add ['dashboard', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::Dashboard, {resource_name: "integration_dashboard"}
8788
add ['test','error'], Api::Resources::ErrorTest, {resource_name: "error_test"}
8889

8990
add ['integrations'], Api::Resources::Integrations, {resource_name: "integrations"}

lib/pact_broker/api/decorators/integration_decorator.rb

+10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
require_relative 'base_decorator'
2+
require 'pact_broker/api/pact_broker_urls'
23

34
module PactBroker
45
module Api
56
module Decorators
67
class IntegrationDecorator < BaseDecorator
8+
include PactBroker::Api::PactBrokerUrls
9+
710
property :consumer do
811
property :name
912
end
1013

1114
property :provider do
1215
property :name
1316
end
17+
18+
link "pb:dashboard" do | options |
19+
{
20+
title: "BETA: Pacts to show on the dashboard",
21+
href: dashboard_url_for_integration(represented.consumer.name, represented.provider.name, options.fetch(:base_url))
22+
}
23+
end
1424
end
1525
end
1626
end

lib/pact_broker/api/pact_broker_urls.rb

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def integration_url consumer_name, provider_name, base_url = ""
8181
"#{base_url}/integrations/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}"
8282
end
8383

84+
def dashboard_url_for_integration consumer_name, provider_name, base_url = ""
85+
"#{base_url}/dashboard/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}"
86+
end
87+
8488
def previous_distinct_diff_url pact, base_url
8589
pact_url(base_url, pact) + "/diff/previous-distinct"
8690
end

lib/pact_broker/api/resources/dashboard.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def to_text
3030
private
3131

3232
def index_items
33-
index_service.find_index_items(tags: true)
33+
index_service.find_index_items(identifier_from_path.merge(tags: true))
3434
end
3535
end
3636
end

lib/pact_broker/index/service.rb

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def self.find_index_items options = {}
1919
.eager(:latest_triggered_webhooks)
2020
.eager(:webhooks)
2121

22+
rows = rows.consumer(options[:consumer_name]) if options[:consumer_name]
23+
rows = rows.provider(options[:provider_name]) if options[:provider_name]
24+
2225
if !options[:tags]
2326
rows = rows.where(consumer_version_tag_name: nil)
2427
else

lib/pact_broker/matrix/row.rb

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ class Row < Sequel::Model(:matrix)
2525
include PactBroker::Repositories::Helpers
2626
include PactBroker::Logging
2727

28+
def consumer consumer_name
29+
where(name_like(:consumer_name, consumer_name))
30+
end
31+
32+
def provider provider_name
33+
where(name_like(:provider_name, provider_name))
34+
end
35+
2836
def matching_selectors selectors
2937
if selectors.size == 1
3038
where_consumer_or_provider_is(selectors.first)

spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb

+21-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ module PactBroker
55
module Api
66
module Decorators
77
describe IntegrationDecorator do
8+
before do
9+
allow(integration_decorator).to receive(:dashboard_url_for_integration).and_return("/dashboard")
10+
end
11+
812
let(:integration) do
913
instance_double(PactBroker::Integrations::Integration,
1014
consumer: consumer,
@@ -13,24 +17,39 @@ module Decorators
1317
end
1418
let(:consumer) { double("consumer", name: "the consumer") }
1519
let(:provider) { double("provider", name: "the provider") }
16-
20+
let(:options) { { user_options: { base_url: 'http://example.org' } } }
1721
let(:expected_hash) do
1822
{
1923
"consumer" => {
2024
"name" => "the consumer"
2125
},
2226
"provider" => {
2327
"name" => "the provider"
28+
},
29+
"_links" => {
30+
"pb:dashboard" => {
31+
"href" => "/dashboard"
32+
}
2433
}
2534
}
2635
end
2736

28-
let(:json) { IntegrationDecorator.new(integration).to_json }
37+
let(:integration_decorator) { IntegrationDecorator.new(integration) }
38+
let(:json) { integration_decorator.to_json(options) }
2939
subject { JSON.parse(json) }
3040

3141
it "generates a hash" do
3242
expect(subject).to match_pact expected_hash
3343
end
44+
45+
it "generates the correct link for the dashboard" do
46+
expect(integration_decorator).to receive(:dashboard_url_for_integration).with(
47+
"the consumer",
48+
"the provider",
49+
"http://example.org"
50+
)
51+
subject
52+
end
3453
end
3554
end
3655
end

0 commit comments

Comments
 (0)