Class: Ace::Git::Models::RepoStatus

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • branch (String)

    Current branch name

  • tracking (String, nil) (defaults to: nil)

    Remote tracking branch

  • ahead (Integer) (defaults to: 0)

    Commits ahead of remote

  • behind (Integer) (defaults to: 0)

    Commits behind remote

  • task_pattern (String, nil) (defaults to: nil)

    Detected task pattern from branch

  • pr_metadata (Hash, nil) (defaults to: nil)

    PR metadata if available

  • pr_activity (Hash, nil) (defaults to: nil)

    PR activity (merged and open PRs)

  • git_status_sb (String, nil) (defaults to: nil)

    Output of git status -sb

  • recent_commits (Array, nil) (defaults to: nil)

    Recent commits array

  • repository_type (Symbol) (defaults to: :normal)

    :normal, :detached, :bare, :worktree, :not_git

  • repository_state (Symbol) (defaults to: :clean)

    :clean, :dirty, :rebasing, :merging



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

#aheadObject (readonly)

Returns the value of attribute ahead.



9
10
11
# File 'lib/ace/git/models/repo_status.rb', line 9

def ahead
  @ahead
end

#behindObject (readonly)

Returns the value of attribute behind.



9
10
11
# File 'lib/ace/git/models/repo_status.rb', line 9

def behind
  @behind
end

#branchObject (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_sbObject (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_activityObject (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_metadataObject (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_commitsObject (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_stateObject (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_typeObject (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_patternObject (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

#trackingObject (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

Parameters:

  • branch_info (Hash)

    Branch information

  • task_pattern (String, nil) (defaults to: nil)

    Detected task pattern

  • pr_metadata (Hash, nil) (defaults to: nil)

    PR metadata

  • pr_activity (Hash, nil) (defaults to: nil)

    PR activity (merged and open PRs)

  • git_status_sb (String, nil) (defaults to: nil)

    Output of git status -sb

  • recent_commits (Array, nil) (defaults to: nil)

    Recent commits array

  • repo_type (Symbol) (defaults to: :normal)

    Repository type

  • repo_state (Symbol) (defaults to: :clean)

    Repository state

Returns:



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

Returns:

  • (Boolean)

    True if no uncommitted changes



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

Returns:

  • (Boolean)

    True if detached HEAD



52
53
54
# File 'lib/ace/git/models/repo_status.rb', line 52

def detached?
  branch == "HEAD" || repository_type == :detached
end

#dirty_file_countInteger

Count dirty files from git status output

Returns:

  • (Integer)

    Number of dirty files (non-branch lines in git status -sb)



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

Returns:

  • (Boolean)

    True if git status output present



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

Returns:

  • (Boolean)

    True if PR metadata present



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

Returns:

  • (Boolean)

    True if any merged or open PRs present



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

Returns:

  • (Boolean)

    True if recent commits present



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

Returns:

  • (Boolean)

    True if task pattern found



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_hHash

Convert to hash

Returns:

  • (Hash)

    Hash representation



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

Returns:

  • (String)

    JSON representation



161
162
163
# File 'lib/ace/git/models/repo_status.rb', line 161

def to_json(*args)
  to_h.to_json(*args)
end

#to_markdownString

Note:

Delegates to Atoms::StatusFormatter for ATOM pattern compliance

Generate markdown output

Returns:

  • (String)

    Markdown-formatted status



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

Returns:

  • (Boolean)

    True if has tracking branch



58
59
60
# File 'lib/ace/git/models/repo_status.rb', line 58

def tracking?
  !tracking.nil? && !tracking.empty?
end

#tracking_statusString

Get tracking status description

Returns:

  • (String)

    Human-readable status



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

Returns:

  • (Boolean)

    True if no ahead/behind



64
65
66
# File 'lib/ace/git/models/repo_status.rb', line 64

def up_to_date?
  ahead == 0 && behind == 0
end