Class: GitHub::Actions::Annotation Private

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
brew/Library/Homebrew/utils/github/actions.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Helper class for formatting annotations on GitHub Actions.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, message, file: nil, line: nil, column: nil) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • type (Symbol)
  • message (String)
  • file (String, Pathname, nil) (defaults to: nil)
  • line (Integer, nil) (defaults to: nil)
  • column (Integer, nil) (defaults to: nil)

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
# File 'brew/Library/Homebrew/utils/github/actions.rb', line 40

def initialize(type, message, file: nil, line: nil, column: nil)
  raise ArgumentError, "Unsupported type: #{type.inspect}" unless [:warning, :error].include?(type)

  @type = type
  @message = Tty.strip_ansi(message)
  @file = self.class.path_relative_to_workspace(file) if file
  @line = Integer(line) if line
  @column = Integer(column) if column
end

Class Method Details

.path_relative_to_workspace(path) ⇒ Pathname?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:



26
27
28
29
30
31
32
# File 'brew/Library/Homebrew/utils/github/actions.rb', line 26

def self.path_relative_to_workspace(path)
  workspace = Pathname(ENV.fetch("GITHUB_WORKSPACE", Dir.pwd)).realpath
  path = Pathname(path)
  return path unless path.exist?

  path.realpath.relative_path_from(workspace)
end

Instance Method Details

#relevant?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

An annotation is only relevant if the corresponding file is relative to the GITHUB_WORKSPACE directory or if no file is specified.

Returns:

  • (Boolean)


69
70
71
72
73
# File 'brew/Library/Homebrew/utils/github/actions.rb', line 69

def relevant?
  return true if @file.nil?

  @file.descend.next.to_s != ".."
end

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'brew/Library/Homebrew/utils/github/actions.rb', line 51

def to_s
   = @type.to_s

  if @file
     << " file=#{Actions.escape(@file.to_s)}"

    if @line
       << ",line=#{@line}"
       << ",col=#{@column}" if @column
    end
  end

  "::#{}::#{Actions.escape(@message)}"
end