BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
8031be73
Commit
8031be73
authored
Jul 03, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'contributors-api' into 'master'
Contributors api Fixes #1266 See merge request !934
parents
efc6baf7
dacf9f9f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
1 deletion
+90
-1
repository.rb
app/models/repository.rb
+21
-0
repositories.md
doc/api/repositories.md
+29
-0
entities.rb
lib/api/entities.rb
+4
-0
repositories.rb
lib/api/repositories.rb
+12
-0
contributors.rb
lib/gitlab/contributors.rb
+9
-0
repositories_spec.rb
spec/requests/api/repositories_spec.rb
+15
-1
No files found.
app/models/repository.rb
View file @
8031be73
...
...
@@ -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
doc/api/repositories.md
View file @
8031be73
...
...
@@ -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
}]
```
lib/api/entities.rb
View file @
8031be73
...
...
@@ -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
lib/api/repositories.rb
View file @
8031be73
...
...
@@ -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
lib/gitlab/contributors.rb
0 → 100644
View file @
8031be73
module
Gitlab
class
Contributor
attr_accessor
:email
,
:name
,
:commits
,
:additions
,
:deletions
def
initialize
@commits
,
@additions
,
@deletions
=
0
,
0
,
0
end
end
end
spec/requests/api/repositories_spec.rb
View file @
8031be73
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment