Class: RailsErrorDashboard::Services::GitBlameReader
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Services::GitBlameReader
- Defined in:
- lib/rails_error_dashboard/services/git_blame_reader.rb
Overview
Reads git blame information for specific file lines Executes git blame command and parses porcelain output
Constant Summary collapse
- COMMAND_TIMEOUT =
seconds
5- PORCELAIN_FIELDS =
%w[ author author-mail author-time author-tz committer committer-mail committer-time committer-tz summary filename ].freeze
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
Instance Method Summary collapse
-
#git_available? ⇒ Boolean
Check if git is available on the system.
-
#initialize(file_path, line_number) ⇒ GitBlameReader
constructor
Initialize a new git blame reader.
-
#read_blame ⇒ Hash?
Read git blame information for the target line.
Constructor Details
#initialize(file_path, line_number) ⇒ GitBlameReader
Initialize a new git blame reader
36 37 38 39 40 |
# File 'lib/rails_error_dashboard/services/git_blame_reader.rb', line 36 def initialize(file_path, line_number) @file_path = file_path @line_number = line_number.to_i @error = nil end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
30 31 32 |
# File 'lib/rails_error_dashboard/services/git_blame_reader.rb', line 30 def error @error end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
30 31 32 |
# File 'lib/rails_error_dashboard/services/git_blame_reader.rb', line 30 def file_path @file_path end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
30 31 32 |
# File 'lib/rails_error_dashboard/services/git_blame_reader.rb', line 30 def line_number @line_number end |
Instance Method Details
#git_available? ⇒ Boolean
Check if git is available on the system
71 72 73 74 75 76 77 78 |
# File 'lib/rails_error_dashboard/services/git_blame_reader.rb', line 71 def git_available? @git_available ||= begin _stdout, _stderr, status = Open3.capture3("git", "--version") status.success? rescue StandardError false end end |
#read_blame ⇒ Hash?
Read git blame information for the target line
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rails_error_dashboard/services/git_blame_reader.rb', line 45 def read_blame unless git_available? @error = "Git not available" return nil end unless File.exist?(file_path) @error = "File not found" return nil end # Execute git blame command output = execute_git_blame return nil unless output # Parse porcelain format output parse_blame_output(output) rescue StandardError => e @error = "Error reading git blame: #{e.}" RailsErrorDashboard::Logger.error("GitBlameReader error for #{file_path}:#{line_number} - #{e.}") nil end |