Class: GitHub::Actions::Annotation Private

Inherits:
Object
  • Object
show all
Defined in:
utils/github/actions.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Helper class for formatting annotations on GitHub Actions.

Constant Summary collapse

ANNOTATION_TYPES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

[:notice, :warning, :error].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

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

Raises:

  • (ArgumentError)


63
64
65
66
67
68
69
70
71
72
73
74
# File 'utils/github/actions.rb', line 63

def initialize(type, message, file:, title: nil, line: nil, end_line: nil, column: nil, end_column: nil)
  raise ArgumentError, "Unsupported type: #{type.inspect}" if ANNOTATION_TYPES.exclude?(type)

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

Class Method Details

.path_relative_to_workspace(path) ⇒ Pathname?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



43
44
45
46
47
48
49
# File 'utils/github/actions.rb', line 43

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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

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

Returns:

  • (Boolean)


99
100
101
# File 'utils/github/actions.rb', line 99

def relevant?
  @file.descend.next.to_s != ".."
end