Commit 767bd780 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use Contributor class instead of hash

parent 5a88873e
......@@ -244,28 +244,23 @@ class Repository
end
def contributors
contributors = {}
log = graph_log.group_by { |i| i[:author_email] }
log.each do |email, contributions|
contributors[email] = {
email: email,
commits: 0,
additions: 0,
deletions: 0,
}
log.map do |email, contributions|
contributor = Gitlab::Contributor.new
contributor.email = email
contributions.each do |contribution|
if contributors[email][:name].blank?
contributors[email][:name] = contribution[:author_name]
if contributor.name.blank?
contributor.name = contribution[:author_name]
end
contributors[email][:commits] += 1
contributors[email][:additions] += contribution[:additions] || 0
contributors[email][:deletions] += contribution[:deletions] || 0
end
contributor.commits += 1
contributor.additions += contribution[:additions] || 0
contributor.deletions += contribution[:deletions] || 0
end
contributors.values
contributor
end
end
end
......@@ -218,5 +218,9 @@ module API
expose :same, as: :compare_same_ref
end
class Contributor < Grape::Entity
expose :name, :email, :commits, :additions, :deletions
end
end
end
......@@ -160,7 +160,7 @@ module API
get ':id/repository/contributors' do
authorize! :download_code, user_project
user_project.repository.contributors
present user_project.repository.contributors, with: Entities::Contributor
end
end
end
......
......@@ -3,7 +3,7 @@ module Gitlab
attr_accessor :email, :name, :commits, :additions, :deletions
def initialize
@commits, @additions, @deletions = 0, 0, 0
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment