Class: RailsErrorDashboard::Services::GithubLinkGenerator
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Services::GithubLinkGenerator
- Defined in:
- lib/rails_error_dashboard/services/github_link_generator.rb
Overview
Generates links to source code on GitHub, GitLab, or Bitbucket Supports commit SHA, branch, and tag references
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#commit_sha ⇒ Object
readonly
Returns the value of attribute commit_sha.
-
#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.
-
#repository_url ⇒ Object
readonly
Returns the value of attribute repository_url.
Instance Method Summary collapse
-
#generate_link ⇒ String?
Generate a link to the source file on the repository host.
-
#initialize(repository_url:, file_path:, line_number:, commit_sha: nil, branch: nil) ⇒ GithubLinkGenerator
constructor
Initialize a new link generator.
Constructor Details
#initialize(repository_url:, file_path:, line_number:, commit_sha: nil, branch: nil) ⇒ GithubLinkGenerator
Initialize a new link generator
27 28 29 30 31 32 33 34 |
# File 'lib/rails_error_dashboard/services/github_link_generator.rb', line 27 def initialize(repository_url:, file_path:, line_number:, commit_sha: nil, branch: nil) @repository_url = repository_url @file_path = file_path @line_number = line_number.to_i @commit_sha = commit_sha @branch = branch || "main" @error = nil end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
18 19 20 |
# File 'lib/rails_error_dashboard/services/github_link_generator.rb', line 18 def branch @branch end |
#commit_sha ⇒ Object (readonly)
Returns the value of attribute commit_sha.
18 19 20 |
# File 'lib/rails_error_dashboard/services/github_link_generator.rb', line 18 def commit_sha @commit_sha end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
18 19 20 |
# File 'lib/rails_error_dashboard/services/github_link_generator.rb', line 18 def error @error end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
18 19 20 |
# File 'lib/rails_error_dashboard/services/github_link_generator.rb', line 18 def file_path @file_path end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
18 19 20 |
# File 'lib/rails_error_dashboard/services/github_link_generator.rb', line 18 def line_number @line_number end |
#repository_url ⇒ Object (readonly)
Returns the value of attribute repository_url.
18 19 20 |
# File 'lib/rails_error_dashboard/services/github_link_generator.rb', line 18 def repository_url @repository_url end |
Instance Method Details
#generate_link ⇒ String?
Generate a link to the source file on the repository host
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rails_error_dashboard/services/github_link_generator.rb', line 39 def generate_link return nil if repository_url.blank? || file_path.blank? # Normalize repository URL normalized_repo = normalize_repository_url # Determine reference (commit SHA or branch) reference = determine_reference # Generate link based on repository type case detect_repository_type when :github generate_github_link(normalized_repo, reference) when :gitlab generate_gitlab_link(normalized_repo, reference) when :bitbucket generate_bitbucket_link(normalized_repo, reference) else @error = "Unsupported repository type" nil end rescue StandardError => e @error = "Error generating link: #{e.}" RailsErrorDashboard::Logger.error("GithubLinkGenerator error for #{repository_url} - #{e.}") nil end |