Commit 3d9b0f08 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '199724-correct-mr-context-commits-endpoint' into 'master'

Correct the MR context commits endpoint

Closes #199724

See merge request gitlab-org/gitlab!24054
parents 88d4c188 94eb5a4c
...@@ -27,15 +27,7 @@ Parameters: ...@@ -27,15 +27,7 @@ Parameters:
"authored_date": "2017-04-11T10:08:59.000Z", "authored_date": "2017-04-11T10:08:59.000Z",
"committer_name": "Luke \"Jared\" Bennett", "committer_name": "Luke \"Jared\" Bennett",
"committer_email": "lbennett@gitlab.com", "committer_email": "lbennett@gitlab.com",
"committed_date": "2017-04-11T10:08:59.000Z", "committed_date": "2017-04-11T10:08:59.000Z"
"author": null,
"author_gravatar_url": "https://www.gravatar.com/avatar/2acf1fb99417a2b3971def5a294abbeb?s=80&d=identicon",
"commit_url": "http://127.0.0.1:3000/gitlab-org/gitlab-test/commit/4a24d82dbca5c11c61556f3b35ca472b7463187e",
"commit_path": "/gitlab-org/gitlab-test/commit/4a24d82dbca5c11c61556f3b35ca472b7463187e",
"description_html": "",
"title_html": "Update README.md to include `Usage in testing and development`",
"signature_html": null,
"pipeline_status_path": null
} }
] ]
``` ```
......
...@@ -670,12 +670,6 @@ module API ...@@ -670,12 +670,6 @@ module API
end end
end end
class MergeRequestContextCommit < Grape::Entity
expose :sha, :relative_order, :new_file, :renamed_file,
:deleted_file, :too_large, :a_mode, :b_mode, :new_path, :old_path,
:diff, :binary
end
class SSHKey < Grape::Entity class SSHKey < Grape::Entity
expose :id, :title, :key, :created_at expose :id, :title, :key, :created_at
end end
......
...@@ -293,7 +293,7 @@ module API ...@@ -293,7 +293,7 @@ module API
end end
desc 'Get the context commits of a merge request' do desc 'Get the context commits of a merge request' do
success Entities::CommitEntity success Entities::Commit
end end
get ':id/merge_requests/:merge_request_iid/context_commits' do get ':id/merge_requests/:merge_request_iid/context_commits' do
merge_request = find_merge_request_with_access(params[:merge_request_iid]) merge_request = find_merge_request_with_access(params[:merge_request_iid])
...@@ -301,8 +301,10 @@ module API ...@@ -301,8 +301,10 @@ module API
not_found! unless project.context_commits_enabled? not_found! unless project.context_commits_enabled?
context_commits = merge_request.context_commits context_commits =
CommitEntity.represent(context_commits, type: :full, request: merge_request) paginate(merge_request.merge_request_context_commits).map(&:to_commit)
present context_commits, with: Entities::Commit
end end
params do params do
......
...@@ -1069,10 +1069,16 @@ describe API::MergeRequests do ...@@ -1069,10 +1069,16 @@ describe API::MergeRequests do
describe 'GET /projects/:id/merge_requests/:merge_request_iid/:context_commits' do describe 'GET /projects/:id/merge_requests/:merge_request_iid/:context_commits' do
it 'returns a 200 when merge request is valid' do it 'returns a 200 when merge request is valid' do
context_commit = merge_request.context_commits.first
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/context_commits", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/context_commits", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(merge_request.context_commits.size) expect(json_response.size).to eq(merge_request.context_commits.size)
expect(json_response.first['id']).to eq(context_commit.id)
expect(json_response.first['title']).to eq(context_commit.title)
end end
it 'returns a 404 when merge_request_iid not found' do it 'returns a 404 when merge_request_iid not found' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment