Commit 0e076f80 authored by Robert Speicher's avatar Robert Speicher

Include dry_run error field for failed dry run operation

parent e20fe9f1
...@@ -203,7 +203,7 @@ module API ...@@ -203,7 +203,7 @@ module API
params do params do
requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag to be cherry picked' requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag to be cherry picked'
requires :branch, type: String, desc: 'The name of the branch', allow_blank: false requires :branch, type: String, desc: 'The name of the branch', allow_blank: false
optional :dry_run, type: Boolean, default: false, desc: "Don't commit any changes" optional :dry_run, type: Boolean, default: false, desc: "Does not commit any changes"
end end
post ':id/repository/commits/:sha/cherry_pick', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do post ':id/repository/commits/:sha/cherry_pick', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
authorize_push_to_branch!(params[:branch]) authorize_push_to_branch!(params[:branch])
...@@ -233,7 +233,10 @@ module API ...@@ -233,7 +233,10 @@ module API
with: Entities::Commit with: Entities::Commit
end end
else else
error!(result.slice(:message, :error_code), 400, header) response = result.slice(:message, :error_code)
response[:dry_run] = :error if params[:dry_run]
error!(response, 400, header)
end end
end end
...@@ -244,7 +247,7 @@ module API ...@@ -244,7 +247,7 @@ module API
params do params do
requires :sha, type: String, desc: 'Commit SHA to revert' requires :sha, type: String, desc: 'Commit SHA to revert'
requires :branch, type: String, desc: 'Target branch name', allow_blank: false requires :branch, type: String, desc: 'Target branch name', allow_blank: false
optional :dry_run, type: Boolean, default: false, desc: "Don't commit any changes" optional :dry_run, type: Boolean, default: false, desc: "Does not commit any changes"
end end
post ':id/repository/commits/:sha/revert', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do post ':id/repository/commits/:sha/revert', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
authorize_push_to_branch!(params[:branch]) authorize_push_to_branch!(params[:branch])
...@@ -274,7 +277,10 @@ module API ...@@ -274,7 +277,10 @@ module API
with: Entities::Commit with: Entities::Commit
end end
else else
error!(result.slice(:message, :error_code), 400, header) response = result.slice(:message, :error_code)
response[:dry_run] = :error if params[:dry_run]
error!(response, 400, header)
end end
end end
......
...@@ -1543,6 +1543,14 @@ RSpec.describe API::Commits do ...@@ -1543,6 +1543,14 @@ RSpec.describe API::Commits do
expect(json_response['error_code']).to eq 'empty' expect(json_response['error_code']).to eq 'empty'
end end
it 'includes an additional dry_run error field when enabled' do
post api(route, current_user), params: { branch: 'markdown', dry_run: true }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error_code']).to eq 'empty'
expect(json_response['dry_run']).to eq 'error'
end
end end
context 'when ref contains a dot' do context 'when ref contains a dot' do
...@@ -1724,6 +1732,18 @@ RSpec.describe API::Commits do ...@@ -1724,6 +1732,18 @@ RSpec.describe API::Commits do
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error_code']).to eq 'empty' expect(json_response['error_code']).to eq 'empty'
end end
it 'includes an additional dry_run error field when enabled' do
# First one actually reverts
post api(route, current_user), params: { branch: 'markdown' }
# Second one is redundant and should be empty
post api(route, current_user), params: { branch: 'markdown', dry_run: true }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error_code']).to eq 'empty'
expect(json_response['dry_run']).to eq 'error'
end
end end
end end
......
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