Commit 58609f84 authored by Gabriel Gizotti's avatar Gabriel Gizotti

backend completely drives creation of merge commit message

parent 512c870e
...@@ -628,7 +628,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -628,7 +628,7 @@ class MergeRequest < ActiveRecord::Base
self.target_project.repository.branch_names.include?(self.target_branch) self.target_project.repository.branch_names.include?(self.target_branch)
end end
def merge_commit_message def merge_commit_message(include_description: false)
closes_issues_references = closes_issues.map do |issue| closes_issues_references = closes_issues.map do |issue|
issue.to_reference(target_project) issue.to_reference(target_project)
end end
...@@ -640,6 +640,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -640,6 +640,7 @@ class MergeRequest < ActiveRecord::Base
message << "Closed Issues: #{closes_issues_references.join(", ")}\n\n" message << "Closed Issues: #{closes_issues_references.join(", ")}\n\n"
end end
message << "#{description}\n\n" if include_description && description.present?
message << "See merge request #{to_reference}" message << "See merge request #{to_reference}"
message message
......
...@@ -37,12 +37,11 @@ ...@@ -37,12 +37,11 @@
#{"Issue".pluralize(mr_issues_mentioned_but_not_closing.size)} mentioned but not being closed: #{"Issue".pluralize(mr_issues_mentioned_but_not_closing.size)} mentioned but not being closed:
= succeed '.' do = succeed '.' do
!= markdown issues_sentence(mr_issues_mentioned_but_not_closing), pipeline: :gfm, author: @merge_request.author != markdown issues_sentence(mr_issues_mentioned_but_not_closing), pipeline: :gfm, author: @merge_request.author
= mr_assign_issues_link
- if mr_closes_issues.present? - if mr_closes_issues.present?
.mr-widget-footer .mr-widget-footer
%span %span
%i.fa.fa-check = icon('check')
Accepting this merge request will close #{"issue".pluralize(mr_closes_issues.size)} Accepting this merge request will close #{"issue".pluralize(mr_closes_issues.size)}
= succeed '.' do = succeed '.' do
!= markdown issues_sentence(mr_closes_issues), pipeline: :gfm, author: @merge_request.author != markdown issues_sentence(mr_closes_issues), pipeline: :gfm, author: @merge_request.author
......
...@@ -41,7 +41,8 @@ ...@@ -41,7 +41,8 @@
Modify commit message Modify commit message
.js-toggle-content.hide.prepend-top-default .js-toggle-content.hide.prepend-top-default
= render 'shared/commit_message_container', params: params, = render 'shared/commit_message_container', params: params,
description: @merge_request.description, message_with_description: @merge_request.merge_commit_message(include_description: true),
message_without_description: @merge_request.merge_commit_message,
text: @merge_request.merge_commit_message, text: @merge_request.merge_commit_message,
rows: 14, hint: true rows: 14, hint: true
......
...@@ -8,42 +8,38 @@ ...@@ -8,42 +8,38 @@
= text_area_tag 'commit_message', = text_area_tag 'commit_message',
(params[:commit_message] || local_assigns[:text] || local_assigns[:placeholder]), (params[:commit_message] || local_assigns[:text] || local_assigns[:placeholder]),
class: 'form-control js-commit-message', placeholder: local_assigns[:placeholder], class: 'form-control js-commit-message', placeholder: local_assigns[:placeholder],
data: local_assigns.slice(:message_with_description, :message_without_description),
required: true, rows: (local_assigns[:rows] || 3), required: true, rows: (local_assigns[:rows] || 3),
id: "commit_message-#{nonce}" id: "commit_message-#{nonce}"
- if local_assigns[:hint] - if local_assigns[:hint]
%p.hint %p.hint
Try to keep the first line under 52 characters Try to keep the first line under 52 characters
and the others under 72. and the others under 72.
- if local_assigns[:description] -if local_assigns.slice(:message_with_description, :message_without_description).present?
%p.hint.use-description-hint %p.hint.with-description-hint
= link_to "#", class: "use-description-link" do = link_to "#", class: "with-description-link" do
Use Merge Request description as merge commit message Include description in commit message
%p.hint.use-default-message-hint.hide %p.hint.without-description-hint.hide
= link_to "#", class: "use-default-message-link" do = link_to "#", class: "without-description-link" do
Use default Gitlab merge commit message Don't include description in commit message
:javascript :javascript
$('.use-description-link').on('click', function(e) { $('.with-description-link').on('click', function(e) {
e.preventDefault(); e.preventDefault();
var message = "Merge branch '#{j @merge_request.source_branch}' into '#{j @merge_request.target_branch}'\n\n" var textarea = $('.js-commit-message')
message = message + "#{j @merge_request.title}\n\n"
message = message + "#{j local_assigns[:description]}\n\n";
message = message + "See merge request #{j @merge_request.to_reference}"
textarea.val(textarea.data('messageWithDescription'))
$('.use-description-hint').hide(); $('.with-description-hint').hide();
$('.use-default-message-hint').show(); $('.without-description-hint').show();
$('.js-commit-message').val(message)
}); });
$('.use-default-message-link').on('click', function(e) { $('.without-description-link').on('click', function(e) {
e.preventDefault(); e.preventDefault();
var defaultMessage = "#{j (params[:commit_message] || local_assigns[:text] || local_assigns[:placeholder])}"; var textarea = $('.js-commit-message')
$('.use-description-hint').show(); textarea.val(textarea.data('messageWithoutDescription'))
$('.use-default-message-hint').hide(); $('.with-description-hint').show();
$('.js-commit-message').val(defaultMessage); $('.without-description-hint').hide();
}); });
...@@ -440,6 +440,20 @@ describe MergeRequest, models: true do ...@@ -440,6 +440,20 @@ describe MergeRequest, models: true do
expect(request.merge_commit_message).not_to match("Title\n\n\n\n") expect(request.merge_commit_message).not_to match("Title\n\n\n\n")
end end
it 'includes its description in the body' do
request = build(:merge_request, description: 'By removing all code')
expect(request.merge_commit_message(include_description: true))
.to match("By removing all code\n\n")
end
it 'does not includes its description in the body' do
request = build(:merge_request, description: 'By removing all code')
expect(request.merge_commit_message)
.not_to match("By removing all code\n\n")
end
end end
describe "#reset_merge_when_build_succeeds" do describe "#reset_merge_when_build_succeeds" do
......
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