diff options
-rw-r--r-- | changelogs/unreleased/51803-include-commits-stats-in-projects-api.yml | 5 | ||||
-rw-r--r-- | doc/api/commits.md | 1 | ||||
-rw-r--r-- | lib/api/commits.rb | 3 | ||||
-rw-r--r-- | spec/requests/api/commits_spec.rb | 14 |
4 files changed, 22 insertions, 1 deletions
diff --git a/changelogs/unreleased/51803-include-commits-stats-in-projects-api.yml b/changelogs/unreleased/51803-include-commits-stats-in-projects-api.yml new file mode 100644 index 00000000000..e67cc27f852 --- /dev/null +++ b/changelogs/unreleased/51803-include-commits-stats-in-projects-api.yml @@ -0,0 +1,5 @@ +--- +title: Includes commit stats in POST project commits API +merge_request: 21968 +author: Jacopo Beschi @jacopo-beschi +type: fixed diff --git a/doc/api/commits.md b/doc/api/commits.md index 5ff1e1f60e0..9b7ca4b6e70 100644 --- a/doc/api/commits.md +++ b/doc/api/commits.md @@ -79,6 +79,7 @@ POST /projects/:id/repository/commits | `actions[]` | array | yes | An array of action hashes to commit as a batch. See the next table for what attributes it can take. | | `author_email` | string | no | Specify the commit author's email address | | `author_name` | string | no | Specify the commit author's name | +| `stats` | boolean | no | Include commit stats. Default is true | | `actions[]` Attribute | Type | Required | Description | diff --git a/lib/api/commits.rb b/lib/api/commits.rb index ff927d1aa3c..e59abd3e3d0 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -98,6 +98,7 @@ module API optional :start_branch, type: String, desc: 'Name of the branch to start the new commit from' optional :author_email, type: String, desc: 'Author email for commit' optional :author_name, type: String, desc: 'Author name for commit' + optional :stats, type: Boolean, default: true, desc: 'Include commit stats' end post ':id/repository/commits' do authorize_push_to_branch!(params[:branch]) @@ -113,7 +114,7 @@ module API Gitlab::WebIdeCommitsCounter.increment if find_user_from_warden - present commit_detail, with: Entities::CommitDetail + present commit_detail, with: Entities::CommitDetail, stats: params[:stats] else render_api_error!(result[:message], 400) end diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index 06ccf383362..98399471f9a 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -572,6 +572,20 @@ describe API::Commits do expect(json_response['title']).to eq(message) end + it 'includes the commit stats' do + post api(url, user), valid_mo_params + + expect(response).to have_gitlab_http_status(201) + expect(json_response).to include 'stats' + end + + it "doesn't include the commit stats when stats is false" do + post api(url, user), valid_mo_params.merge(stats: false) + + expect(response).to have_gitlab_http_status(201) + expect(json_response).not_to include 'stats' + end + it 'return a 400 bad request if there are any issues' do post api(url, user), invalid_mo_params |