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: nil, 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, nil) (defaults to: nil)
  • 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)


84
85
86
87
88
89
90
91
92
93
94
95
# File 'utils/github/actions.rb', line 84

def initialize(type, message, file: nil, 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) if file.present?
  @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:



64
65
66
67
68
69
70
# File 'utils/github/actions.rb', line 64

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)


122
123
124
125
126
# File 'utils/github/actions.rb', line 122

def relevant?
  return true if @file.blank?

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