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

Use Contributor class instead of hash

parent 5a88873e
...@@ -244,28 +244,23 @@ class Repository ...@@ -244,28 +244,23 @@ class Repository
end end
def contributors def contributors
contributors = {}
log = graph_log.group_by { |i| i[:author_email] } log = graph_log.group_by { |i| i[:author_email] }
log.each do |email, contributions| log.map do |email, contributions|
contributors[email] = { contributor = Gitlab::Contributor.new
email: email, contributor.email = email
commits: 0,
additions: 0,
deletions: 0,
}
contributions.each do |contribution| contributions.each do |contribution|
if contributors[email][:name].blank? if contributor.name.blank?
contributors[email][:name] = contribution[:author_name] contributor.name = contribution[:author_name]
end end
contributors[email][:commits] += 1 contributor.commits += 1
contributors[email][:additions] += contribution[:additions] || 0 contributor.additions += contribution[:additions] || 0
contributors[email][:deletions] += contribution[:deletions] || 0 contributor.deletions += contribution[:deletions] || 0
end
end end
contributors.values contributor
end
end end
end end
...@@ -218,5 +218,9 @@ module API ...@@ -218,5 +218,9 @@ module API
expose :same, as: :compare_same_ref expose :same, as: :compare_same_ref
end end
class Contributor < Grape::Entity
expose :name, :email, :commits, :additions, :deletions
end
end end
end end
...@@ -160,7 +160,7 @@ module API ...@@ -160,7 +160,7 @@ module API
get ':id/repository/contributors' do get ':id/repository/contributors' do
authorize! :download_code, user_project authorize! :download_code, user_project
user_project.repository.contributors present user_project.repository.contributors, with: Entities::Contributor
end end
end end
end end
......
...@@ -3,7 +3,7 @@ module Gitlab ...@@ -3,7 +3,7 @@ module Gitlab
attr_accessor :email, :name, :commits, :additions, :deletions attr_accessor :email, :name, :commits, :additions, :deletions
def initialize def initialize
@commits, @additions, @deletions = 0, 0, 0
end end
end 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