2016-11-22 05:46:02 -05:00
|
|
|
module Gitlab
|
|
|
|
module CycleAnalytics
|
|
|
|
module Summary
|
|
|
|
class Commit < Base
|
2017-05-03 22:05:38 -04:00
|
|
|
def title
|
|
|
|
n_('Commit', 'Commits', value)
|
|
|
|
end
|
|
|
|
|
2016-11-22 05:46:02 -05:00
|
|
|
def value
|
|
|
|
@value ||= count_commits
|
|
|
|
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.
|
|
|
|
def count_commits
|
|
|
|
return unless ref
|
|
|
|
|
|
|
|
repository = @project.repository.raw_repository
|
|
|
|
sha = @project.repository.commit(ref).sha
|
|
|
|
|
|
|
|
cmd = %W(git --git-dir=#{repository.path} log)
|
|
|
|
cmd << '--format=%H'
|
|
|
|
cmd << "--after=#{@from.iso8601}"
|
|
|
|
cmd << sha
|
|
|
|
|
2016-12-09 09:23:09 -05:00
|
|
|
output, status = Gitlab::Popen.popen(cmd)
|
2016-12-09 06:41:15 -05:00
|
|
|
|
|
|
|
raise IOError, output unless status.zero?
|
|
|
|
|
|
|
|
output.lines.count
|
2016-11-22 05:46:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def ref
|
|
|
|
@ref ||= @project.default_branch.presence
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|