| 1 |
module Gitorious |
| 2 |
module Graphs |
| 3 |
|
| 4 |
class CommitsByAuthorBuilder < Gitorious::Graphs::Builder |
| 5 |
def self.generate_for(repository) |
| 6 |
if repository.has_commits? |
| 7 |
repository.git.heads.each do |head| |
| 8 |
branch = head.name |
| 9 |
if !File.exist?(self.status_file(repository, branch)) |
| 10 |
builder = new(repository, branch) |
| 11 |
builder.build |
| 12 |
builder.write |
| 13 |
FileUtils.touch(self.status_file(repository, branch)) |
| 14 |
end |
| 15 |
end |
| 16 |
end |
| 17 |
end |
| 18 |
|
| 19 |
def initialize(repository, branch) |
| 20 |
@repository = repository |
| 21 |
@branch = branch |
| 22 |
@graph = Gruff::Mini::Pie.new(250) |
| 23 |
@graph.theme = self.class.sidebar_pastel_theme |
| 24 |
@graph.marker_font_size = 32 |
| 25 |
@graph.legend_font_size = 32 |
| 26 |
@graph.top_margin = 1 |
| 27 |
@graph.bottom_margin = 1 |
| 28 |
@graph.no_data_message = "" |
| 29 |
end |
| 30 |
|
| 31 |
def build |
| 32 |
commits_by_author = @repository.commit_graph_data_by_author(@branch) |
| 33 |
|
| 34 |
max_entries = 5 |
| 35 |
|
| 36 |
sorted = commits_by_author.sort_by { |author, count| count }.reverse |
| 37 |
|
| 38 |
top = sorted |
| 39 |
if sorted.size > max_entries |
| 40 |
top = sorted[0, max_entries-1] |
| 41 |
|
| 42 |
count = 0 |
| 43 |
sorted[max_entries-1, sorted.size].each do |v| |
| 44 |
count += v.last |
| 45 |
end |
| 46 |
top << ["Others", count] |
| 47 |
end |
| 48 |
|
| 49 |
labels = {} |
| 50 |
label_it = 0 |
| 51 |
top.each do |v| |
| 52 |
@graph.data("#{v.first} [#{v.last}]", v.last) |
| 53 |
|
| 54 |
labels[label_it] = v.first |
| 55 |
label_it += 1 |
| 56 |
end |
| 57 |
|
| 58 |
@graph.labels = labels |
| 59 |
end |
| 60 |
|
| 61 |
def self.filename(repository, branch) |
| 62 |
Builder.construct_filename(repository, branch, "commit_count_by_author") |
| 63 |
end |
| 64 |
|
| 65 |
def construct_filename |
| 66 |
CommitsByAuthorBuilder.filename(@repository, @branch) |
| 67 |
end |
| 68 |
end |
| 69 |
|
| 70 |
end |
| 71 |
end |