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
24
# File 'lib/gitlab/git/commit_stats.rb', line 15

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

  additions, deletions, files = ensure_stats_format(repo)

  @additions = additions.to_i
  @deletions = deletions.to_i
  @files = files.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

#filesObject (readonly)

Returns the value of attribute files.



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

def files
  @files
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

#ensure_stats_format(repo) ⇒ Object



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

def ensure_stats_format(repo)
  cached_stats = fetch_stats(repo)

  if cached_stats.length == 2
    Rails.cache.delete(cache_key(repo))
    cached_stats = fetch_stats(repo)
  end

  cached_stats
end

#fetch_stats(repo) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/gitlab/git/commit_stats.rb', line 37

def fetch_stats(repo)
  Rails.cache.fetch(cache_key(repo)) do
    stats = wrapped_gitaly_errors do
      repo.gitaly_commit_client.commit_stats(@id)
    end

    [stats.additions, stats.deletions, stats.files]
  end
end