diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-02-02 17:24:30 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-02-02 17:24:30 +0000 |
commit | 5c08a59150c5610ec901ced7dafa43c51d1a7dbb (patch) | |
tree | 364b4bd053e227f8b1974c9e12bef305ca4c42b8 /app/services | |
parent | e685acbaf5f83ee5c78455784145300abe5dd381 (diff) | |
parent | f0e7d79c8b21c798b4793ee7d037683941c4d6e6 (diff) | |
download | gitlab-ce-5c08a59150c5610ec901ced7dafa43c51d1a7dbb.tar.gz |
Merge branch '40793-fix-mr-title-for-jira' into 'master'
Resolve "Incorrect merge request title when Jira activated and multiple commits on branch"
Closes #40793
See merge request gitlab-org/gitlab-ce!16491
Diffstat (limited to 'app/services')
-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 |