BigW Consortium Gitlab

Commit 8031be73 by Dmitriy Zaporozhets

Merge branch 'contributors-api' into 'master'

Contributors api Fixes #1266 See merge request !934
parents efc6baf7 dacf9f9f
......@@ -242,4 +242,25 @@ class Repository
branches
end
end
def contributors
log = graph_log.group_by { |i| i[:author_email] }
log.map do |email, contributions|
contributor = Gitlab::Contributor.new
contributor.email = email
contributions.each do |contribution|
if contributor.name.blank?
contributor.name = contribution[:author_name]
end
contributor.commits += 1
contributor.additions += contribution[:additions] || 0
contributor.deletions += contribution[:deletions] || 0
end
contributor
end
end
end
......@@ -220,3 +220,32 @@ Response:
"compare_same_ref": false
}
```
## Contributors
Get repository contributors list
```
GET /projects/:id/repository/contributors
```
Parameters:
+ `id` (required) - The ID of a project
Response:
```
[{
"name": "Dmitriy Zaporozhets",
"email": "dmitriy.zaporozhets@gmail.com",
"commits": 117,
"additions": 2097,
"deletions": 517
}, {
"name": "Jacob Vosmaer",
"email": "contact@jacobvosmaer.nl",
"commits": 33,
"additions": 338,
"deletions": 244
}]
```
......@@ -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
......@@ -150,6 +150,18 @@ module API
compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to], MergeRequestDiff::COMMITS_SAFE_SIZE)
present compare, with: Entities::Compare
end
# Get repository contributors
#
# Parameters:
# id (required) - The ID of a project
# Example Request:
# GET /projects/:id/repository/contributors
get ':id/repository/contributors' do
authorize! :download_code, user_project
present user_project.repository.contributors, with: Entities::Contributor
end
end
end
end
module Gitlab
class Contributor
attr_accessor :email, :name, :commits, :additions, :deletions
def initialize
@commits, @additions, @deletions = 0, 0, 0
end
end
end
......@@ -128,7 +128,7 @@ describe API::API, api: true do
end
end
describe 'GET /GET /projects/:id/repository/compare' do
describe 'GET /projects/:id/repository/compare' do
it "should compare branches" do
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'simple_merge_request'
response.status.should == 200
......@@ -166,4 +166,18 @@ describe API::API, api: true do
json_response['compare_same_ref'].should be_true
end
end
describe 'GET /projects/:id/repository/contributors' do
it 'should return valid data' do
get api("/projects/#{project.id}/repository/contributors", user)
response.status.should == 200
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
contributor['additions'].should == 66072
contributor['deletions'].should == 63013
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