Merge branch 'commits_api_with_stats' into 'master'
Added with_stats option to GET /projects/:id/repository/commits (API) See merge request gitlab-org/gitlab-ce!19484
This commit is contained in:
commit
886b81e5c7
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Added with_statsoption for GET /projects/:id/repository/commits
|
||||||
|
merge_request:
|
||||||
|
author:
|
||||||
|
type: added
|
|
@ -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 |
|
| `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 |
|
| `path` | string | no | The file path |
|
||||||
| `all` | boolean | no | Retrieve every commit from the repository |
|
| `all` | boolean | no | Retrieve every commit from the repository |
|
||||||
|
| `with_stats` | boolean | no | Stats about each commit will be added to the response |
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
@ -15,19 +15,21 @@ module API
|
||||||
end
|
end
|
||||||
params do
|
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 :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 :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 :until, type: DateTime, desc: 'Only commits before or on this date will be returned'
|
||||||
optional :path, type: String, desc: 'The file path'
|
optional :path, type: String, desc: 'The file path'
|
||||||
optional :all, type: Boolean, desc: 'Every commit will be returned'
|
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
|
use :pagination
|
||||||
end
|
end
|
||||||
get ':id/repository/commits' do
|
get ':id/repository/commits' do
|
||||||
path = params[:path]
|
path = params[:path]
|
||||||
before = params[:until]
|
before = params[:until]
|
||||||
after = params[:since]
|
after = params[:since]
|
||||||
ref = params[:ref_name] || user_project.try(:default_branch) || 'master' unless params[:all]
|
ref = params[:ref_name] || user_project.try(:default_branch) || 'master' unless params[:all]
|
||||||
offset = (params[:page] - 1) * params[:per_page]
|
offset = (params[:page] - 1) * params[:per_page]
|
||||||
all = params[:all]
|
all = params[:all]
|
||||||
|
with_stats = params[:with_stats]
|
||||||
|
|
||||||
commits = user_project.repository.commits(ref,
|
commits = user_project.repository.commits(ref,
|
||||||
path: path,
|
path: path,
|
||||||
|
@ -47,7 +49,9 @@ module API
|
||||||
|
|
||||||
paginated_commits = Kaminari.paginate_array(commits, total_count: commit_count)
|
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
|
end
|
||||||
|
|
||||||
desc 'Commit multiple file changes as one commit' do
|
desc 'Commit multiple file changes as one commit' do
|
||||||
|
|
|
@ -308,6 +308,10 @@ module API
|
||||||
expose :additions, :deletions, :total
|
expose :additions, :deletions, :total
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class CommitWithStats < Commit
|
||||||
|
expose :stats, using: Entities::CommitStats
|
||||||
|
end
|
||||||
|
|
||||||
class CommitDetail < Commit
|
class CommitDetail < Commit
|
||||||
expose :stats, using: Entities::CommitStats, if: :stats
|
expose :stats, using: Entities::CommitStats, if: :stats
|
||||||
expose :status
|
expose :status
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"allOf": [
|
||||||
|
{ "$ref": "basic.json" },
|
||||||
|
{
|
||||||
|
"required" : [
|
||||||
|
"stats"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"stats": { "$ref": "../commit_stats.json" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "commit/with_stats.json" }
|
||||||
|
}
|
|
@ -18,14 +18,14 @@ describe API::Commits do
|
||||||
describe 'GET /projects/:id/repository/commits' do
|
describe 'GET /projects/:id/repository/commits' do
|
||||||
let(:route) { "/projects/#{project_id}/repository/commits" }
|
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
|
it "returns project commits" do
|
||||||
commit = project.repository.commit
|
commit = project.repository.commit
|
||||||
|
|
||||||
get api(route, current_user)
|
get api(route, current_user)
|
||||||
|
|
||||||
expect(response).to have_gitlab_http_status(200)
|
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['id']).to eq(commit.id)
|
||||||
expect(json_response.first['committer_name']).to eq(commit.committer_name)
|
expect(json_response.first['committer_name']).to eq(commit.committer_name)
|
||||||
expect(json_response.first['committer_email']).to eq(commit.committer_email)
|
expect(json_response.first['committer_email']).to eq(commit.committer_email)
|
||||||
|
@ -161,6 +161,23 @@ describe API::Commits do
|
||||||
end
|
end
|
||||||
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
|
context 'with pagination params' do
|
||||||
let(:page) { 1 }
|
let(:page) { 1 }
|
||||||
let(:per_page) { 5 }
|
let(:per_page) { 5 }
|
||||||
|
|
Loading…
Reference in New Issue