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
|
2022-04-04 11:22:00 +05:30
|
|
|
def identifier
|
|
|
|
:commits
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
@commits_count ||= gitaly_commit_client.commit_count(ref, after: @options[:from], before: @options[: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
|