diff options
author | Andrew McCallum <andrew.mccallum@semafone.com> | 2018-02-02 20:20:48 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-02-02 20:20:48 +0300 |
commit | f0e7d79c8b21c798b4793ee7d037683941c4d6e6 (patch) | |
tree | 90d423b580c3f0a2ff7e346a990c1163d35b95a7 /app/services/merge_requests | |
parent | 283ace44dd156a5698a3191e2901c3302c1ad52f (diff) |
Resolve "Incorrect merge request title when Jira activated and multiple commits on branch"
Diffstat (limited to 'app/services/merge_requests')
-rw-r--r-- | app/services/merge_requests/build_service.rb | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/app/services/merge_requests/build_service.rb b/app/services/merge_requests/build_service.rb index 22b9b91a957..2ae855d078b 100644 --- a/app/services/merge_requests/build_service.rb +++ b/app/services/merge_requests/build_service.rb @@ -1,7 +1,9 @@ module MergeRequests class BuildService < MergeRequests::BaseService + include Gitlab::Utils::StrongMemoize + def execute - @issue_iid = params.delete(:issue_iid) + @params_issue_iid = params.delete(:issue_iid) self.merge_request = MergeRequest.new(params) merge_request.compare_commits = [] @@ -123,7 +125,7 @@ module MergeRequests # def assign_title_and_description assign_title_and_description_from_single_commit - assign_title_from_issue + assign_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? @@ -132,9 +134,9 @@ module MergeRequests end def append_closes_description - return unless issue_iid + return unless issue - closes_issue = "Closes ##{issue_iid}" + closes_issue = "Closes #{issue.to_reference}" if description.present? merge_request.description += closes_issue.prepend("\n\n") @@ -154,13 +156,27 @@ module MergeRequests end def assign_title_from_issue - return unless issue && issue.is_a?(Issue) + return unless issue + + merge_request.title = "Resolve \"#{issue.title}\"" if issue.is_a?(Issue) - merge_request.title = "Resolve \"#{issue.title}\"" + unless merge_request.title + branch_title = source_branch.downcase.remove(issue_iid.downcase).titleize.humanize + merge_request.title = "Resolve #{issue_iid}" + merge_request.title += " \"#{branch_title}\"" unless branch_title.empty? + end end def issue_iid - @issue_iid ||= source_branch.match(/\A(\d+)-/).try(:[], 1) + strong_memoize(:issue_iid) do + @params_issue_iid || begin + id = if target_project.external_issue_tracker + source_branch.match(target_project.external_issue_reference_pattern).try(:[], 0) + end + + id || source_branch.match(/\A(\d+)-/).try(:[], 1) + end + end end def issue |