diff --git a/lib/pact_broker/api/decorators/publish_contracts_results_decorator.rb b/lib/pact_broker/api/decorators/publish_contracts_results_decorator.rb index ebaa200f0..6619c2cab 100644 --- a/lib/pact_broker/api/decorators/publish_contracts_results_decorator.rb +++ b/lib/pact_broker/api/decorators/publish_contracts_results_decorator.rb @@ -8,7 +8,8 @@ module Decorators class PublishContractsResultsDecorator < BaseDecorator camelize_property_names - property :logs, getter: ->(represented:, **) { represented.logs.collect(&:to_h) } + property :logs, getter: ->(represented:, **) { represented.notices.collect{ | notice | { level: notice.type, message: notice.text, deprecationWarning: "Replaced by notices" } } } + property :notices, getter: ->(represented:, **) { represented.notices.collect(&:to_h) } property :pacticipant, embedded: true, extend: EmbeddedPacticipantDecorator property :version, embedded: true, extend: EmbeddedVersionDecorator diff --git a/lib/pact_broker/contracts/contracts_publication_results.rb b/lib/pact_broker/contracts/contracts_publication_results.rb index 301aecb56..15862b668 100644 --- a/lib/pact_broker/contracts/contracts_publication_results.rb +++ b/lib/pact_broker/contracts/contracts_publication_results.rb @@ -1,12 +1,12 @@ module PactBroker module Contracts - ContractsPublicationResults = Struct.new(:pacticipant, :version, :tags, :contracts, :logs) do + ContractsPublicationResults = Struct.new(:pacticipant, :version, :tags, :contracts, :notices) do def self.from_hash(params) new(params[:pacticipant], params[:version], params[:tags], params[:contracts], - params[:logs] + params[:notices] ) end end diff --git a/lib/pact_broker/contracts/log_message.rb b/lib/pact_broker/contracts/log_message.rb deleted file mode 100644 index d6a3689ae..000000000 --- a/lib/pact_broker/contracts/log_message.rb +++ /dev/null @@ -1,17 +0,0 @@ -module PactBroker - module Contracts - LogMessage = Struct.new(:level, :message) do - def self.info(message) - LogMessage.new("info", message) - end - - def self.warn(message) - LogMessage.new("warn", message) - end - - def self.debug(message) - LogMessage.new("debug", message) - end - end - end -end diff --git a/lib/pact_broker/contracts/notice.rb b/lib/pact_broker/contracts/notice.rb new file mode 100644 index 000000000..a5084c7ad --- /dev/null +++ b/lib/pact_broker/contracts/notice.rb @@ -0,0 +1,21 @@ +module PactBroker + module Contracts + Notice = Struct.new(:type, :text) do + def self.info(text) + Notice.new("info", text) + end + + def self.debug(text) + Notice.new("debug", text) + end + + def self.warning(text) + Notice.new("warning", text) + end + + def self.success(text) + Notice.new("success", text) + end + end + end +end diff --git a/lib/pact_broker/contracts/service.rb b/lib/pact_broker/contracts/service.rb index da073d211..0b77c4e06 100644 --- a/lib/pact_broker/contracts/service.rb +++ b/lib/pact_broker/contracts/service.rb @@ -3,7 +3,7 @@ require 'pact_broker/services' require 'pact_broker/messages' require 'pact_broker/contracts/contracts_publication_results' -require 'pact_broker/contracts/log_message' +require 'pact_broker/contracts/notice' require 'pact_broker/events/subscriber' require 'pact_broker/api/pact_broker_urls' @@ -29,16 +29,16 @@ def triggered_webhooks_created_for_event(params) end def publish(parsed_contracts, base_url: ) - version, version_logs = create_version(parsed_contracts) + version, version_notices = create_version(parsed_contracts) tags = create_tags(parsed_contracts, version) - pacts, pact_logs = create_pacts(parsed_contracts, base_url) - logs = version_logs + pact_logs + pacts, pact_notices = create_pacts(parsed_contracts, base_url) + notices = version_notices + pact_notices ContractsPublicationResults.from_hash( pacticipant: version.pacticipant, version: version, tags: tags, contracts: pacts, - logs: logs + notices: notices ) end @@ -50,7 +50,7 @@ def create_version(parsed_contracts) existing_version = find_existing_version(parsed_contracts) version = create_or_update_version(parsed_contracts, version_params) - return version, log_messages_for_version_creation(existing_version, parsed_contracts) + return version, notices_for_version_creation(existing_version, parsed_contracts) end private :create_version @@ -83,16 +83,16 @@ def create_tags(parsed_contracts, version) private :create_tags def create_pacts(parsed_contracts, base_url) - logs = [] + notices = [] pacts = parsed_contracts.contracts.select(&:pact?).collect do | contract_to_publish | pact_params = create_pact_params(parsed_contracts, contract_to_publish) existing_pact = pact_service.find_pact(pact_params) listener = TriggeredWebhooksCreatedListener.new created_pact = create_or_merge_pact(contract_to_publish.merge?, existing_pact, pact_params, listener) - logs.concat(log_messages_for_pact(parsed_contracts, contract_to_publish, existing_pact, created_pact, listener, base_url)) + notices.concat(notices_for_pact(parsed_contracts, contract_to_publish, existing_pact, created_pact, listener, base_url)) created_pact end - return pacts, logs + return pacts, notices end private :create_pacts @@ -120,23 +120,23 @@ def create_or_merge_pact(merge, existing_pact, pact_params, listener) private :create_or_merge_pact - def log_messages_for_version_creation(existing_version, parsed_contracts) - logs = [] + def notices_for_version_creation(existing_version, parsed_contracts) + notices = [] message_params = parsed_contracts.to_h if parsed_contracts.tags&.any? message_params[:tags] = parsed_contracts.tags.join(", ") end message_params[:action] = existing_version ? "Updated" : "Created" - logs << LogMessage.debug(message(log_message_key_for_version_creation(parsed_contracts), message_params)) + notices << Notice.debug(message(message_key_for_version_creation(parsed_contracts), message_params)) if parsed_contracts.branch.nil? - logs << LogMessage.warn(" Next steps:\n " + message("messages.next_steps.version_branch")) + notices << Notice.warning(" Next steps:\n " + message("messages.next_steps.version_branch")) end - logs + notices end - private :log_messages_for_version_creation + private :notices_for_version_creation - def log_message_key_for_version_creation(parsed_contracts) + def message_key_for_version_creation(parsed_contracts) if parsed_contracts.branch && parsed_contracts.tags&.any? "messages.version.created_for_branch_with_tags" elsif parsed_contracts.branch @@ -148,62 +148,62 @@ def log_message_key_for_version_creation(parsed_contracts) end end - private :log_message_key_for_version_creation + private :message_key_for_version_creation - def log_messages_for_pact(parsed_contracts, contract_to_publish, existing_pact, created_pact, listener, base_url) - logs = [] - logs << log_mesage_for_pact_publication(parsed_contracts, contract_to_publish.merge?, existing_pact, created_pact) - logs << log_message_for_pact_url(created_pact, base_url) - logs.concat(event_and_webhook_logs(listener, created_pact)) - logs.concat(next_steps_logs(created_pact)) - logs + def notices_for_pact(parsed_contracts, contract_to_publish, existing_pact, created_pact, listener, base_url) + notices = [] + notices << notice_for_pact_publication(parsed_contracts, contract_to_publish.merge?, existing_pact, created_pact) + notices << notice_for_pact_url(created_pact, base_url) + notices.concat(event_and_webhook_notices(listener, created_pact)) + notices.concat(next_steps_notices(created_pact)) + notices end - private :log_messages_for_pact + private :notices_for_pact - def log_mesage_for_pact_publication(parsed_contracts, merge, existing_pact, created_pact) - log_message_params = { + def notice_for_pact_publication(parsed_contracts, merge, existing_pact, created_pact) + message_params = { consumer_name: parsed_contracts.pacticipant_name, consumer_version_number: parsed_contracts.pacticipant_version_number, provider_name: created_pact.provider_name } if merge if existing_pact - LogMessage.info(message("messages.contract.pact_merged", log_message_params)) + Notice.success(message("messages.contract.pact_merged", message_params)) else - LogMessage.info(message("messages.contract.pact_published", log_message_params)) + Notice.success(message("messages.contract.pact_published", message_params)) end else if existing_pact if existing_pact.pact_version_sha != created_pact.pact_version_sha - LogMessage.warn(message("messages.contract.pact_modified_for_same_version", log_message_params)) + Notice.warning(message("messages.contract.pact_modified_for_same_version", message_params)) else - LogMessage.info(message("messages.contract.same_pact_content_published", log_message_params)) + Notice.success(message("messages.contract.same_pact_content_published", message_params)) end else - LogMessage.info(message("messages.contract.pact_published", log_message_params)) + Notice.success(message("messages.contract.pact_published", message_params)) end end end - private :log_mesage_for_pact_publication + private :notice_for_pact_publication - def log_message_for_pact_url(pact, base_url) - LogMessage.debug(" View the published pact at #{PactBroker::Api::PactBrokerUrls.pact_url(base_url, pact)}") + def notice_for_pact_url(pact, base_url) + Notice.debug(" View the published pact at #{PactBroker::Api::PactBrokerUrls.pact_url(base_url, pact)}") end - private :log_message_for_pact_url + private :notice_for_pact_url - def event_and_webhook_logs(listener, pact) - event_descriptions(listener) + triggered_webhook_logs(listener, pact) + def event_and_webhook_notices(listener, pact) + event_descriptions(listener) + triggered_webhook_notices(listener, pact) end - private :event_and_webhook_logs + private :event_and_webhook_notices def event_descriptions(listener) event_descriptions = listener.detected_events.collect{ | event | event.name + (event.comment ? " (#{event.comment})" : "") } if event_descriptions.any? - [LogMessage.debug(" Events detected: " + event_descriptions.join(", "))] + [Notice.debug(" Events detected: " + event_descriptions.join(", "))] else [] end @@ -212,40 +212,40 @@ def event_descriptions(listener) private :event_descriptions # TODO add can-i-deploy and record-deployment - def next_steps_logs(pact) - logs = [] + def next_steps_notices(pact) + notices = [] if !verification_service.any_verifications?(pact.consumer, pact.provider) - logs << LogMessage.warn(" * " + message("messages.next_steps.verifications", provider_name: pact.provider_name)) + notices << Notice.warning(" * " + message("messages.next_steps.verifications", provider_name: pact.provider_name)) end if !webhook_service.any_webhooks_configured_for_pact?(pact) - logs << LogMessage.warn(" * " + message("messages.next_steps.webhooks", provider_name: pact.provider_name)) + notices << Notice.warning(" * " + message("messages.next_steps.webhooks", provider_name: pact.provider_name)) end - if logs.any? - logs.unshift(LogMessage.warn(" Next steps:")) + if notices.any? + notices.unshift(Notice.warning(" Next steps:")) end - logs + notices end - private :next_steps_logs + private :next_steps_notices - def triggered_webhook_logs(listener, pact) + def triggered_webhook_notices(listener, pact) triggered_webhooks = listener.detected_events.flat_map(&:triggered_webhooks) if triggered_webhooks.any? triggered_webhooks.collect do | triggered_webhook | base_url = triggered_webhook.event_context[:base_url] - triggered_webhooks_logs_url = url_for_triggered_webhook(triggered_webhook, base_url) + triggered_webhooks_notices_url = url_for_triggered_webhook(triggered_webhook, base_url) text_2_params = { webhook_description: triggered_webhook.webhook.description&.inspect || triggered_webhook.webhook_uuid, event_name: triggered_webhook.event_name } text_1 = message("messages.webhooks.webhook_triggered_for_event", text_2_params) - text_2 = message("messages.webhooks.triggered_webhook_see_logs", url: triggered_webhooks_logs_url) - LogMessage.debug(" #{text_1}\n #{text_2}") + text_2 = message("messages.webhooks.triggered_webhook_see_notices", url: triggered_webhooks_notices_url) + Notice.debug(" #{text_1}\n #{text_2}") end else if webhook_service.any_webhooks_configured_for_pact?(pact) # There are some webhooks, just not any for this particular event - [LogMessage.debug(" " + message("messages.webhooks.no_webhooks_enabled_for_event"))] + [Notice.debug(" " + message("messages.webhooks.no_webhooks_enabled_for_event"))] else [] end diff --git a/spec/fixtures/approvals/publish_contract_no_branch.approved.json b/spec/fixtures/approvals/publish_contract_no_branch.approved.json index 67878222d..98c2abb3d 100644 --- a/spec/fixtures/approvals/publish_contract_no_branch.approved.json +++ b/spec/fixtures/approvals/publish_contract_no_branch.approved.json @@ -30,41 +30,83 @@ "status": 200, "headers": { "Content-Type": "application/hal+json;charset=utf-8", - "Content-Length": "1876" + "Content-Length": "3235" }, "body": { "logs": [ { "level": "debug", - "message": "Created Foo version 1 with tags a, b" + "message": "Created Foo version 1 with tags a, b", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " Next steps:\n Configure the version branch to be the value of your repository branch." + "level": "warning", + "message": " Next steps:\n Configure the version branch to be the value of your repository branch.", + "deprecationWarning": "Replaced by notices" }, { - "level": "info", - "message": "Pact successfully published for Foo version 1 and provider Bar." + "level": "success", + "message": "Pact successfully published for Foo version 1 and provider Bar.", + "deprecationWarning": "Replaced by notices" }, { "level": "debug", - "message": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1" + "message": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1", + "deprecationWarning": "Replaced by notices" }, { "level": "debug", - "message": " Events detected: contract_published, contract_content_changed (first time any pact published for this consumer with consumer version tagged a, first time any pact published for this consumer with consumer version tagged b)" + "message": " Events detected: contract_published, contract_content_changed (first time any pact published for this consumer with consumer version tagged a, first time any pact published for this consumer with consumer version tagged b)", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " Next steps:" + "level": "warning", + "message": " Next steps:", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " * Add Pact verification tests to the Bar build. See https://docs.pact.io/go/provider_verification" + "level": "warning", + "message": " * Add Pact verification tests to the Bar build. See https://docs.pact.io/go/provider_verification", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks" + "level": "warning", + "message": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks", + "deprecationWarning": "Replaced by notices" + } + ], + "notices": [ + { + "type": "debug", + "text": "Created Foo version 1 with tags a, b" + }, + { + "type": "warning", + "text": " Next steps:\n Configure the version branch to be the value of your repository branch." + }, + { + "type": "success", + "text": "Pact successfully published for Foo version 1 and provider Bar." + }, + { + "type": "debug", + "text": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1" + }, + { + "type": "debug", + "text": " Events detected: contract_published, contract_content_changed (first time any pact published for this consumer with consumer version tagged a, first time any pact published for this consumer with consumer version tagged b)" + }, + { + "type": "warning", + "text": " Next steps:" + }, + { + "type": "warning", + "text": " * Add Pact verification tests to the Bar build. See https://docs.pact.io/go/provider_verification" + }, + { + "type": "warning", + "text": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks" } ], "_embedded": { diff --git a/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json b/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json index 49467744f..bf41fb2ba 100644 --- a/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json +++ b/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json @@ -30,37 +30,74 @@ "status": 200, "headers": { "Content-Type": "application/hal+json;charset=utf-8", - "Content-Length": "1788" + "Content-Length": "2998" }, "body": { "logs": [ { "level": "debug", - "message": "Created Foo version 1 with branch main and tags a, b" + "message": "Created Foo version 1 with branch main and tags a, b", + "deprecationWarning": "Replaced by notices" }, { - "level": "info", - "message": "Pact successfully published for Foo version 1 and provider Bar." + "level": "success", + "message": "Pact successfully published for Foo version 1 and provider Bar.", + "deprecationWarning": "Replaced by notices" }, { "level": "debug", - "message": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1" + "message": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1", + "deprecationWarning": "Replaced by notices" }, { "level": "debug", - "message": " Events detected: contract_published, contract_content_changed (first time any pact published for this consumer with consumer version tagged a, first time any pact published for this consumer with consumer version tagged b)" + "message": " Events detected: contract_published, contract_content_changed (first time any pact published for this consumer with consumer version tagged a, first time any pact published for this consumer with consumer version tagged b)", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " Next steps:" + "level": "warning", + "message": " Next steps:", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " * Add Pact verification tests to the Bar build. See https://docs.pact.io/go/provider_verification" + "level": "warning", + "message": " * Add Pact verification tests to the Bar build. See https://docs.pact.io/go/provider_verification", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks" + "level": "warning", + "message": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks", + "deprecationWarning": "Replaced by notices" + } + ], + "notices": [ + { + "type": "debug", + "text": "Created Foo version 1 with branch main and tags a, b" + }, + { + "type": "success", + "text": "Pact successfully published for Foo version 1 and provider Bar." + }, + { + "type": "debug", + "text": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1" + }, + { + "type": "debug", + "text": " Events detected: contract_published, contract_content_changed (first time any pact published for this consumer with consumer version tagged a, first time any pact published for this consumer with consumer version tagged b)" + }, + { + "type": "warning", + "text": " Next steps:" + }, + { + "type": "warning", + "text": " * Add Pact verification tests to the Bar build. See https://docs.pact.io/go/provider_verification" + }, + { + "type": "warning", + "text": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks" } ], "_embedded": { diff --git a/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json b/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json index a55a69b87..c747da953 100644 --- a/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json +++ b/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json @@ -30,37 +30,74 @@ "status": 200, "headers": { "Content-Type": "application/hal+json;charset=utf-8", - "Content-Length": "1780" + "Content-Length": "3022" }, "body": { "logs": [ { "level": "debug", - "message": "Created Foo version 1 with branch main and tags a, b" + "message": "Created Foo version 1 with branch main and tags a, b", + "deprecationWarning": "Replaced by notices" }, { - "level": "info", - "message": "Pact successfully published for Foo version 1 and provider Bar." + "level": "success", + "message": "Pact successfully published for Foo version 1 and provider Bar.", + "deprecationWarning": "Replaced by notices" }, { "level": "debug", - "message": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1" + "message": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1", + "deprecationWarning": "Replaced by notices" }, { "level": "debug", - "message": " Events detected: contract_published, contract_content_changed (first time any pact published for this consumer with consumer version tagged a, first time any pact published for this consumer with consumer version tagged b)" + "message": " Events detected: contract_published, contract_content_changed (first time any pact published for this consumer with consumer version tagged a, first time any pact published for this consumer with consumer version tagged b)", + "deprecationWarning": "Replaced by notices" }, { "level": "debug", - "message": " Webhook \"foo webhook\" triggered for event contract_content_changed.\n View logs at http://example.org/triggered-webhooks/1234/logs" + "message": " Webhook \"foo webhook\" triggered for event contract_content_changed.\n translation missing: en.pact_broker.messages.webhooks.triggered_webhook_see_notices", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " Next steps:" + "level": "warning", + "message": " Next steps:", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " * Add Pact verification tests to the Bar build. See https://docs.pact.io/go/provider_verification" + "level": "warning", + "message": " * Add Pact verification tests to the Bar build. See https://docs.pact.io/go/provider_verification", + "deprecationWarning": "Replaced by notices" + } + ], + "notices": [ + { + "type": "debug", + "text": "Created Foo version 1 with branch main and tags a, b" + }, + { + "type": "success", + "text": "Pact successfully published for Foo version 1 and provider Bar." + }, + { + "type": "debug", + "text": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1" + }, + { + "type": "debug", + "text": " Events detected: contract_published, contract_content_changed (first time any pact published for this consumer with consumer version tagged a, first time any pact published for this consumer with consumer version tagged b)" + }, + { + "type": "debug", + "text": " Webhook \"foo webhook\" triggered for event contract_content_changed.\n translation missing: en.pact_broker.messages.webhooks.triggered_webhook_see_notices" + }, + { + "type": "warning", + "text": " Next steps:" + }, + { + "type": "warning", + "text": " * Add Pact verification tests to the Bar build. See https://docs.pact.io/go/provider_verification" } ], "_embedded": { diff --git a/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json b/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json index 607e996ac..c5865d2f0 100644 --- a/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json +++ b/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json @@ -30,33 +30,65 @@ "status": 200, "headers": { "Content-Type": "application/hal+json;charset=utf-8", - "Content-Length": "1778" + "Content-Length": "2933" }, "body": { "logs": [ { "level": "debug", - "message": "Updated Foo version 1 with branch main and tags a, b" + "message": "Updated Foo version 1 with branch main and tags a, b", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": "Pact with changed content published over existing content for Foo version 1 and provider Bar. This is not recommended in normal cicumstances and may indicate that you have not configured your Pact pipeline correctly. For more information see https://docs.pact.io/go/versioning" + "level": "warning", + "message": "Pact with changed content published over existing content for Foo version 1 and provider Bar. This is not recommended in normal cicumstances and may indicate that you have not configured your Pact pipeline correctly. For more information see https://docs.pact.io/go/versioning", + "deprecationWarning": "Replaced by notices" }, { "level": "debug", - "message": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1" + "message": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1", + "deprecationWarning": "Replaced by notices" }, { "level": "debug", - "message": " Events detected: contract_published, contract_content_changed (pact content modified since previous publication for Foo version 1)" + "message": " Events detected: contract_published, contract_content_changed (pact content modified since previous publication for Foo version 1)", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " Next steps:" + "level": "warning", + "message": " Next steps:", + "deprecationWarning": "Replaced by notices" }, { - "level": "warn", - "message": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks" + "level": "warning", + "message": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks", + "deprecationWarning": "Replaced by notices" + } + ], + "notices": [ + { + "type": "debug", + "text": "Updated Foo version 1 with branch main and tags a, b" + }, + { + "type": "warning", + "text": "Pact with changed content published over existing content for Foo version 1 and provider Bar. This is not recommended in normal cicumstances and may indicate that you have not configured your Pact pipeline correctly. For more information see https://docs.pact.io/go/versioning" + }, + { + "type": "debug", + "text": " View the published pact at http://example.org/pacts/provider/Bar/consumer/Foo/version/1" + }, + { + "type": "debug", + "text": " Events detected: contract_published, contract_content_changed (pact content modified since previous publication for Foo version 1)" + }, + { + "type": "warning", + "text": " Next steps:" + }, + { + "type": "warning", + "text": " * Configure separate Bar pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks" } ], "_embedded": { diff --git a/spec/fixtures/approvals/publish_contracts_results_decorator.approved.json b/spec/fixtures/approvals/publish_contracts_results_decorator.approved.json index be845d361..f297b84e5 100644 --- a/spec/fixtures/approvals/publish_contracts_results_decorator.approved.json +++ b/spec/fixtures/approvals/publish_contracts_results_decorator.approved.json @@ -1,8 +1,15 @@ { "logs": [ { - "level": "warn", - "message": "foo" + "level": "warning", + "message": "foo", + "deprecationWarning": "Replaced by notices" + } + ], + "notices": [ + { + "type": "warning", + "text": "foo" } ], "_embedded": { diff --git a/spec/lib/pact_broker/api/decorators/publish_contracts_results_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/publish_contracts_results_decorator_spec.rb index a93d4742a..05dd521e8 100644 --- a/spec/lib/pact_broker/api/decorators/publish_contracts_results_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/publish_contracts_results_decorator_spec.rb @@ -1,6 +1,6 @@ require 'pact_broker/api/decorators/publish_contracts_results_decorator' require 'pact_broker/contracts/contracts_publication_results' -require 'pact_broker/contracts/log_message' +require 'pact_broker/contracts/notice' module PactBroker module Api @@ -18,7 +18,7 @@ module Decorators let(:results) do PactBroker::Contracts::ContractsPublicationResults.from_hash( - logs: logs, + notices: notices, pacticipant: pacticipant, version: version, contracts: contracts, @@ -31,7 +31,7 @@ module Decorators let(:tags) { [tag]} let(:tag) { PactBroker::Domain::Tag.new(name: "main")} let(:version) { PactBroker::Domain::Version.new(number: "1" ) } - let(:logs) { [PactBroker::Contracts::LogMessage.warn("foo") ] } + let(:notices) { [PactBroker::Contracts::Notice.warning("foo") ] } let(:decorator_options) { { user_options: user_options } } let(:user_options) do { diff --git a/spec/lib/pact_broker/contracts/service_spec.rb b/spec/lib/pact_broker/contracts/service_spec.rb index 37f5c2f0c..2795b873b 100644 --- a/spec/lib/pact_broker/contracts/service_spec.rb +++ b/spec/lib/pact_broker/contracts/service_spec.rb @@ -49,7 +49,7 @@ module Contracts context "when the pact does not already exist" do context "when the write mode is overwrite" do it "returns an info message" do - expect(subject.logs.find{ |log| log.level == "info" && log.message.include?(" published ") }).to_not be nil + expect(subject.notices.find{ |log| log.type == "success" && log.text.include?(" published ") }).to_not be nil end end @@ -57,7 +57,7 @@ module Contracts let(:write_mode) { "merge" } it "returns an info message" do - expect(subject.logs.find{ |log| log.level == "info" && log.message.include?(" published ") }).to_not be nil + expect(subject.notices.find{ |log| log.type == "success" && log.text.include?(" published ") }).to_not be nil end end end @@ -81,7 +81,7 @@ module Contracts context "when the write mode is overwrite" do context "when the content is different" do it "returns a warning message" do - expect(subject.logs.find{ |log| log.level == "warn" && log.message.include?("changed content") }).to_not be nil + expect(subject.notices.find{ |log| log.type == "warning" && log.text.include?("changed content") }).to_not be nil end end @@ -89,7 +89,7 @@ module Contracts let(:decoded_contract) { PactBroker::Pacts::PactVersion.last.content } it "returns an info message" do - expect(subject.logs.find{ |log| log.level == "info" && log.message.include?("republished") }).to_not be nil + expect(subject.notices.find{ |log| log.type == "success" && log.text.include?("republished") }).to_not be nil end end end @@ -98,7 +98,7 @@ module Contracts let(:write_mode) { "merge" } it "returns an info message" do - expect(subject.logs.find{ |log| log.level == "info" && log.message.include?("merged") }).to_not be nil + expect(subject.notices.find{ |log| log.type == "success" && log.text.include?("merged") }).to_not be nil end end end