summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2016-10-27 09:26:58 -0400
committerBen Boeckel <ben.boeckel@kitware.com>2017-02-14 13:22:14 -0500
commit309aee45b69888f9b51aaa0ce393a3f13b08c255 (patch)
tree3ddeb4d01c44afbe2363de6ee649ef4fa664b3b2
parente5f446b7ca4bc54ffaf527e4c57dea2bee2f79f6 (diff)
downloadgitlab-ce-309aee45b69888f9b51aaa0ce393a3f13b08c255.tar.gz
entities: use the RepoCommit entity for branch commits
Fixes #23895.
-rw-r--r--changelogs/unreleased/api-entities.yml4
-rw-r--r--doc/api/branches.md10
-rw-r--r--doc/api/commits.md18
-rw-r--r--lib/api/entities.rb35
-rw-r--r--spec/requests/api/branches_spec.rb13
-rw-r--r--spec/requests/api/commits_spec.rb20
6 files changed, 74 insertions, 26 deletions
diff --git a/changelogs/unreleased/api-entities.yml b/changelogs/unreleased/api-entities.yml
new file mode 100644
index 00000000000..2003d00fd52
--- /dev/null
+++ b/changelogs/unreleased/api-entities.yml
@@ -0,0 +1,4 @@
+---
+title: "Use an entity for RepoBranch commits and enhance RepoCommit"
+merge_request: 7138
+author: Ben Boeckel
diff --git a/doc/api/branches.md b/doc/api/branches.md
index ffcfea41453..5eaa8d2e920 100644
--- a/doc/api/branches.md
+++ b/doc/api/branches.md
@@ -34,6 +34,8 @@ Example response:
"committer_email": "john@example.com",
"committer_name": "John Smith",
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
+ "short_id": "7b5c3cc",
+ "title": "add projects API",
"message": "add projects API",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
@@ -78,6 +80,8 @@ Example response:
"committer_email": "john@example.com",
"committer_name": "John Smith",
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
+ "short_id": "7b5c3cc",
+ "title": "add projects API",
"message": "add projects API",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
@@ -119,6 +123,8 @@ Example response:
"committer_email": "john@example.com",
"committer_name": "John Smith",
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
+ "short_id": "7b5c3cc",
+ "title": "add projects API",
"message": "add projects API",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
@@ -163,6 +169,8 @@ Example response:
"committer_email": "john@example.com",
"committer_name": "John Smith",
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
+ "short_id": "7b5c3cc",
+ "title": "add projects API",
"message": "add projects API",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
@@ -204,6 +212,8 @@ Example response:
"committer_email": "john@example.com",
"committer_name": "John Smith",
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
+ "short_id": "7b5c3cc",
+ "title": "add projects API",
"message": "add projects API",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
diff --git a/doc/api/commits.md b/doc/api/commits.md
index 53ce381c8ae..abf6de5cfdc 100644
--- a/doc/api/commits.md
+++ b/doc/api/commits.md
@@ -29,11 +29,15 @@ Example response:
"title": "Replace sanitize with escape once",
"author_name": "Dmitriy Zaporozhets",
"author_email": "dzaporozhets@sphereconsultinginc.com",
+ "authored_date": "2012-09-20T11:50:22+03:00",
"committer_name": "Administrator",
"committer_email": "admin@example.com",
+ "committed_date": "2012-09-20T11:50:22+03:00",
"created_at": "2012-09-20T11:50:22+03:00",
"message": "Replace sanitize with escape once",
- "allow_failure": false
+ "parent_ids": [
+ "6104942438c14ec7bd21c6cd5bd995272b3faff6"
+ ]
},
{
"id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
@@ -45,7 +49,9 @@ Example response:
"committer_email": "dmitriy.zaporozhets@gmail.com",
"created_at": "2012-09-20T09:06:12+03:00",
"message": "Sanitize for network graph",
- "allow_failure": false
+ "parent_ids": [
+ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
+ ]
}
]
```
@@ -214,10 +220,16 @@ Example response:
"title": "Feature added",
"author_name": "Dmitriy Zaporozhets",
"author_email": "dmitriy.zaporozhets@gmail.com",
+ "authored_date": "2016-12-12T20:10:39.000+01:00",
"created_at": "2016-12-12T20:10:39.000+01:00",
"committer_name": "Administrator",
"committer_email": "admin@example.com",
- "message": "Feature added\n\nSigned-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>\n"
+ "committed_date": "2016-12-12T20:10:39.000+01:00",
+ "title": "Feature added",
+ "message": "Feature added\n\nSigned-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>\n",
+ "parent_ids": [
+ "a738f717824ff53aebad8b090c1b79a14f2bd9e8"
+ ]
}
```
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 2a071e649fa..0b8204fe7f3 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -155,10 +155,27 @@ module API
expose :shared_projects, using: Entities::Project
end
+ class RepoCommit < Grape::Entity
+ expose :id, :short_id, :title, :created_at
+ expose :parent_ids
+ expose :safe_message, as: :message
+ expose :author_name, :author_email, :authored_date
+ expose :committer_name, :committer_email, :committed_date
+ end
+
+ class RepoCommitStats < Grape::Entity
+ expose :additions, :deletions, :total
+ end
+
+ class RepoCommitDetail < RepoCommit
+ expose :stats, using: Entities::RepoCommitStats
+ expose :status
+ end
+
class RepoBranch < Grape::Entity
expose :name
- expose :commit do |repo_branch, options|
+ expose :commit, using: Entities::RepoCommit do |repo_branch, options|
options[:project].repository.commit(repo_branch.dereferenced_target)
end
@@ -193,22 +210,6 @@ module API
end
end
- class RepoCommit < Grape::Entity
- expose :id, :short_id, :title, :author_name, :author_email, :created_at
- expose :committer_name, :committer_email
- 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
-
class ProjectSnippet < Grape::Entity
expose :id, :title, :file_name
expose :author, using: Entities::UserBasic
diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb
index 5a3ffc284f2..3e66236f6ae 100644
--- a/spec/requests/api/branches_spec.rb
+++ b/spec/requests/api/branches_spec.rb
@@ -31,7 +31,18 @@ describe API::Branches, api: true do
expect(response).to have_http_status(200)
expect(json_response['name']).to eq(branch_name)
- expect(json_response['commit']['id']).to eq(branch_sha)
+ json_commit = json_response['commit']
+ expect(json_commit['id']).to eq(branch_sha)
+ expect(json_commit).to have_key('short_id')
+ expect(json_commit).to have_key('title')
+ expect(json_commit).to have_key('message')
+ expect(json_commit).to have_key('author_name')
+ expect(json_commit).to have_key('author_email')
+ expect(json_commit).to have_key('authored_date')
+ expect(json_commit).to have_key('committer_name')
+ expect(json_commit).to have_key('committer_email')
+ expect(json_commit).to have_key('committed_date')
+ expect(json_commit).to have_key('parent_ids')
expect(json_response['merged']).to eq(false)
expect(json_response['protected']).to eq(false)
expect(json_response['developers_can_push']).to eq(false)
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb
index af9028a8978..3d0d6735359 100644
--- a/spec/requests/api/commits_spec.rb
+++ b/spec/requests/api/commits_spec.rb
@@ -367,11 +367,21 @@ describe API::Commits, api: true 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)
+ commit = project.repository.commit
+ expect(json_response['id']).to eq(commit.id)
+ expect(json_response['short_id']).to eq(commit.short_id)
+ expect(json_response['title']).to eq(commit.title)
+ expect(json_response['message']).to eq(commit.safe_message)
+ expect(json_response['author_name']).to eq(commit.author_name)
+ expect(json_response['author_email']).to eq(commit.author_email)
+ expect(json_response['authored_date']).to eq(commit.authored_date.iso8601(3))
+ expect(json_response['committer_name']).to eq(commit.committer_name)
+ expect(json_response['committer_email']).to eq(commit.committer_email)
+ expect(json_response['committed_date']).to eq(commit.committed_date.iso8601(3))
+ expect(json_response['parent_ids']).to eq(commit.parent_ids)
+ expect(json_response['stats']['additions']).to eq(commit.stats.additions)
+ expect(json_response['stats']['deletions']).to eq(commit.stats.deletions)
+ expect(json_response['stats']['total']).to eq(commit.stats.total)
end
it "returns a 404 error if not found" do