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
-
.allure_cli? ⇒ void
Check allure cli is installed and executable.
-
.colorize(message, color) ⇒ String
Colorize string.
-
.debug_io ⇒ StringIO
Debug logging session output.
-
.error(message) ⇒ void
Print error message and exit.
-
.execute_shell(command, mask: nil) ⇒ String
Execute shell command.
-
.log(message, color = :magenta) ⇒ void
Log message to stdout.
-
.log_debug(message) ⇒ void
Save debug message to be displayed later.
-
.logger ⇒ Logger
Logger instance.
-
.pastel(force_color: nil) ⇒ Pastel
Global instance of pastel.
-
.path(*args) ⇒ String
Safe join path.
-
.reset_debug_io! ⇒ void
Clear debug log output.
Instance Method Summary collapse
-
#env(name) ⇒ String?
Return non empty environment variable value.
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
72 73 74 |
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 72 def colorize(, color) Helpers.pastel.decorate(, color) end |
.debug_io ⇒ StringIO
Debug logging session output
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
97 98 99 100 |
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 97 def error() warn colorize(, :red) exit(1) end |
.execute_shell(command, mask: nil) ⇒ String
Execute shell command
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 114 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
81 82 83 |
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 81 def log(, color = :magenta) puts colorize(, color) end |
.log_debug(message) ⇒ void
This method returns an undefined value.
Save debug message to be displayed later
89 90 91 |
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 89 def log_debug() Helpers.logger.info() end |
.logger ⇒ Logger
Logger instance
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
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
106 107 108 |
# File 'lib/allure_report_publisher/lib/helpers/helpers.rb', line 106 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
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 |