Class: Mbeditor::GitCommitGraphService
- Inherits:
-
Object
- Object
- Mbeditor::GitCommitGraphService
- Includes:
- GitService
- Defined in:
- app/services/mbeditor/git_commit_graph_service.rb
Overview
Builds commit graph data for rendering a VSCode-style commit graph.
Each commit entry:
{
"hash" => String, # full 40-char sha
"parents" => Array<String>, # parent sha(s) — enables line drawing
"title" => String,
"author" => String,
"date" => String, # ISO-8601
"isLocal" => Boolean # true if commit is ahead of upstream
}
Constant Summary collapse
- MAX_COMMITS =
150
Constants included from GitService
Mbeditor::GitService::SAFE_GIT_REF
Instance Attribute Summary collapse
-
#repo_path ⇒ Object
readonly
Returns the value of attribute repo_path.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(repo_path:) ⇒ GitCommitGraphService
constructor
A new instance of GitCommitGraphService.
Methods included from GitService
ahead_behind, current_branch, parse_git_log, parse_git_log_with_parents, resolve_path, run_git, upstream_branch
Constructor Details
#initialize(repo_path:) ⇒ GitCommitGraphService
Returns a new instance of GitCommitGraphService.
22 23 24 |
# File 'app/services/mbeditor/git_commit_graph_service.rb', line 22 def initialize(repo_path:) @repo_path = repo_path.to_s end |
Instance Attribute Details
#repo_path ⇒ Object (readonly)
Returns the value of attribute repo_path.
20 21 22 |
# File 'app/services/mbeditor/git_commit_graph_service.rb', line 20 def repo_path @repo_path end |
Instance Method Details
#call ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/mbeditor/git_commit_graph_service.rb', line 26 def call output, status = GitService.run_git( repo_path, "log", "--all", "-n", MAX_COMMITS.to_s, "--pretty=format:%H%x1f%P%x1f%s%x1f%an%x1f%aI%x1e" ) raise "git log failed" unless status.success? commits = GitService.parse_git_log_with_parents(output) local_shas = local_commit_shas commits.map do |c| c.merge("isLocal" => local_shas.include?(c["hash"])) end end |