Use Contributor class instead of hash
This commit is contained in:
parent
5a88873e5c
commit
767bd78081
4 changed files with 16 additions and 17 deletions
|
@ -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
|
||||
contributor.commits += 1
|
||||
contributor.additions += contribution[:additions] || 0
|
||||
contributor.deletions += contribution[:deletions] || 0
|
||||
end
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue