Commit 0749a06d authored by Patrick Bajao's avatar Patrick Bajao

Merge branch 'merge-commit-template-ignore-cr' into 'master'

Remove CR newlines when generating merge commit message from template

See merge request gitlab-org/gitlab!74334
parents c06be029 7c20728a
...@@ -10,6 +10,7 @@ module Gitlab ...@@ -10,6 +10,7 @@ module Gitlab
return unless @merge_request.target_project.merge_commit_template.present? return unless @merge_request.target_project.merge_commit_template.present?
message = @merge_request.target_project.merge_commit_template message = @merge_request.target_project.merge_commit_template
message = message.delete("\r")
# Remove placeholders that correspond to empty values and are the last word in the line # Remove placeholders that correspond to empty values and are the last word in the line
# along with all whitespace characters preceding them. # along with all whitespace characters preceding them.
......
...@@ -183,4 +183,37 @@ RSpec.describe Gitlab::MergeRequests::MergeCommitMessage do ...@@ -183,4 +183,37 @@ RSpec.describe Gitlab::MergeRequests::MergeCommitMessage do
end end
end end
end end
context 'when project has template with CRLF newlines' do
let(:merge_commit_template) do
"Merge branch '%{source_branch}' into '%{target_branch}'\r\n\r\n%{title}\r\n\r\n%{description}\r\n\r\nSee merge request %{reference}"
end
it 'converts it to LF newlines' do
expect(subject.message).to eq <<~MSG.rstrip
Merge branch 'feature' into 'master'
Bugfix
Merge Request Description
Next line
See merge request #{merge_request.to_reference(full: true)}
MSG
end
context 'when description is empty string' do
let(:merge_request_description) { '' }
it 'skips description placeholder and removes new line characters before it' do
expect(subject.message).to eq <<~MSG.rstrip
Merge branch 'feature' into 'master'
Bugfix
See merge request #{merge_request.to_reference(full: true)}
MSG
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