Module: SuperExceptionNotifier::GitBlame
- Included in:
- NotifiableHelper
- Defined in:
- lib/super_exception_notifier/git_blame.rb
Instance Method Summary collapse
- #blame_output(line_number, path) ⇒ Object
-
#exception_in_project?(path) ⇒ Boolean
should be a path like /path/to/broken/thingy.rb.
- #lay_blame(exception) ⇒ Object
Instance Method Details
#blame_output(line_number, path) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/super_exception_notifier/git_blame.rb', line 33 def blame_output(line_number, path) app_directory = Dir.pwd Dir.chdir ExceptionNotifier.config[:git_repo_path] blame = `git blame -p -L #{line_number},#{line_number} #{path}` Dir.chdir app_directory blame end |
#exception_in_project?(path) ⇒ Boolean
should be a path like /path/to/broken/thingy.rb
42 43 44 45 46 47 48 49 |
# File 'lib/super_exception_notifier/git_blame.rb', line 42 def exception_in_project?(path) # should be a path like /path/to/broken/thingy.rb dir = File.split(path).first rescue '' if(File.directory?(dir) and !(path =~ /vendor\/plugins/) and !(path =~ /vendor\/gems/) and path.include?(RAILS_ROOT)) path else nil end end |
#lay_blame(exception) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/super_exception_notifier/git_blame.rb', line 7 def lay_blame(exception) error = {} unless(ExceptionNotifier.config[:git_repo_path].nil?) if(exception.class == ActionView::TemplateError) blame = blame_output(exception.line_number, "app/views/#{exception.file_name}") error[:author] = blame[/^author\s.+$/].gsub(/author\s/,'') error[:line] = exception.line_number error[:file] = exception.file_name else exception.backtrace.each do |line| file = exception_in_project?(line[/^.+?(?=:)/]) unless(file.nil?) line_number = line[/:\d+:/].gsub(/[^\d]/,'') # Use relative path or weird stuff happens blame = blame_output(line_number, file.gsub(Regexp.new("#{RAILS_ROOT}/"),'')) error[:author] = blame[/^author\s.+$/].sub(/author\s/,'') error[:line] = line_number error[:file] = file break end end end end error end |