summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordixpac <dino.onex@gmail.com>2016-07-27 11:02:49 +0200
committerdixpac <dino.onex@gmail.com>2016-07-28 11:30:56 +0200
commita4bb9993c45b3d63a3d88f92ffc14bf849c38906 (patch)
tree08bbe10511be0826ac26d6844d4fc5c7979b7c67
parent17be364d072298f42d77fd22189bf9289b7cda2e (diff)
downloadgitlab-ce-a4bb9993c45b3d63a3d88f92ffc14bf849c38906.tar.gz
Add commit stats to commit api response
-rw-r--r--CHANGELOG1
-rw-r--r--doc/api/commits.md5
-rw-r--r--lib/api/entities.rb5
-rw-r--r--spec/requests/api/commits_spec.rb4
4 files changed, 15 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index f4567fc5bbd..d95dd0ec54f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -22,6 +22,7 @@ v 8.11.0 (unreleased)
- Add the `sprockets-es6` gem
- Multiple trigger variables show in separate lines (Katarzyna Kobierska Ula Budziszewska)
- Profile requests when a header is passed
+ - Add commit stats in commit api. !5517 (dixpac)
- Make error pages responsive (Takuya Noguchi)
- Change requests_profiles resource constraint to catch virtually any file
diff --git a/doc/api/commits.md b/doc/api/commits.md
index 57c2e1d9b87..2960c2ae428 100644
--- a/doc/api/commits.md
+++ b/doc/api/commits.md
@@ -81,6 +81,11 @@ Example response:
"parent_ids": [
"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
],
+ "stats": {
+ "additions": 15,
+ "deletions": 10,
+ "total": 25
+ },
"status": "running"
}
```
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index fbf0d74663f..e76e7304674 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -149,8 +149,13 @@ module API
expose :safe_message, as: :message
end
+ class RepoCommitStats < Grape::Entity
+ expose :additions, :deletions, :total
+ end
+
class RepoCommitDetail < RepoCommit
expose :parent_ids, :committed_date, :authored_date
+ expose :stats, using: Entities::RepoCommitStats
expose :status
end
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb
index 5219c808791..e4ea8506598 100644
--- a/spec/requests/api/commits_spec.rb
+++ b/spec/requests/api/commits_spec.rb
@@ -73,9 +73,13 @@ describe API::API, api: true do
context "authorized user" do
it "should return a commit by sha" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
+
expect(response).to have_http_status(200)
expect(json_response['id']).to eq(project.repository.commit.id)
expect(json_response['title']).to eq(project.repository.commit.title)
+ expect(json_response['stats']['additions']).to eq(project.repository.commit.stats.additions)
+ expect(json_response['stats']['deletions']).to eq(project.repository.commit.stats.deletions)
+ expect(json_response['stats']['total']).to eq(project.repository.commit.stats.total)
end
it "should return a 404 error if not found" do