diff --git a/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb b/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb index 86c2cbdcc..bcd5baa38 100644 --- a/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +++ b/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb @@ -30,25 +30,33 @@ def initialize(verifiable_pact) property :notices, getter: -> (context) { context[:decorator].notices(context[:options][:user_options]) } property :noteToDevelopers, getter: -> (_) { "Please print out the text from the 'notices' rather than using the inclusionReason and the pendingReason fields. These will be removed when this API moves out of beta."} - def inclusion_reason(pact_url) - PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url).inclusion_reason - end - - def pending_reason(pact_url) - PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url).pending_reason - end - def notices(user_options) + # TODO move this out of the decorator pact_url = pact_version_url(represented, user_options[:base_url]) - mess = [{ - timing: 'pre_verification', - text: inclusion_reason(pact_url) + messages = PactBroker::Pacts::VerifiablePactMessages.new(represented, pact_url) + + the_notices = [{ + when: 'before_verification', + text: messages.inclusion_reason }] - mess << { - timing: 'pre_verification', - text: pending_reason(pact_url) - } if user_options[:include_pending_status] - mess + + if user_options[:include_pending_status] + append_notice(the_notices, 'before_verification', messages.pending_reason) + append_notice(the_notices, 'after_verification:success_true_published_false', messages.verification_success_true_published_false) + append_notice(the_notices, 'after_verification:success_false_published_false', messages.verification_success_false_published_false) + append_notice(the_notices, 'after_verification:success_true_published_true', messages.verification_success_true_published_true) + append_notice(the_notices, 'after_verification:success_false_published_true', messages.verification_success_false_published_true) + end + the_notices + end + + def append_notice the_notices, the_when, text + if text + the_notices << { + when: the_when, + text: text + } + end end end diff --git a/lib/pact_broker/pacts/verifiable_pact_messages.rb b/lib/pact_broker/pacts/verifiable_pact_messages.rb index 24a02defc..9bd73fc60 100644 --- a/lib/pact_broker/pacts/verifiable_pact_messages.rb +++ b/lib/pact_broker/pacts/verifiable_pact_messages.rb @@ -35,6 +35,28 @@ def pending_reason end end + def verification_success_true_published_false + if pending? + "This pact is still in pending state for #{pending_provider_tags_description} as the successful verification results #{with_these_tags}have not yet been published." + end + end + + def verification_success_true_published_true + if pending? + "This pact is no longer in pending state for #{pending_provider_tags_description}, as a successful verification result #{with_these_tags}has been published. If a verification for a version with fails in the future, it will fail the build. #{READ_MORE_PENDING}" + end + end + + def verification_success_false_published_false + if pending? + "This pact is still in pending state for #{pending_provider_tags_description} as a successful verification result #{with_these_tags}has not yet been published" + end + end + + def verification_success_false_published_true + verification_success_false_published_false + end + private attr_reader :verifiable_pact, :pact_version_url @@ -77,6 +99,14 @@ def non_pending_provider_tags_description else "a version of #{provider_name} with tag #{join(non_pending_provider_tags)}" end end + + def with_these_tags + case pending_provider_tags.size + when 0 then "" + when 1 then "with this tag " + else "with these tags " + end + end end end end