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
404ef050
Commit
404ef050
authored
Jun 06, 2018
by
Leonid Batizhevskii
Committed by
Leonid Batizhevsky
Jun 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added with_statsoption for GET /projects/:id/repository/commits
parent
760b12dc
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
11 deletions
+60
-11
changelogs/unreleased/commits_api_with_stats.yml
changelogs/unreleased/commits_api_with_stats.yml
+5
-0
doc/api/commits.md
doc/api/commits.md
+1
-0
lib/api/commits.rb
lib/api/commits.rb
+13
-9
lib/api/entities.rb
lib/api/entities.rb
+4
-0
spec/fixtures/api/schemas/public_api/v4/commit/with_stats.json
...fixtures/api/schemas/public_api/v4/commit/with_stats.json
+14
-0
spec/fixtures/api/schemas/public_api/v4/commits_with_stats.json
...ixtures/api/schemas/public_api/v4/commits_with_stats.json
+4
-0
spec/requests/api/commits_spec.rb
spec/requests/api/commits_spec.rb
+19
-2
No files found.
changelogs/unreleased/commits_api_with_stats.yml
0 → 100644
View file @
404ef050
---
title
:
Added with_statsoption for GET /projects/:id/repository/commits
merge_request
:
author
:
type
:
added
doc/api/commits.md
View file @
404ef050
...
...
@@ -16,6 +16,7 @@ GET /projects/:id/repository/commits
|
`until`
| string | no | Only commits before or on this date will be returned in ISO 8601 format YYYY-MM-DDTHH:MM:SSZ |
|
`path`
| string | no | The file path |
|
`all`
| boolean | no | Retrieve every commit from the repository |
|
`with_stats`
| boolean | no | Stats about each commit will be added to the response |
```
bash
...
...
lib/api/commits.rb
View file @
404ef050
...
...
@@ -15,19 +15,21 @@ module API
end
params
do
optional
:ref_name
,
type:
String
,
desc:
'The name of a repository branch or tag, if not given the default branch is used'
optional
:since
,
type:
DateTime
,
desc:
'Only commits after or on this date will be returned'
optional
:until
,
type:
DateTime
,
desc:
'Only commits before or on this date will be returned'
optional
:path
,
type:
String
,
desc:
'The file path'
optional
:all
,
type:
Boolean
,
desc:
'Every commit will be returned'
optional
:since
,
type:
DateTime
,
desc:
'Only commits after or on this date will be returned'
optional
:until
,
type:
DateTime
,
desc:
'Only commits before or on this date will be returned'
optional
:path
,
type:
String
,
desc:
'The file path'
optional
:all
,
type:
Boolean
,
desc:
'Every commit will be returned'
optional
:with_stats
,
type:
Boolean
,
desc:
'Stats about each commit will be added to the response'
use
:pagination
end
get
':id/repository/commits'
do
path
=
params
[
:path
]
path
=
params
[
:path
]
before
=
params
[
:until
]
after
=
params
[
:since
]
ref
=
params
[
:ref_name
]
||
user_project
.
try
(
:default_branch
)
||
'master'
unless
params
[
:all
]
after
=
params
[
:since
]
ref
=
params
[
:ref_name
]
||
user_project
.
try
(
:default_branch
)
||
'master'
unless
params
[
:all
]
offset
=
(
params
[
:page
]
-
1
)
*
params
[
:per_page
]
all
=
params
[
:all
]
all
=
params
[
:all
]
with_stats
=
params
[
:with_stats
]
commits
=
user_project
.
repository
.
commits
(
ref
,
path:
path
,
...
...
@@ -47,7 +49,9 @@ module API
paginated_commits
=
Kaminari
.
paginate_array
(
commits
,
total_count:
commit_count
)
present
paginate
(
paginated_commits
),
with:
Entities
::
Commit
serializer
=
with_stats
?
Entities
::
CommitWithStats
:
Entities
::
Commit
present
paginate
(
paginated_commits
),
with:
serializer
end
desc
'Commit multiple file changes as one commit'
do
...
...
lib/api/entities.rb
View file @
404ef050
...
...
@@ -308,6 +308,10 @@ module API
expose
:additions
,
:deletions
,
:total
end
class
CommitWithStats
<
Commit
expose
:stats
,
using:
Entities
::
CommitStats
end
class
CommitDetail
<
Commit
expose
:stats
,
using:
Entities
::
CommitStats
,
if: :stats
expose
:status
...
...
spec/fixtures/api/schemas/public_api/v4/commit/with_stats.json
0 → 100644
View file @
404ef050
{
"type"
:
"object"
,
"allOf"
:
[
{
"$ref"
:
"basic.json"
},
{
"required"
:
[
"stats"
],
"properties"
:
{
"stats"
:
{
"$ref"
:
"../commit_stats.json"
}
}
}
]
}
spec/fixtures/api/schemas/public_api/v4/commits_with_stats.json
0 → 100644
View file @
404ef050
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"commit/with_stats.json"
}
}
spec/requests/api/commits_spec.rb
View file @
404ef050
...
...
@@ -18,14 +18,14 @@ describe API::Commits do
describe
'GET /projects/:id/repository/commits'
do
let
(
:route
)
{
"/projects/
#{
project_id
}
/repository/commits"
}
shared_examples_for
'project commits'
do
shared_examples_for
'project commits'
do
|
schema:
'public_api/v4/commits'
|
it
"returns project commits"
do
commit
=
project
.
repository
.
commit
get
api
(
route
,
current_user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/commits'
)
expect
(
response
).
to
match_response_schema
(
schema
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
commit
.
id
)
expect
(
json_response
.
first
[
'committer_name'
]).
to
eq
(
commit
.
committer_name
)
expect
(
json_response
.
first
[
'committer_email'
]).
to
eq
(
commit
.
committer_email
)
...
...
@@ -161,6 +161,23 @@ describe API::Commits do
end
end
context
'with_stats optional parameter'
do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
it_behaves_like
'project commits'
,
schema:
'public_api/v4/commits_with_stats'
do
let
(
:route
)
{
"/projects/
#{
project_id
}
/repository/commits?with_stats=true"
}
it
'include commits details'
do
commit
=
project
.
repository
.
commit
get
api
(
route
,
current_user
)
expect
(
json_response
.
first
[
'stats'
][
'additions'
]).
to
eq
(
commit
.
stats
.
additions
)
expect
(
json_response
.
first
[
'stats'
][
'deletions'
]).
to
eq
(
commit
.
stats
.
deletions
)
expect
(
json_response
.
first
[
'stats'
][
'total'
]).
to
eq
(
commit
.
stats
.
total
)
end
end
end
context
'with pagination params'
do
let
(
:page
)
{
1
}
let
(
:per_page
)
{
5
}
...
...
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