summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-08-27 08:19:45 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-08-27 08:19:45 +0000
commit8e2dec761f81aaf25233fb3ffe98cfec743891c0 (patch)
tree5aef4e945e907aef65a60deaad8d23c65b411480
parent76d9f556c7d02e5fef4f1a4feae00b2a30139800 (diff)
parent007163501c72fc05c448581e4e20098e4d6409aa (diff)
downloadgitlab-ce-8e2dec761f81aaf25233fb3ffe98cfec743891c0.tar.gz
Merge branch 'patch-28' into 'master'
Fix fallback logic for automatic MR title assignment See merge request gitlab-org/gitlab-ce!20930
-rw-r--r--app/services/merge_requests/build_service.rb19
-rw-r--r--changelogs/unreleased/fix-mr-title-fallback-logic.yml5
-rw-r--r--spec/services/merge_requests/build_service_spec.rb4
3 files changed, 17 insertions, 11 deletions
diff --git a/app/services/merge_requests/build_service.rb b/app/services/merge_requests/build_service.rb
index bc988eb2a26..55750269bb4 100644
--- a/app/services/merge_requests/build_service.rb
+++ b/app/services/merge_requests/build_service.rb
@@ -128,8 +128,7 @@ module MergeRequests
#
def assign_title_and_description
assign_title_and_description_from_single_commit
- assign_title_from_issue if target_project.issues_enabled? || target_project.external_issue_tracker
-
+ merge_request.title ||= title_from_issue if target_project.issues_enabled? || target_project.external_issue_tracker
merge_request.title ||= source_branch.titleize.humanize
merge_request.title = wip_title if compare_commits.empty?
@@ -159,20 +158,18 @@ module MergeRequests
merge_request.description ||= commit.description.try(:strip)
end
- def assign_title_from_issue
+ def title_from_issue
return unless issue
- merge_request.title = "Resolve \"#{issue.title}\"" if issue.is_a?(Issue)
+ return "Resolve \"#{issue.title}\"" if issue.is_a?(Issue)
- return if merge_request.title.present?
+ return if issue_iid.blank?
- if issue_iid.present?
- title_parts = ["Resolve #{issue.to_reference}"]
- branch_title = source_branch.downcase.remove(issue_iid.downcase).titleize.humanize
+ title_parts = ["Resolve #{issue.to_reference}"]
+ branch_title = source_branch.downcase.remove(issue_iid.downcase).titleize.humanize
- title_parts << "\"#{branch_title}\"" if branch_title.present?
- merge_request.title = title_parts.join(' ')
- end
+ title_parts << "\"#{branch_title}\"" if branch_title.present?
+ title_parts.join(' ')
end
def issue_iid
diff --git a/changelogs/unreleased/fix-mr-title-fallback-logic.yml b/changelogs/unreleased/fix-mr-title-fallback-logic.yml
new file mode 100644
index 00000000000..5056c38573b
--- /dev/null
+++ b/changelogs/unreleased/fix-mr-title-fallback-logic.yml
@@ -0,0 +1,5 @@
+---
+title: Fix fallback logic for automatic MR title assignment
+merge_request: 20930
+author: Franz Liedke
+type: fixed
diff --git a/spec/services/merge_requests/build_service_spec.rb b/spec/services/merge_requests/build_service_spec.rb
index 6aed481939e..0ced5d1b6d6 100644
--- a/spec/services/merge_requests/build_service_spec.rb
+++ b/spec/services/merge_requests/build_service_spec.rb
@@ -169,6 +169,10 @@ describe MergeRequests::BuildService do
end
end
+ it 'uses the title of the commit as the title of the merge request' do
+ expect(merge_request.title).to eq('Initial commit')
+ end
+
it 'appends the closing description' do
expected_description = [commit_description, closing_message].compact.join("\n\n")