Class: Gitlab::Git::CommitStats

Inherits:
Object
  • Object
show all
Includes:
WrapsGitalyErrors
Defined in:
lib/gitlab/git/commit_stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from WrapsGitalyErrors

#wrapped_gitaly_errors

Constructor Details

#initialize(repo, commit) ⇒ CommitStats

Instantiate a CommitStats object

Gitaly migration: gitlab.com/gitlab-org/gitaly/issues/323



15
16
17
18
19
20
21
22
23
# File 'lib/gitlab/git/commit_stats.rb', line 15

def initialize(repo, commit)
  @id = commit.id

  additions, deletions = fetch_stats(repo, commit)

  @additions = additions.to_i
  @deletions = deletions.to_i
  @total = @additions + @deletions
end

Instance Attribute Details

#additionsObject (readonly)

Returns the value of attribute additions.



10
11
12
# File 'lib/gitlab/git/commit_stats.rb', line 10

def additions
  @additions
end

#deletionsObject (readonly)

Returns the value of attribute deletions.



10
11
12
# File 'lib/gitlab/git/commit_stats.rb', line 10

def deletions
  @deletions
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/gitlab/git/commit_stats.rb', line 10

def id
  @id
end

#totalObject (readonly)

Returns the value of attribute total.



10
11
12
# File 'lib/gitlab/git/commit_stats.rb', line 10

def total
  @total
end

Instance Method Details

#fetch_stats(repo, commit) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/git/commit_stats.rb', line 25

def fetch_stats(repo, commit)
  Rails.cache.fetch("commit_stats:#{repo.gl_project_path}:#{@id}") do
    stats = wrapped_gitaly_errors do
      repo.gitaly_commit_client.commit_stats(@id)
    end

    [stats.additions, stats.deletions]
  end
end