Commit 7b42ff63 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'rs-merge_commit_message' into 'master'

Improve how MergeCommit#merge_commit_message builds the message

Now a merge request with a blank description will no longer produce a
merge commit message like this:

```
Merge branch 'foo' into 'master'

Bring the wonders of foo into the world



See merge request !7283
```

What an improvement! 🎉

See merge request !6450
parents b0af83f9 b007bd81
...@@ -590,13 +590,11 @@ class MergeRequest < ActiveRecord::Base ...@@ -590,13 +590,11 @@ class MergeRequest < ActiveRecord::Base
end end
def merge_commit_message def merge_commit_message
message = "Merge branch '#{source_branch}' into '#{target_branch}'" message = "Merge branch '#{source_branch}' into '#{target_branch}'\n\n"
message << "\n\n" message << "#{title}\n\n"
message << title.to_s message << "#{description}\n\n" if description.present?
message << "\n\n" message << "See merge request #{to_reference}"
message << description.to_s
message << "\n\n"
message << "See merge request !#{iid}"
message message
end end
......
...@@ -328,6 +328,42 @@ describe MergeRequest, models: true do ...@@ -328,6 +328,42 @@ describe MergeRequest, models: true do
end end
end end
describe '#merge_commit_message' do
it 'includes merge information as the title' do
request = build(:merge_request, source_branch: 'source', target_branch: 'target')
expect(request.merge_commit_message)
.to match("Merge branch 'source' into 'target'\n\n")
end
it 'includes its title in the body' do
request = build(:merge_request, title: 'Remove all technical debt')
expect(request.merge_commit_message)
.to match("Remove all technical debt\n\n")
end
it 'includes its description in the body' do
request = build(:merge_request, description: 'By removing all code')
expect(request.merge_commit_message)
.to match("By removing all code\n\n")
end
it 'includes its reference in the body' do
request = build_stubbed(:merge_request)
expect(request.merge_commit_message)
.to match("See merge request #{request.to_reference}")
end
it 'excludes multiple linebreak runs when description is blank' do
request = build(:merge_request, title: 'Title', description: nil)
expect(request.merge_commit_message).not_to match("Title\n\n\n\n")
end
end
describe "#reset_merge_when_build_succeeds" do describe "#reset_merge_when_build_succeeds" do
let(:merge_if_green) do let(:merge_if_green) do
create :merge_request, merge_when_build_succeeds: true, merge_user: create(:user), create :merge_request, merge_when_build_succeeds: true, merge_user: create(:user),
......
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