Module: Publisher::Helpers

Included in:
Commands::Upload, Spinner, Providers::Github, Providers::Gitlab, Providers::Info::Github, Providers::Info::Gitlab, ReportGenerator, Uploaders::Uploader
Defined in:
lib/allure_report_publisher/lib/helpers/helpers.rb,
lib/allure_report_publisher/lib/helpers/spinner.rb,
lib/allure_report_publisher/lib/helpers/summary.rb,
lib/allure_report_publisher/lib/helpers/url_section_builder.rb

Overview

Helpers

Defined Under Namespace

Classes: ShellCommandFailure, Spinner, Summary, UrlSectionBuilder

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allure_cli?void

This method returns an undefined value.

Check allure cli is installed and executable



24
25
26
27
28
29
30
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 24

def allure_cli?
  execute_shell("which allure")
rescue StandardError
  Helpers.error(
    "Allure cli is missing! See https://docs.qameta.io/allure/#_installing_a_commandline on how to install it!"
  )
end

.colorize(message, color) ⇒ String

Colorize string

Parameters:

  • message (String)
  • color (Symbol)

Returns:

  • (String)


74
75
76
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 74

def colorize(message, color)
  Helpers.pastel.decorate(message, color)
end

.debug_ioStringIO

Debug logging session output

Returns:

  • (StringIO)


35
36
37
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 35

def debug_io
  @debug_io ||= StringIO.new
end

.error(message) ⇒ void

This method returns an undefined value.

Print error message and exit

Parameters:

  • message (String)


99
100
101
102
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 99

def error(message)
  warn colorize(message, :red)
  exit(1)
end

.execute_shell(command, mask: nil) ⇒ String

Execute shell command

Parameters:

  • command (String)

Returns:

  • (String)

    output



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 116

def execute_shell(command, mask: nil)
  loggable_command = mask ? command.gsub(mask, "***") : command
  log_debug("Executing command '#{loggable_command}'")
  out, err, status = Open3.capture3(command)

  cmd_output = []
  cmd_output << "Out: #{out}" unless out.empty?
  cmd_output << "Err: #{err}" unless err.empty?
  output = cmd_output.join("\n")

  unless status.success?
    err_msg = "Command '#{loggable_command}' failed!\n#{output}"
    err_msg = err_msg.gsub(mask, "***") if mask
    raise(ShellCommandFailure, err_msg)
  end

  mask ? output.gsub(mask, "***") : output
end

.log(message, color = :magenta) ⇒ void

This method returns an undefined value.

Log message to stdout

Parameters:

  • message (String)
  • color (String) (defaults to: :magenta)


83
84
85
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 83

def log(message, color = :magenta)
  puts colorize(message, color)
end

.log_debug(message) ⇒ void

This method returns an undefined value.

Save debug message to be displayed later

Parameters:

  • message (String)


91
92
93
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 91

def log_debug(message)
  Helpers.logger.info(message)
end

.loggerLogger

Logger instance

Returns:

  • (Logger)


49
50
51
52
53
54
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 49

def logger
  Logger.new(debug_io).tap do |logger|
    logger.datetime_format = "%Y-%m-%d %H:%M:%S"
    logger.formatter = proc { |_severity, time, _progname, msg| "[#{time}] #{msg}\n" }
  end
end

.pastel(force_color: nil) ⇒ Pastel

Global instance of pastel

Parameters:

  • force_color (Boolean) (defaults to: nil)

Returns:

  • (Pastel)


17
18
19
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 17

def pastel(force_color: nil)
  @pastel ||= Pastel.new(enabled: force_color, eachline: "\n")
end

.path(*args) ⇒ String

Safe join path

Parameters:

  • *args (Array<String>)

Returns:

  • (String)


108
109
110
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 108

def path(*args)
  File.join(args).to_s
end

.reset_debug_io!void

This method returns an undefined value.

Clear debug log output



42
43
44
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 42

def reset_debug_io!
  @debug_io = nil
end

Instance Method Details

#env(name) ⇒ String?

Return non empty environment variable value

Parameters:

  • name (String)

Returns:

  • (String, nil)


61
62
63
64
65
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 61

def env(name)
  return unless ENV[name] && !ENV[name].empty?

  ENV[name]
end