API: Catch empty commit messages
This commit is contained in:
parent
cc9764acd0
commit
ceaee58c49
3 changed files with 18 additions and 1 deletions
5
changelogs/unreleased/api-empty-commit-message.yml
Normal file
5
changelogs/unreleased/api-empty-commit-message.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: 'API: Catch empty commit messages'
|
||||||
|
merge_request: 21322
|
||||||
|
author: Robert Schilling
|
||||||
|
type: fixed
|
|
@ -59,7 +59,7 @@ module API
|
||||||
params :simple_file_params do
|
params :simple_file_params do
|
||||||
requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
|
requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb'
|
||||||
requires :branch, type: String, desc: 'Name of the branch to commit into. To create a new branch, also provide `start_branch`.'
|
requires :branch, type: String, desc: 'Name of the branch to commit into. To create a new branch, also provide `start_branch`.'
|
||||||
requires :commit_message, type: String, desc: 'Commit message'
|
requires :commit_message, type: String, regexp: /^\S+$/, desc: 'Commit message'
|
||||||
optional :start_branch, type: String, desc: 'Name of the branch to start the new commit from'
|
optional :start_branch, type: String, desc: 'Name of the branch to start the new commit from'
|
||||||
optional :author_email, type: String, desc: 'The email of the author'
|
optional :author_email, type: String, desc: 'The email of the author'
|
||||||
optional :author_name, type: String, desc: 'The name of the author'
|
optional :author_name, type: String, desc: 'The name of the author'
|
||||||
|
|
|
@ -337,6 +337,18 @@ describe API::Files do
|
||||||
expect(response).to have_gitlab_http_status(400)
|
expect(response).to have_gitlab_http_status(400)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns a 400 bad request if the commit message is empty' do
|
||||||
|
invalid_params = {
|
||||||
|
branch: 'master',
|
||||||
|
content: 'puts 8',
|
||||||
|
commit_message: ''
|
||||||
|
}
|
||||||
|
|
||||||
|
post api(route(file_path), user), invalid_params
|
||||||
|
|
||||||
|
expect(response).to have_gitlab_http_status(400)
|
||||||
|
end
|
||||||
|
|
||||||
it "returns a 400 if editor fails to create file" do
|
it "returns a 400 if editor fails to create file" do
|
||||||
allow_any_instance_of(Repository).to receive(:create_file)
|
allow_any_instance_of(Repository).to receive(:create_file)
|
||||||
.and_raise(Gitlab::Git::CommitError, 'Cannot create file')
|
.and_raise(Gitlab::Git::CommitError, 'Cannot create file')
|
||||||
|
|
Loading…
Reference in a new issue