Commit 5a88873e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move API contributors logic to repository model

parent 81d41c0f
......@@ -242,4 +242,30 @@ class Repository
branches
end
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,
}
contributions.each do |contribution|
if contributors[email][:name].blank?
contributors[email][:name] = contribution[:author_name]
end
contributors[email][:commits] += 1
contributors[email][:additions] += contribution[:additions] || 0
contributors[email][:deletions] += contribution[:deletions] || 0
end
end
contributors.values
end
end
......@@ -160,29 +160,7 @@ module API
get ':id/repository/contributors' do
authorize! :download_code, user_project
contributors = {}
contributors
log = user_project.repository.graph_log
log.each do |entry|
email = entry[:author_email].to_s
if contributors.has_key?(email)
contributors[email][:commits] += 1
contributors[email][:additions] += entry[:additions] || 0
contributors[email][:deletions] += entry[:deletions] || 0
else
contributors[email] = {
email: email,
name: entry[:author_name],
commits: 1,
additions: entry[:additions] || 0,
deletions: entry[:deletions] || 0,
}
end
end
contributors
user_project.repository.contributors
end
end
end
......
module Gitlab
class Contributor
attr_accessor :email, :name, :commits, :additions, :deletions
def initialize
end
end
end
......@@ -171,7 +171,8 @@ describe API::API, api: true do
it 'should return valid data' do
get api("/projects/#{project.id}/repository/contributors", user)
response.status.should == 200
contributor = json_response.values.first
json_response.should be_an Array
contributor = json_response.first
contributor['email'].should == 'dmitriy.zaporozhets@gmail.com'
contributor['name'].should == 'Dmitriy Zaporozhets'
contributor['commits'].should == 185
......
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