Skip to content

Commit

Permalink
feat: update colours of pact publish output
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 24, 2021
1 parent 961f6ba commit 2a51e37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/pact_broker/client/colorize_notices.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'term/ansicolor'

module PactBroker
module Client
class ColorizeNotices
Expand All @@ -10,15 +12,15 @@ def self.call(notices)
def self.colorized_message(notice)
color = color_for_type(notice.type)
if color
::Term::ANSIColor.send(color, notice.text || '')
::Term::ANSIColor.color(color, notice.text || '')
else
notice.text
end
end

def self.color_for_type(type)
case type
when "warning" then :yellow
when "warning", "prompt" then "yellow"
when "error", "danger" then :red
when "success" then :green
else nil
Expand Down
5 changes: 4 additions & 1 deletion lib/pact_broker/client/publish_pacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'pact_broker/client/hal_client_methods'
require 'base64'
require 'pact_broker/client/publish_pacts_the_old_way'
require 'pact_broker/client/colorize_notices'

module PactBroker
module Client
Expand Down Expand Up @@ -71,7 +72,9 @@ def message
def text_message
response_entities.flat_map do | response_entity |
if response_entity.success?
if response_entity.logs
if response_entity.notices
PactBroker::Client::ColorizeNotices.call(response_entity.notices.collect{ |n| OpenStruct.new(n) } )
elsif response_entity.logs
response_entity.logs.collect do | log |
colorized_message(log)
end
Expand Down

0 comments on commit 2a51e37

Please sign in to comment.