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
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
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
3 deletions
+63
-3
fj-41681-add-param-disable-commit-stats-api.yml
...nreleased/fj-41681-add-param-disable-commit-stats-api.yml
+5
-0
commits.md
doc/api/commits.md
+1
-0
commits.rb
lib/api/commits.rb
+2
-1
entities.rb
lib/api/entities.rb
+1
-1
commits.rb
lib/api/v3/commits.rb
+2
-1
commits_spec.rb
spec/requests/api/commits_spec.rb
+25
-0
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:
| --------- | ---- | -------- | ----------- |
|
`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 |
|
`stats`
| boolean | no | Include commit stats. Default is true |
```
bash
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
end
params
do
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
get
':id/repository/commits/:sha'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
present
commit
,
with:
Entities
::
CommitDetail
present
commit
,
with:
Entities
::
CommitDetail
,
stats:
params
[
:stats
]
end
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
end
class
CommitDetail
<
Commit
expose
:stats
,
using:
Entities
::
CommitStats
expose
:stats
,
using:
Entities
::
CommitStats
,
if: :stats
expose
:status
expose
:last_pipeline
,
using:
'API::Entities::PipelineBasic'
end
...
...
lib/api/v3/commits.rb
View file @
f6c1d382
...
...
@@ -71,13 +71,14 @@ module API
end
params
do
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
get
":id/repository/commits/:sha"
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
"Commit"
unless
commit
present
commit
,
with:
::
API
::
Entities
::
CommitDetail
present
commit
,
with:
::
API
::
Entities
::
CommitDetail
,
stats:
params
[
:stats
]
end
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
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
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
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'status'
]).
to
eq
(
"created"
)
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
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