diff --git a/lib/pact_broker/api/pact_broker_urls.rb b/lib/pact_broker/api/pact_broker_urls.rb index bd19716f9..94a4679a7 100644 --- a/lib/pact_broker/api/pact_broker_urls.rb +++ b/lib/pact_broker/api/pact_broker_urls.rb @@ -4,6 +4,8 @@ module PactBroker module Api module PactBrokerUrls + # TODO make base_url the last and optional argument for all methods, defaulting to '' + extend self def pacticipants_url base_url @@ -14,6 +16,14 @@ def pacticipant_url base_url, pacticipant "#{pacticipants_url(base_url)}/#{url_encode(pacticipant.name)}" end + def pacticipant_url_from_params params, base_url = '' + [ + base_url, + 'pacticipants', + url_encode(params.fetch(:pacticipant_name)) + ].join("/") + end + def latest_version_url base_url, pacticipant "#{pacticipant_url(base_url, pacticipant)}/versions/latest" end @@ -26,6 +36,16 @@ def version_url base_url, version "#{pacticipant_url(base_url, version.pacticipant)}/versions/#{version.number}" end + def version_url_from_params params, base_url = '' + [ + base_url, + 'pacticipants', + url_encode(params.fetch(:pacticipant_name)), + 'versions', + url_encode(params.fetch(:version_number)), + ].join("/") + end + def pact_url base_url, pact "#{pactigration_base_url(base_url, pact)}/version/#{pact.consumer_version_number}" end diff --git a/lib/pact_broker/ui/view_models/matrix_line.rb b/lib/pact_broker/ui/view_models/matrix_line.rb index 7e33f4963..5af6a490a 100644 --- a/lib/pact_broker/ui/view_models/matrix_line.rb +++ b/lib/pact_broker/ui/view_models/matrix_line.rb @@ -18,17 +18,25 @@ def provider_name @line[:provider_name] end + def provider_name_url + hal_browser_url(pacticipant_url_from_params(pacticipant_name: provider_name)) + end + def consumer_name @line[:consumer_name] end + def consumer_name_url + hal_browser_url(pacticipant_url_from_params(pacticipant_name: consumer_name)) + end + def pact_version_sha @line[:pact_version_sha] end - # verification number + # verification number, used in verification_url method def number - @line[:number] + @line[:verification_number] end def consumer_name @@ -40,7 +48,8 @@ def consumer_version_number end def consumer_version_number_url - pact_url_from_params('', @line) + params = { pacticipant_name: consumer_name, version_number: consumer_version_number } + hal_browser_url(version_url_from_params(params)) end def consumer_version_order @@ -60,7 +69,8 @@ def provider_version_order end def provider_version_number_url - hal_browser_url(verification_url(self)) + params = { pacticipant_name: provider_name, version_number: provider_version_number } + hal_browser_url(version_url_from_params(params)) end def provider_version_order @@ -116,10 +126,18 @@ def verification_status # end end + def verification_status_url + hal_browser_url(verification_url(self)) + end + def pact_publication_date relative_date(@line[:pact_created_at]) end + def pact_publication_date_url + pact_url_from_params('', @line) + end + def relative_date date DateHelper.distance_of_time_in_words(date, DateTime.now) + " ago" end diff --git a/lib/pact_broker/ui/views/matrix/show.haml b/lib/pact_broker/ui/views/matrix/show.haml index ee31cdc1d..8178facc2 100644 --- a/lib/pact_broker/ui/views/matrix/show.haml +++ b/lib/pact_broker/ui/views/matrix/show.haml @@ -97,7 +97,8 @@ - lines.each do | line | %tr %td.consumer{'data-sort-value' => line.consumer_name} - = line.consumer_name + %a{href: line.consumer_name_url} + = line.consumer_name %td.consumer-version{'data-sort-value' => line.consumer_version_order} %div %a{href: line.consumer_version_number_url} @@ -113,9 +114,11 @@ .tag.label.label-default = tag.name %td.pact-published{'data-sort-value' => line.pact_published_order} - = line.pact_publication_date + %a{href: line.pact_publication_date_url} + = line.pact_publication_date %td.provider{'data-sort-value' => line.provider_name} - = line.provider_name + %a{href: line.provider_name_url} + = line.provider_name %td.provider-version{'data-sort-value' => line.provider_version_order} %div %a{href: line.provider_version_number_url} @@ -131,4 +134,5 @@ .tag.label.label-default = tag.name %td.verification-result{class: line.verification_status_class} - = line.verification_status + %a{href: line.verification_status_url} + = line.verification_status