lib/pact_broker/pacts/diff.rb in pact_broker-1.14.0 vs lib/pact_broker/pacts/diff.rb in pact_broker-1.15.0

- old
+ new

@@ -1,41 +1,41 @@ -require 'trailblazer/operation' -require 'pact_broker/repositories' -require 'pact_broker/pacts/create_formatted_diff' require 'pact_broker/api/pact_broker_urls' -require 'yaml' require 'pact_broker/date_helper' +require 'pact_broker/pacts/create_formatted_diff' +require 'pact_broker/repositories' +require 'yaml' - module PactBroker module Pacts - class Diff < Trailblazer::Operation - + class Diff include PactBroker::Repositories - attr_reader :params, :options - def process params, options - pact = pact_repository.find_pact(params.consumer_name, params.consumer_version_number, params.provider_name) - previous_distinct_pact = pact_repository.find_previous_distinct_pact pact - @output = if previous_distinct_pact - next_pact = pact_repository.find_next_pact previous_distinct_pact - DiffDecorator.new(pact, previous_distinct_pact, next_pact, options[:base_url]).to_text + def process(params) + pact = find_pact(params) + previous_distinct_pact = pact_repository.find_previous_distinct_pact(pact) + + if previous_distinct_pact + next_pact = pact_repository.find_next_pact(previous_distinct_pact) + DiffDecorator.new(pact, previous_distinct_pact, next_pact, params[:base_url]).to_text else no_previous_version_message pact end end - def no_previous_version_message pact - "No previous distinct version was found for #{pact.name}" + private + + def find_pact(params) + pact_repository.find_pact(params.consumer_name, + params.consumer_version_number, + params.provider_name) end - def output - @output + def no_previous_version_message(pact) + "No previous distinct version was found for #{pact.name}" end - private # The next pact version after the previous distinct version. # Eg. v1 (previous distinct) -> pactContentA # v2 (next pact) -> pactContentB # v3 -> pactContentB @@ -44,14 +44,11 @@ # v1, and the next pact after that is v2. # The timestamps on v2 are the ones we want - that's when # the latest distinct version content was first created. class DiffDecorator - - attr_reader :pact, :previous_distinct_pact, :next_pact, :base_url - - def initialize pact, previous_distinct_pact, next_pact, base_url + def initialize(pact, previous_distinct_pact, next_pact, base_url) @pact = pact @previous_distinct_pact = previous_distinct_pact @next_pact = next_pact @base_url = base_url end @@ -60,10 +57,12 @@ header + "\n\n" + diff + "\n\n" + links end private + attr_reader :pact, :previous_distinct_pact, :next_pact, :base_url + def change_date_in_words DateHelper.local_date_in_words next_pact.updated_at end def now @@ -71,16 +70,17 @@ end def header title = "# Diff between versions #{previous_distinct_pact.consumer_version_number} and #{pact.consumer_version_number} of the pact between #{pact.consumer.name} and #{pact.provider.name}" description = "The following changes were made #{change_date_ago_in_words} ago (#{change_date_in_words})" + title + "\n\n" + description end def links - self_url = PactBroker::Api::PactBrokerUrls.pact_url base_url, pact - previous_distinct_url = PactBroker::Api::PactBrokerUrls.pact_url base_url, previous_distinct_pact + self_url = PactBroker::Api::PactBrokerUrls.pact_url(base_url, pact) + previous_distinct_url = PactBroker::Api::PactBrokerUrls.pact_url(base_url, previous_distinct_pact) links = { "current-pact-version" => { "title" => "Pact", "name" => pact.name, @@ -101,9 +101,8 @@ def change_date_ago_in_words DateHelper.distance_of_time_in_words next_pact.updated_at, now end end - end end end