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