class Airbrake::Filters::GitRepositoryFilter
Attaches git repository URL to `context`. @api private @since v2.12.0
Attributes
weight[R]
@return [Integer]
Public Class Methods
new(root_directory)
click to toggle source
@param [String] root_directory
# 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
Public Instance Methods
attach_repository(notice)
click to toggle source
# File lib/airbrake-ruby/filters/git_repository_filter.rb, line 24 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)
click to toggle source
@macro call_filter
# File lib/airbrake-ruby/filters/git_repository_filter.rb, line 19 def call(notice) return if notice[:context].key?(:repository) attach_repository(notice) end
Private Instance Methods
detect_git_version()
click to toggle source
# File lib/airbrake-ruby/filters/git_repository_filter.rb, line 47 def detect_git_version return unless which('git') Gem::Version.new(`git --version`.split[2]) end
which(cmd)
click to toggle source
Cross-platform way to tell if an executable is accessible.
# File lib/airbrake-ruby/filters/git_repository_filter.rb, line 53 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).find do |path| exts.find do |ext| exe = File.join(path, "#{cmd}#{ext}") File.executable?(exe) && !File.directory?(exe) end end end