Commit 8b543a42 authored by trakos's avatar trakos Committed by Piotr Stankowski

Add merge commit template field in project settings and docs

This change allows editing project's merge_commit_template
in project settings. Additionally it adds documentation
on merge commit template feature.
parent 61729d8a
- form = local_assigns.fetch(:form)
.form-group
%b= s_('ProjectSettings|Merge commit message template')
%p.text-secondary
- configure_the_merge_commit_message_help_link_url = help_page_path('user/project/merge_requests/commit_templates.md', anchor: 'merge-commit-message-template')
- configure_the_merge_commit_message_help_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: configure_the_merge_commit_message_help_link_url }
= s_('ProjectSettings|The commit message used when merging, if the merge method creates a merge commit. %{link_start}Learn more about syntax and variables.%{link_end}').html_safe % { link_start: configure_the_merge_commit_message_help_link_start, link_end: '</a>'.html_safe }
.mb-2
- default_merge_commit_template = "Merge branch '%{source_branch}' into '%{target_branch}'\n\n%{title}\n\n%{issues}\n\nSee merge request %{reference}"
= form.text_area :merge_commit_template, class: 'form-control gl-form-input', rows: 8, maxlength: 500, placeholder: default_merge_commit_template
%p.form-text.text-muted
= s_('ProjectSettings|Maximum 500 characters.')
= s_('ProjectSettings|Supported variables:')
- Gitlab::MergeRequests::MergeCommitMessage::PLACEHOLDERS.keys.each do |placeholder|
%code
= "%{#{placeholder}}".html_safe
......@@ -10,5 +10,7 @@
= render 'projects/merge_request_merge_suggestions_settings', project: @project, form: form
= render 'projects/merge_request_merge_commit_template', project: @project, form: form
- if @project.forked?
= render 'projects/merge_request_target_project_settings', project: @project, form: form
---
stage: Create
group: Code Review
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
type: reference, howto
---
# Commit message templates **(FREE)**
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/20263) in GitLab 14.5.
## Merge commit message template
As a project maintainer, you're able to configure merge commit message template. It will be used during merge to
create commit message. Template uses similar syntax to
[review suggestions](reviews/suggestions.md#configure-the-commit-message-for-applied-suggestions).
Default merge commit message can be recreated using following template:
```plaintext
Merge branch '%{source_branch}' into '%{target_branch}'
%{title}
%{issues}
See merge request %{reference}
```
This commit message can be customized to follow any guidelines you might have.
To do so, expand the **Merge requests** tab within your project's **General**
settings and change the **Merge commit message template** text:
![Custom commit message for applied suggestions](img/merge_commit_message_template_v14_5.png)
You can use static text and following variables:
| Variable | Description | Output example |
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
| `%{source_branch}` | The name of the branch that is being merged. | `my-feature-branch` |
| `%{target_branch}` | The name of the branch that the changes are applied to. | `master` |
| `%{title}` | Title of the merge request. | Fix stuff |
| `%{issues}` | String with phrase "Closes <issue numbers>" with all issues mentioned in the MR description matching [issue closing patterns](../issues/managing_issues.md#closing-issues-automatically). It will be empty when no issues were mentioned. | `Closes #465, #190 and #400` |
| `%{description}` | Description of the merge request. | Merge request description.<br>Can be multiline. |
| `%{reference}` | Reference to the merge request. | group-name/project-name!72359 |
NOTE:
Empty variables that are the only word in a line will be removed along with all newline characters preceding it.
Merge commit template field has a limit of 500 characters. This limit only applies to the template
itself.
......@@ -310,6 +310,7 @@ Set up your project's merge request settings:
- Enable [require an associated issue from Jira](../../../integration/jira/issues.md#require-associated-jira-issue-for-merge-requests-to-be-merged).
- Enable [`delete source branch after merge` option by default](../merge_requests/getting_started.md#deleting-the-source-branch).
- Configure [suggested changes commit messages](../merge_requests/reviews/suggestions.md#configure-the-commit-message-for-applied-suggestions).
- Configure [merge commit message template](../merge_requests/commit_templates.md).
- Configure [the default target project](../merge_requests/creating_merge_requests.md#set-the-default-target-project) for merge requests coming from forks.
### Service Desk
......
......@@ -13,6 +13,8 @@
= render 'projects/merge_request_merge_suggestions_settings', project: @project, form: form
= render_ce 'projects/merge_request_merge_commit_template', project: @project, form: form
- if @project.forked?
= render_ce 'projects/merge_request_target_project_settings', project: @project, form: form
......
......@@ -27144,12 +27144,18 @@ msgstr ""
msgid "ProjectSettings|Manages large files such as audio, video, and graphics files."
msgstr ""
msgid "ProjectSettings|Maximum 500 characters."
msgstr ""
msgid "ProjectSettings|Merge checks"
msgstr ""
msgid "ProjectSettings|Merge commit"
msgstr ""
msgid "ProjectSettings|Merge commit message template"
msgstr ""
msgid "ProjectSettings|Merge commit with semi-linear history"
msgstr ""
......@@ -27267,6 +27273,9 @@ msgstr ""
msgid "ProjectSettings|The commit message used when applying merge request suggestions. %{link_start}Learn more about suggestions.%{link_end}"
msgstr ""
msgid "ProjectSettings|The commit message used when merging, if the merge method creates a merge commit. %{link_start}Learn more about syntax and variables.%{link_end}"
msgstr ""
msgid "ProjectSettings|The default target project for merge requests created in this fork project."
msgstr ""
......
......@@ -57,6 +57,41 @@ RSpec.describe 'projects/edit' do
end
end
context 'merge commit template' do
it 'displays all possible variables' do
render
expect(rendered).to have_content('%{source_branch}')
expect(rendered).to have_content('%{target_branch}')
expect(rendered).to have_content('%{title}')
expect(rendered).to have_content('%{issues}')
expect(rendered).to have_content('%{description}')
expect(rendered).to have_content('%{reference}')
end
it 'displays a placeholder if none is set' do
render
expect(rendered).to have_field('project[merge_commit_template]', placeholder: <<~MSG.rstrip)
Merge branch '%{source_branch}' into '%{target_branch}'
%{title}
%{issues}
See merge request %{reference}
MSG
end
it 'displays the user entered value' do
project.update!(merge_commit_template: '%{title}')
render
expect(rendered).to have_field('project[merge_commit_template]', with: '%{title}')
end
end
context 'forking' do
before do
assign(:project, project)
......
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