Parent

Gitlab::Git::Stats

Attributes

ref[RW]
repo[RW]

Public Class Methods

new(repo, ref) click to toggle source
# File lib/gitlab_git/stats.rb, line 6
def initialize repo, ref
  @repo, @ref = repo, ref
end

Public Instance Methods

authors() click to toggle source
# File lib/gitlab_git/stats.rb, line 10
def authors
  @authors ||= collect_authors
end
authors_count() click to toggle source
# File lib/gitlab_git/stats.rb, line 23
def authors_count
  authors.size
end
commits_count() click to toggle source
# File lib/gitlab_git/stats.rb, line 14
def commits_count
  @commits_count ||= repo.commit_count(ref)
end
files_count() click to toggle source
# File lib/gitlab_git/stats.rb, line 18
def files_count
  args = [ref, '-r', '--name-only' ]
  repo.git.native(:ls_tree, {}, args).split("\n").count
end
graph() click to toggle source
# File lib/gitlab_git/stats.rb, line 27
def graph
  @graph ||= build_graph
end

Protected Instance Methods

build_graph(n = 4) click to toggle source
# File lib/gitlab_git/stats.rb, line 55
def build_graph(n = 4)
  from, to = (Date.today.prev_day(n*7)), Date.today
  args = ['--all', "--since=#{from.to_s}", '--format=%ad' ]
  rev_list = repo.git.native(:rev_list, {}, args).split("\n")

  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
collect_authors() click to toggle source
# File lib/gitlab_git/stats.rb, line 33
def collect_authors
  shortlog = repo.git.shortlog({e: true, s: true }, ref)

  authors = []

  lines = shortlog.split("\n")

  lines.each do |line|
    data = line.split("\t")
    commits = data.first
    author = Grit::Actor.from_string(data.last)

    authors << OpenStruct.new(
      name: author.name,
      email: author.email,
      commits: commits.to_i
    )
  end

  authors.sort_by(&:commits).reverse
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.