diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-05-06 12:14:13 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-05-06 12:14:13 +0000 |
commit | 0cdd4f310fed3d42c61060dd52dba96884638bb3 (patch) | |
tree | 1c803d154e88ae21a5445e806d5462f4fcb485f8 /app/services | |
parent | e65b78c6f1a05b01dc9e6a2e7042cc530718a904 (diff) | |
parent | 09209725cee58b3d9645b8cf58ec955b566f5b5b (diff) | |
download | gitlab-ce-0cdd4f310fed3d42c61060dd52dba96884638bb3.tar.gz |
Merge branch '14564-mr-automatic-title' into 'master'
Auto-set title for branches created from issues
This sets the title for a new MR to 'Resolves "$issue-title"' when:
- The source branch for the MR begins with a value iid.
- The MR has more than one commit in its diff (if there's one commit, keep using the commit's first line).
- The iid does not point to a confidential issue.
Single commit:
![A single commit uses the commit title](/uploads/cd34f59cd67f095c3034fae07950f8b5/image.png)
Multiple commits:
![Multiple commits use the issue title](/uploads/a322c406ddd56913c5aebd88d16e5a5e/image.png)
Confidential issue:
![A confidential issue uses the branch name](/uploads/7ae9b79de5f6101ced46802f3c3a6e71/image.png)
cc @DouweM @zj
Closes #14564
See merge request !3966
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/merge_requests/build_service.rb | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/app/services/merge_requests/build_service.rb b/app/services/merge_requests/build_service.rb index 3544752d47a..cd4230aa5e4 100644 --- a/app/services/merge_requests/build_service.rb +++ b/app/services/merge_requests/build_service.rb @@ -41,21 +41,45 @@ module MergeRequests merge_request.can_be_created = false end + set_title_and_description(merge_request) + end + + private + + # When your branch name starts with an iid followed by a dash this pattern will be + # interpreted as the user wants to close that issue on this project. + # + # For example: + # - Issue 112 exists, title: Emoji don't show up in commit title + # - Source branch is: 112-fix-mep-mep + # + # Will lead to: + # - Appending `Closes #112` to the description + # - Setting the title as 'Resolves "Emoji don't show up in commit title"' if there is + # more than one commit in the MR + # + def set_title_and_description(merge_request) + if match = merge_request.source_branch.match(/\A(\d+)-/) + iid = match[1] + end + commits = merge_request.compare_commits if commits && commits.count == 1 commit = commits.first merge_request.title = commit.title merge_request.description ||= commit.description.try(:strip) + elsif iid && (issue = merge_request.target_project.get_issue(iid)) && !issue.try(:confidential?) + case issue + when Issue + merge_request.title = "Resolve \"#{issue.title}\"" + when ExternalIssue + merge_request.title = "Resolve #{issue.title}" + end else merge_request.title = merge_request.source_branch.titleize.humanize end - # When your branch name starts with an iid followed by a dash this pattern will - # be interpreted as the use wants to close that issue on this project - # Pattern example: 112-fix-mep-mep - # Will lead to appending `Closes #112` to the description - if match = merge_request.source_branch.match(/\A(\d+)-/) - iid = match[1] + if iid closes_issue = "Closes ##{iid}" if merge_request.description.present? |