Commit 316bacde authored by Arturo Herrero's avatar Arturo Herrero

Merge branch '300479-change-prefilled-mr-title-description' into 'master'

Set default MR title/description to first multi-line commit

See merge request gitlab-org/gitlab!52984
parents 15e5c966 7022db84
......@@ -1282,7 +1282,14 @@ class MergeRequest < ApplicationRecord
# Returns the oldest multi-line commit message, or the MR title if none found
def default_squash_commit_message
strong_memoize(:default_squash_commit_message) do
recent_commits.without_merge_commits.reverse_each.find(&:description?)&.safe_message || title
first_multiline_commit&.safe_message || title
end
end
# Returns the oldest multi-line commit
def first_multiline_commit
strong_memoize(:first_multiline_commit) do
recent_commits.without_merge_commits.reverse_each.find(&:description?)
end
end
......
......@@ -58,6 +58,7 @@ module MergeRequests
:compare_commits,
:wip_title,
:description,
:first_multiline_commit,
:errors,
to: :merge_request
......@@ -196,7 +197,8 @@ module MergeRequests
# 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
# - Issue 112 exists
# - title: Emoji don't show up in commit title
# - Source branch is: 112-fix-mep-mep
#
# Will lead to:
......@@ -205,7 +207,7 @@ module MergeRequests
# more than one commit in the MR
#
def assign_title_and_description
assign_title_and_description_from_single_commit
assign_title_and_description_from_commits
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?
......@@ -240,12 +242,16 @@ module MergeRequests
end
end
def assign_title_and_description_from_single_commit
def assign_title_and_description_from_commits
commits = compare_commits
return unless commits&.count == 1
if commits&.count == 1
commit = commits.first
else
commit = first_multiline_commit
return unless commit
end
commit = commits.first
merge_request.title ||= commit.title
merge_request.description ||= commit.description.try(:strip)
end
......
---
title: Prefill first multiline commit message for new MRs
merge_request: 52984
author: Max Coplan @vegerot
type: changed
......@@ -30,11 +30,16 @@ button and start a merge request from there.
## New Merge Request page
On the **New Merge Request** page, start by filling in the title
and description for the merge request. If there are already
commits on the branch, the title is prefilled with the first
line of the first commit message, and the description is
prefilled with any additional lines in the commit message.
On the **New Merge Request** page, start by filling in the title and description
for the merge request. If commits already exist on the branch, GitLab suggests a
merge request title for you:
- **If a multi-line commit message exists**: GitLab adds the first line of the
first multi-line commit message as the title. Any additional lines in that
commit message become the description.
- **If no multi-line commit message exists**: GitLab adds the branch name as the
title, and leaves the description blank.
The title is the only field that is mandatory in all cases.
From there, you can fill it with information (title, description,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment