Sha256: 51582563dff0f1508d3fb5ce227f4d2cc8c18df99e52692159641a741c6e27eb
Contents?: true
Size: 1.84 KB
Versions: 2
Compression:
Stored size: 1.84 KB
Contents
module Gitlab module Git class Stats attr_accessor :repo, :ref def initialize repo, ref @repo, @ref = repo, ref end def authors @authors ||= collect_authors end def commits_count @commits_count ||= repo.commit_count(ref) end def files_count index = repo.rugged.index index.read_tree(repo.rugged.head.target.tree) index.count end def authors_count authors.size end def graph @graph ||= build_graph end protected def collect_authors commits = repo.log(ref: ref, limit: 0) author_stats = {} commits.each do |commit| if author_stats.key?(commit.author[:name]) author_stats[commit.author[:name]][:count] += 1 else author_stats[commit.author[:name]] = { email: commit.author[:email], count: 1 } end end authors = [] author_stats.each do |author_name, info| authors << OpenStruct.new( name: author_name, email: info[:email], commits: info[:count] ) end authors.sort_by(&:commits).reverse end def build_graph(n = 4) from, to = (Date.today.prev_day(n*7)), Date.today rev_list = repo.commits_since(from) commits_dates = rev_list.values_at(* rev_list.each_index.select {|i| i.odd?}) commits_dates = commits_dates.map { |date_str| Time.parse(date_str).to_date.to_s } commits_per_day = from.upto(to).map do |day| commits_dates.count(day.to_date.to_s) end OpenStruct.new( labels: from.upto(to).map { |day| day.strftime('%b %d') }, commits: commits_per_day, weeks: n ) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gitlab_git-7.0.0.rc2 | lib/gitlab_git/stats.rb |
gitlab_git-7.0.0.rc1 | lib/gitlab_git/stats.rb |