Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5a88873e
Commit
5a88873e
authored
Jul 02, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move API contributors logic to repository model
parent
81d41c0f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
24 deletions
+38
-24
app/models/repository.rb
app/models/repository.rb
+26
-0
lib/api/repositories.rb
lib/api/repositories.rb
+1
-23
lib/gitlab/contributors.rb
lib/gitlab/contributors.rb
+9
-0
spec/requests/api/repositories_spec.rb
spec/requests/api/repositories_spec.rb
+2
-1
No files found.
app/models/repository.rb
View file @
5a88873e
...
@@ -242,4 +242,30 @@ class Repository
...
@@ -242,4 +242,30 @@ class Repository
branches
branches
end
end
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
end
lib/api/repositories.rb
View file @
5a88873e
...
@@ -160,29 +160,7 @@ module API
...
@@ -160,29 +160,7 @@ module API
get
':id/repository/contributors'
do
get
':id/repository/contributors'
do
authorize!
:download_code
,
user_project
authorize!
:download_code
,
user_project
contributors
=
{}
user_project
.
repository
.
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
end
end
end
end
end
end
...
...
lib/gitlab/contributors.rb
0 → 100644
View file @
5a88873e
module
Gitlab
class
Contributor
attr_accessor
:email
,
:name
,
:commits
,
:additions
,
:deletions
def
initialize
end
end
end
spec/requests/api/repositories_spec.rb
View file @
5a88873e
...
@@ -171,7 +171,8 @@ describe API::API, api: true do
...
@@ -171,7 +171,8 @@ describe API::API, api: true do
it
'should return valid data'
do
it
'should return valid data'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/contributors"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/contributors"
,
user
)
response
.
status
.
should
==
200
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
[
'email'
].
should
==
'dmitriy.zaporozhets@gmail.com'
contributor
[
'name'
].
should
==
'Dmitriy Zaporozhets'
contributor
[
'name'
].
should
==
'Dmitriy Zaporozhets'
contributor
[
'commits'
].
should
==
185
contributor
[
'commits'
].
should
==
185
...
...
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