summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Gizotti <gabriel@gizotti.com>2016-11-28 19:48:55 +1000
committerGabriel Gizotti <gabriel@gizotti.com>2016-12-16 19:13:17 +1000
commit58609f842e1344579ed14745bb6bcb365059166f (patch)
tree73fad7acde8d639943efe1c56198f209e6537109
parent512c870ed46b5e441fd0b8daa8bd9cab449f7ac0 (diff)
downloadgitlab-ce-58609f842e1344579ed14745bb6bcb365059166f.tar.gz
backend completely drives creation of merge commit message
-rw-r--r--app/models/merge_request.rb3
-rw-r--r--app/views/projects/merge_requests/widget/_open.html.haml3
-rw-r--r--app/views/projects/merge_requests/widget/open/_accept.html.haml3
-rw-r--r--app/views/shared/_commit_message_container.html.haml40
-rw-r--r--spec/models/merge_request_spec.rb14
5 files changed, 37 insertions, 26 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index dba0c463fd6..2d7be2c2c7e 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -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
diff --git a/app/views/projects/merge_requests/widget/_open.html.haml b/app/views/projects/merge_requests/widget/_open.html.haml
index ebea48a4321..bf1e49c98ce 100644
--- a/app/views/projects/merge_requests/widget/_open.html.haml
+++ b/app/views/projects/merge_requests/widget/_open.html.haml
@@ -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
diff --git a/app/views/projects/merge_requests/widget/open/_accept.html.haml b/app/views/projects/merge_requests/widget/open/_accept.html.haml
index 66096ff7476..d6f7f23533c 100644
--- a/app/views/projects/merge_requests/widget/open/_accept.html.haml
+++ b/app/views/projects/merge_requests/widget/open/_accept.html.haml
@@ -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
diff --git a/app/views/shared/_commit_message_container.html.haml b/app/views/shared/_commit_message_container.html.haml
index a151731ba0a..3e0186983e4 100644
--- a/app/views/shared/_commit_message_container.html.haml
+++ b/app/views/shared/_commit_message_container.html.haml
@@ -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();
});
-
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 9ca60e27900..f74c89bba4d 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -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