debian-mirror-gitlab/lib/gitlab/cycle_analytics/summary/commit.rb

38 lines
1,009 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module CycleAnalytics
module Summary
class Commit < Base
def title
2020-06-23 00:09:42 +05:30
n_('Commit', 'Commits', value.to_i)
2017-08-17 22:00:37 +05:30
end
def value
2020-05-24 23:13:21 +05:30
@value ||= commits_count ? Value::PrettyNumeric.new(commits_count) : Value::None.new
2017-08-17 22:00:37 +05:30
end
private
# Don't use the `Gitlab::Git::Repository#log` method, because it enforces
# a limit. Since we need a commit count, we _can't_ enforce a limit, so
# the easiest way forward is to replicate the relevant portions of the
# `log` function here.
2020-05-24 23:13:21 +05:30
def commits_count
2017-08-17 22:00:37 +05:30
return unless ref
2020-05-24 23:13:21 +05:30
@commits_count ||= gitaly_commit_client.commit_count(ref, after: @from, before: @to)
2018-11-08 19:23:39 +05:30
end
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
def gitaly_commit_client
Gitlab::GitalyClient::CommitService.new(@project.repository.raw_repository)
2017-08-17 22:00:37 +05:30
end
def ref
@ref ||= @project.default_branch.presence
end
end
end
end
end