Commit ceaee58c authored by Robert Schilling's avatar Robert Schilling

API: Catch empty commit messages

parent cc9764ac
---
title: 'API: Catch empty commit messages'
merge_request: 21322
author: Robert Schilling
type: fixed
...@@ -59,7 +59,7 @@ module API ...@@ -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 ...@@ -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')
......
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