Class: Ace::Git::Models::RepoStatus
- Inherits:
-
Object
- Object
- Ace::Git::Models::RepoStatus
- Defined in:
- lib/ace/git/models/repo_status.rb
Overview
Data structure representing repository status Includes branch info, task pattern, PR metadata, and repository state
Instance Attribute Summary collapse
-
#ahead ⇒ Object
readonly
Returns the value of attribute ahead.
-
#behind ⇒ Object
readonly
Returns the value of attribute behind.
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#git_status_sb ⇒ Object
readonly
Returns the value of attribute git_status_sb.
-
#pr_activity ⇒ Object
readonly
Returns the value of attribute pr_activity.
-
#pr_metadata ⇒ Object
readonly
Returns the value of attribute pr_metadata.
-
#recent_commits ⇒ Object
readonly
Returns the value of attribute recent_commits.
-
#repository_state ⇒ Object
readonly
Returns the value of attribute repository_state.
-
#repository_type ⇒ Object
readonly
Returns the value of attribute repository_type.
-
#task_pattern ⇒ Object
readonly
Returns the value of attribute task_pattern.
-
#tracking ⇒ Object
readonly
Returns the value of attribute tracking.
Class Method Summary collapse
-
.from_data(branch_info:, task_pattern: nil, pr_metadata: nil, pr_activity: nil, git_status_sb: nil, recent_commits: nil, repo_type: :normal, repo_state: :clean) ⇒ RepoStatus
Create from loaded data.
Instance Method Summary collapse
-
#clean? ⇒ Boolean
Check if repository is clean.
-
#detached? ⇒ Boolean
Check if branch is detached.
-
#dirty_file_count ⇒ Integer
Count dirty files from git status output.
-
#has_git_status? ⇒ Boolean
Check if has git status output.
-
#has_pr? ⇒ Boolean
Check if has associated PR.
-
#has_pr_activity? ⇒ Boolean
Check if has PR activity data.
-
#has_recent_commits? ⇒ Boolean
Check if has recent commits data.
-
#has_task_pattern? ⇒ Boolean
Check if has detected task pattern.
-
#initialize(branch:, tracking: nil, ahead: 0, behind: 0, task_pattern: nil, pr_metadata: nil, pr_activity: nil, git_status_sb: nil, recent_commits: nil, repository_type: :normal, repository_state: :clean) ⇒ RepoStatus
constructor
A new instance of RepoStatus.
-
#to_h ⇒ Hash
Convert to hash.
-
#to_json(*args) ⇒ String
Convert to JSON.
-
#to_markdown ⇒ String
Generate markdown output.
-
#tracking? ⇒ Boolean
Check if tracking remote.
-
#tracking_status ⇒ String
Get tracking status description.
-
#up_to_date? ⇒ Boolean
Check if up to date with remote.
Constructor Details
#initialize(branch:, tracking: nil, ahead: 0, behind: 0, task_pattern: nil, pr_metadata: nil, pr_activity: nil, git_status_sb: nil, recent_commits: nil, repository_type: :normal, repository_state: :clean) ⇒ RepoStatus
Returns a new instance of RepoStatus.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ace/git/models/repo_status.rb', line 24 def initialize( branch:, tracking: nil, ahead: 0, behind: 0, task_pattern: nil, pr_metadata: nil, pr_activity: nil, git_status_sb: nil, recent_commits: nil, repository_type: :normal, repository_state: :clean ) @branch = branch @tracking = tracking @ahead = ahead @behind = behind @task_pattern = task_pattern @pr_metadata = @pr_activity = pr_activity @git_status_sb = git_status_sb @recent_commits = recent_commits @repository_type = repository_type @repository_state = repository_state end |
Instance Attribute Details
#ahead ⇒ Object (readonly)
Returns the value of attribute ahead.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def ahead @ahead end |
#behind ⇒ Object (readonly)
Returns the value of attribute behind.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def behind @behind end |
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def branch @branch end |
#git_status_sb ⇒ Object (readonly)
Returns the value of attribute git_status_sb.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def git_status_sb @git_status_sb end |
#pr_activity ⇒ Object (readonly)
Returns the value of attribute pr_activity.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def pr_activity @pr_activity end |
#pr_metadata ⇒ Object (readonly)
Returns the value of attribute pr_metadata.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def @pr_metadata end |
#recent_commits ⇒ Object (readonly)
Returns the value of attribute recent_commits.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def recent_commits @recent_commits end |
#repository_state ⇒ Object (readonly)
Returns the value of attribute repository_state.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def repository_state @repository_state end |
#repository_type ⇒ Object (readonly)
Returns the value of attribute repository_type.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def repository_type @repository_type end |
#task_pattern ⇒ Object (readonly)
Returns the value of attribute task_pattern.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def task_pattern @task_pattern end |
#tracking ⇒ Object (readonly)
Returns the value of attribute tracking.
9 10 11 |
# File 'lib/ace/git/models/repo_status.rb', line 9 def tracking @tracking end |
Class Method Details
.from_data(branch_info:, task_pattern: nil, pr_metadata: nil, pr_activity: nil, git_status_sb: nil, recent_commits: nil, repo_type: :normal, repo_state: :clean) ⇒ RepoStatus
Create from loaded data
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/ace/git/models/repo_status.rb', line 182 def self.from_data(branch_info:, task_pattern: nil, pr_metadata: nil, pr_activity: nil, git_status_sb: nil, recent_commits: nil, repo_type: :normal, repo_state: :clean) new( branch: branch_info[:name] || branch_info["name"], tracking: branch_info[:tracking] || branch_info["tracking"], ahead: branch_info[:ahead] || branch_info["ahead"] || 0, behind: branch_info[:behind] || branch_info["behind"] || 0, task_pattern: task_pattern, pr_metadata: , pr_activity: pr_activity, git_status_sb: git_status_sb, recent_commits: recent_commits, repository_type: repo_type, repository_state: repo_state ) end |
Instance Method Details
#clean? ⇒ Boolean
Check if repository is clean
104 105 106 |
# File 'lib/ace/git/models/repo_status.rb', line 104 def clean? repository_state == :clean end |
#detached? ⇒ Boolean
Check if branch is detached
52 53 54 |
# File 'lib/ace/git/models/repo_status.rb', line 52 def detached? branch == "HEAD" || repository_type == :detached end |
#dirty_file_count ⇒ Integer
Count dirty files from git status output
110 111 112 113 114 |
# File 'lib/ace/git/models/repo_status.rb', line 110 def dirty_file_count return 0 unless has_git_status? git_status_sb.lines.count { |l| !l.start_with?("##") } end |
#has_git_status? ⇒ Boolean
Check if has git status output
98 99 100 |
# File 'lib/ace/git/models/repo_status.rb', line 98 def has_git_status? !git_status_sb.nil? && !git_status_sb.empty? end |
#has_pr? ⇒ Boolean
Check if has associated PR
70 71 72 |
# File 'lib/ace/git/models/repo_status.rb', line 70 def has_pr? !.nil? && !.empty? end |
#has_pr_activity? ⇒ Boolean
Check if has PR activity data
82 83 84 85 86 87 88 |
# File 'lib/ace/git/models/repo_status.rb', line 82 def has_pr_activity? return false if pr_activity.nil? merged = pr_activity[:merged] || pr_activity["merged"] || [] open = pr_activity[:open] || pr_activity["open"] || [] !merged.empty? || !open.empty? end |
#has_recent_commits? ⇒ Boolean
Check if has recent commits data
92 93 94 |
# File 'lib/ace/git/models/repo_status.rb', line 92 def has_recent_commits? !recent_commits.nil? && !recent_commits.empty? end |
#has_task_pattern? ⇒ Boolean
Check if has detected task pattern
76 77 78 |
# File 'lib/ace/git/models/repo_status.rb', line 76 def has_task_pattern? !task_pattern.nil? && !task_pattern.empty? end |
#to_h ⇒ Hash
Convert to hash
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/ace/git/models/repo_status.rb', line 134 def to_h { branch: branch, tracking: tracking, ahead: ahead, behind: behind, up_to_date: up_to_date?, task_pattern: task_pattern, pr_metadata: , pr_activity: pr_activity, git_status_sb: git_status_sb, recent_commits: recent_commits, repository_type: repository_type, repository_state: repository_state, detached: detached?, has_pr: has_pr?, has_pr_activity: has_pr_activity?, has_recent_commits: has_recent_commits?, has_git_status: has_git_status?, has_task_pattern: has_task_pattern?, clean: clean?, dirty_files: dirty_file_count } end |
#to_json(*args) ⇒ String
Convert to JSON
161 162 163 |
# File 'lib/ace/git/models/repo_status.rb', line 161 def to_json(*args) to_h.to_json(*args) end |
#to_markdown ⇒ String
Delegates to Atoms::StatusFormatter for ATOM pattern compliance
Generate markdown output
168 169 170 |
# File 'lib/ace/git/models/repo_status.rb', line 168 def to_markdown Atoms::StatusFormatter.to_markdown(self) end |
#tracking? ⇒ Boolean
Check if tracking remote
58 59 60 |
# File 'lib/ace/git/models/repo_status.rb', line 58 def tracking? !tracking.nil? && !tracking.empty? end |
#tracking_status ⇒ String
Get tracking status description
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/ace/git/models/repo_status.rb', line 118 def tracking_status return "no tracking branch" unless tracking? if up_to_date? "up to date" elsif ahead > 0 && behind > 0 "#{ahead} ahead, #{behind} behind" elsif ahead > 0 "#{ahead} ahead" else "#{behind} behind" end end |
#up_to_date? ⇒ Boolean
Check if up to date with remote
64 65 66 |
# File 'lib/ace/git/models/repo_status.rb', line 64 def up_to_date? ahead == 0 && behind == 0 end |