Class: GitHub::Actions::Annotation Private

Inherits:
Object
  • Object
show all
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) ⇒ Annotation

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 a new instance of Annotation.

Raises:

  • (ArgumentError)


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

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) ⇒ Object

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.



19
20
21
22
23
24
25
# File 'brew/Library/Homebrew/utils/github/actions.rb', line 19

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)


49
50
51
52
53
# File 'brew/Library/Homebrew/utils/github/actions.rb', line 49

def relevant?
  return true if @file.nil?

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

#to_sObject

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.



37
38
39
40
41
42
43
44
45
# File 'brew/Library/Homebrew/utils/github/actions.rb', line 37

def to_s
  file = "file=#{Actions.escape(@file.to_s)}" if @file
  line = "line=#{@line}" if @line
  column = "col=#{@column}" if @column

   = [*file, *line, *column].join(",").presence&.prepend(" ")

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