Class: Airbrake::Filters::GitRepositoryFilter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake-ruby/filters/git_repository_filter.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.

Attaches git repository URL to ‘context`.

Since:

  • v2.12.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_directory) ⇒ GitRepositoryFilter

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 GitRepositoryFilter.

Parameters:

  • root_directory (String)

Since:

  • v2.12.0



11
12
13
14
15
16
# File 'lib/airbrake-ruby/filters/git_repository_filter.rb', line 11

def initialize(root_directory)
  @git_path = File.join(root_directory, '.git')
  @repository = nil
  @git_version = detect_git_version
  @weight = 116
end

Instance Attribute Details

#weightInteger (readonly)

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:

  • (Integer)

Since:

  • v2.12.0



8
9
10
# File 'lib/airbrake-ruby/filters/git_repository_filter.rb', line 8

def weight
  @weight
end

Instance Method Details

#attach_repository(notice) ⇒ 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.

Since:

  • v2.12.0



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/airbrake-ruby/filters/git_repository_filter.rb', line 25

def attach_repository(notice)
  if @repository
    notice[:context][:repository] = @repository
    return
  end

  return unless File.exist?(@git_path)
  return unless @git_version

  @repository =
    if @git_version >= Gem::Version.new('2.7.0')
      `cd #{@git_path} && git config --get remote.origin.url`.chomp
    else
      "`git remote get-url` is unsupported in git #{@git_version}. " \
        'Consider an upgrade to 2.7+'
    end

  return unless @repository

  notice[:context][:repository] = @repository
end

#call(notice) ⇒ 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.

This method returns an undefined value.

This is a mandatory method required by any filter integrated with FilterChain.

Parameters:

  • notice (Notice)

    the notice to be filtered

See Also:

Since:

  • v2.12.0



19
20
21
22
23
# File 'lib/airbrake-ruby/filters/git_repository_filter.rb', line 19

def call(notice)
  return if notice[:context].key?(:repository)

  attach_repository(notice)
end