module Publisher::Helpers

Helpers

Helpers

Attributes

exit_on_error[R]
spinner_message[R]

Public Class Methods

colorize(message, color) click to toggle source

Colorize string

@param [String] message @param [Symbol] color @return [String]

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 33
def colorize(message, color)
  Helpers.pastel.decorate(message, color)
end
error(message) click to toggle source

Print error message and exit

@param [String] message @return [void]

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 50
def error(message)
  warn colorize(message, :red)
  exit(1)
end
execute_shell(command) click to toggle source

Execute shell command

@param [String] command @return [String] output

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 67
def execute_shell(command)
  out, err, status = Open3.capture3(command)
  raise("Out:\n#{out}\n\nErr:\n#{err}") unless status.success?

  out
end
log(message, color = :magenta) click to toggle source

Log message to stdout

@param [String] message @param [String] color @return [void]

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 42
def log(message, color = :magenta)
  puts colorize(message, color)
end
pastel(force_color: nil) click to toggle source

Global instance of pastel

@param [Boolean] force_color @return [Pastel]

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 12
def self.pastel(force_color: nil)
  @pastel ||= Pastel.new(enabled: force_color, eachline: "\n")
end
path(*args) click to toggle source

Safe join path

@param [Array<String>] *args @return [String]

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 59
def path(*args)
  File.join(args).to_s
end
validate_allure_cli_present() click to toggle source

Check allure cli is installed and executable

@return [void]

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 19
def self.validate_allure_cli_present
  _out, status = Open3.capture2("which allure")
  return if status.success?

  Helpers.error(
    "Allure cli is missing! See https://docs.qameta.io/allure/#_installing_a_commandline on how to install it!"
  )
end

Private Instance Methods

colorize(message, color) click to toggle source

Colorize string

@param [String] message @param [Symbol] color @return [String]

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 33
def colorize(message, color)
  Helpers.pastel.decorate(message, color)
end
error(message) click to toggle source

Print error message and exit

@param [String] message @return [void]

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 50
def error(message)
  warn colorize(message, :red)
  exit(1)
end
error_color() click to toggle source

Error message color

@return [Symbol]

# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 49
def error_color
  @error_color ||= exit_on_error ? :red : :yellow
end
error_mark() click to toggle source

Error mark

@return [String]

# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 63
def error_mark
  colorize(TTY::Spinner::CROSS, error_color)
end
execute_shell(command) click to toggle source

Execute shell command

@param [String] command @return [String] output

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 67
def execute_shell(command)
  out, err, status = Open3.capture3(command)
  raise("Out:\n#{out}\n\nErr:\n#{err}") unless status.success?

  out
end
log(message, color = :magenta) click to toggle source

Log message to stdout

@param [String] message @param [String] color @return [void]

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 42
def log(message, color = :magenta)
  puts colorize(message, color)
end
path(*args) click to toggle source

Safe join path

@param [Array<String>] *args @return [String]

# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 59
def path(*args)
  File.join(args).to_s
end
spinner() click to toggle source

Spinner instance

@return [TTY::Spinner]

# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 70
def spinner
  @spinner ||= TTY::Spinner.new(
    "[:spinner] #{spinner_message} ...",
    format: :dots,
    success_mark: success_mark,
    error_mark: error_mark
  )
end
spinner_error(error_message) click to toggle source

Return spinner error

@param [String] error_message @return [void]

# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 101
def spinner_error(error_message)
  colored_message = colorize("failed\n#{error_message}", error_color)
  return spinner.error(colored_message) if tty?

  spinner.stop
  puts("[#{error_mark}] #{spinner_message} ... #{colored_message}")
end
spinner_success(done_message) click to toggle source

Return spinner success

@param [String] done_message @return [void]

# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 90
def spinner_success(done_message)
  return spinner.success(done_message) if tty?

  spinner.stop
  puts("[#{success_mark}] #{spinner_message} ... #{done_message}")
end
success_mark() click to toggle source

Success mark

@return [String]

# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 56
def success_mark
  @success_mark ||= colorize(TTY::Spinner::TICK, :green)
end
tty?() click to toggle source

Check tty

@return [Boolean]

# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 82
def tty?
  spinner.send(:tty?)
end