2016-09-19 05:30:55 -04:00
|
|
|
class CycleAnalytics
|
|
|
|
class Summary
|
|
|
|
def initialize(project, from:)
|
|
|
|
@project = project
|
|
|
|
@from = from
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_issues
|
2016-09-20 15:17:37 -04:00
|
|
|
@project.issues.created_after(@from).count
|
2016-09-19 05:30:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def commits
|
2016-09-26 00:33:57 -04:00
|
|
|
ref = @project.default_branch.presence
|
|
|
|
count_commits_for(ref)
|
2016-09-19 05:30:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def deploys
|
2016-09-20 00:24:42 -04:00
|
|
|
@project.deployments.where("created_at > ?", @from).count
|
2016-09-19 05:30:55 -04:00
|
|
|
end
|
2016-09-26 00:33:57 -04:00
|
|
|
|
|
|
|
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_for(ref)
|
|
|
|
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
|
|
|
|
|
|
|
|
raw_output = IO.popen(cmd) { |io| io.read }
|
|
|
|
raw_output.lines.count
|
|
|
|
end
|
2016-09-19 05:30:55 -04:00
|
|
|
end
|
|
|
|
end
|