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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
f6c1d382
Commit
f6c1d382
authored
Jan 09, 2018
by
Francisco Javier López
Committed by
Douwe Maan
Jan 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to disable commit stats to commit API
parent
4eae806a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
3 deletions
+63
-3
changelogs/unreleased/fj-41681-add-param-disable-commit-stats-api.yml
...nreleased/fj-41681-add-param-disable-commit-stats-api.yml
+5
-0
doc/api/commits.md
doc/api/commits.md
+1
-0
lib/api/commits.rb
lib/api/commits.rb
+2
-1
lib/api/entities.rb
lib/api/entities.rb
+1
-1
lib/api/v3/commits.rb
lib/api/v3/commits.rb
+2
-1
spec/requests/api/commits_spec.rb
spec/requests/api/commits_spec.rb
+25
-0
spec/requests/api/v3/commits_spec.rb
spec/requests/api/v3/commits_spec.rb
+27
-0
No files found.
changelogs/unreleased/fj-41681-add-param-disable-commit-stats-api.yml
0 → 100644
View file @
f6c1d382
---
title
:
Added option to disable commits stats in the commit endpoint
merge_request
:
16309
author
:
type
:
added
doc/api/commits.md
View file @
f6c1d382
...
@@ -159,6 +159,7 @@ Parameters:
...
@@ -159,6 +159,7 @@ Parameters:
| --------- | ---- | -------- | ----------- |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user
|
`sha`
| string | yes | The commit hash or name of a repository branch or tag |
|
`sha`
| string | yes | The commit hash or name of a repository branch or tag |
|
`stats`
| boolean | no | Include commit stats. Default is true |
```
bash
```
bash
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
"https://gitlab.example.com/api/v4/projects/5/repository/commits/master
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
"https://gitlab.example.com/api/v4/projects/5/repository/commits/master
...
...
lib/api/commits.rb
View file @
f6c1d382
...
@@ -82,13 +82,14 @@ module API
...
@@ -82,13 +82,14 @@ module API
end
end
params
do
params
do
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag'
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag'
optional
:stats
,
type:
Boolean
,
default:
true
,
desc:
'Include commit stats'
end
end
get
':id/repository/commits/:sha'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
get
':id/repository/commits/:sha'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
not_found!
'Commit'
unless
commit
present
commit
,
with:
Entities
::
CommitDetail
present
commit
,
with:
Entities
::
CommitDetail
,
stats:
params
[
:stats
]
end
end
desc
'Get the diff for a specific commit of a project'
do
desc
'Get the diff for a specific commit of a project'
do
...
...
lib/api/entities.rb
View file @
f6c1d382
...
@@ -278,7 +278,7 @@ module API
...
@@ -278,7 +278,7 @@ module API
end
end
class
CommitDetail
<
Commit
class
CommitDetail
<
Commit
expose
:stats
,
using:
Entities
::
CommitStats
expose
:stats
,
using:
Entities
::
CommitStats
,
if: :stats
expose
:status
expose
:status
expose
:last_pipeline
,
using:
'API::Entities::PipelineBasic'
expose
:last_pipeline
,
using:
'API::Entities::PipelineBasic'
end
end
...
...
lib/api/v3/commits.rb
View file @
f6c1d382
...
@@ -71,13 +71,14 @@ module API
...
@@ -71,13 +71,14 @@ module API
end
end
params
do
params
do
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag'
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag'
optional
:stats
,
type:
Boolean
,
default:
true
,
desc:
'Include commit stats'
end
end
get
":id/repository/commits/:sha"
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
get
":id/repository/commits/:sha"
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
"Commit"
unless
commit
not_found!
"Commit"
unless
commit
present
commit
,
with:
::
API
::
Entities
::
CommitDetail
present
commit
,
with:
::
API
::
Entities
::
CommitDetail
,
stats:
params
[
:stats
]
end
end
desc
'Get the diff for a specific commit of a project'
do
desc
'Get the diff for a specific commit of a project'
do
...
...
spec/requests/api/commits_spec.rb
View file @
f6c1d382
...
@@ -512,6 +512,31 @@ describe API::Commits do
...
@@ -512,6 +512,31 @@ describe API::Commits do
end
end
end
end
context
'when stat param'
do
let
(
:route
)
{
"/projects/
#{
project_id
}
/repository/commits/
#{
commit_id
}
"
}
it
'is not present return stats by default'
do
get
api
(
route
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
include
'stats'
end
it
"is false it does not include stats"
do
get
api
(
route
,
user
),
stats:
false
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
not_to
include
'stats'
end
it
"is true it includes stats"
do
get
api
(
route
,
user
),
stats:
true
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
include
'stats'
end
end
context
'when unauthenticated'
,
'and project is public'
do
context
'when unauthenticated'
,
'and project is public'
do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
...
...
spec/requests/api/v3/commits_spec.rb
View file @
f6c1d382
...
@@ -403,6 +403,33 @@ describe API::V3::Commits do
...
@@ -403,6 +403,33 @@ describe API::V3::Commits do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'status'
]).
to
eq
(
"created"
)
expect
(
json_response
[
'status'
]).
to
eq
(
"created"
)
end
end
context
'when stat param'
do
let
(
:project_id
)
{
project
.
id
}
let
(
:commit_id
)
{
project
.
repository
.
commit
.
id
}
let
(
:route
)
{
"/projects/
#{
project_id
}
/repository/commits/
#{
commit_id
}
"
}
it
'is not present return stats by default'
do
get
v3_api
(
route
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
include
'stats'
end
it
"is false it does not include stats"
do
get
v3_api
(
route
,
user
),
stats:
false
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
not_to
include
'stats'
end
it
"is true it includes stats"
do
get
v3_api
(
route
,
user
),
stats:
true
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
include
'stats'
end
end
end
end
context
"unauthorized user"
do
context
"unauthorized user"
do
...
...
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