Commit 17b9aa47 authored by Piotr Stankowski's avatar Piotr Stankowski

Add squash commit template field in project settings and docs

This change allows editing project's squash_commit_template
in project settings. Additionally it adds documentation
on squash commit template feature.
parent 42375dd4
......@@ -12,5 +12,7 @@
= render 'projects/merge_request_merge_commit_template', project: @project, form: form
= render 'projects/merge_request_squash_commit_template', project: @project, form: form
- if @project.forked?
= render 'projects/merge_request_target_project_settings', project: @project, form: form
- form = local_assigns.fetch(:form)
.form-group
%b= s_('ProjectSettings|Squash commit message template')
%p.text-secondary
- configure_the_squash_commit_message_help_link_url = help_page_path('user/project/merge_requests/commit_templates.md', anchor: 'squash-commit-message-template')
- configure_the_squash_commit_message_help_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: configure_the_squash_commit_message_help_link_url }
= s_('ProjectSettings|The commit message used when squashing commits. %{link_start}Learn more about syntax and variables.%{link_end}').html_safe % { link_start: configure_the_squash_commit_message_help_link_start, link_end: '</a>'.html_safe }
.mb-2
= form.text_area :squash_commit_template, class: 'form-control gl-form-input', rows: 8, maxlength: 500, placeholder: '%{title}'
%p.form-text.text-muted
= s_('ProjectSettings|Maximum 500 characters.')
= s_('ProjectSettings|Supported variables:')
- Gitlab::MergeRequests::CommitMessageGenerator::PLACEHOLDERS.keys.each do |placeholder|
%code
= "%{#{placeholder}}".html_safe
......@@ -31,7 +31,7 @@ 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)
![Custom commit message for merge commit](img/merge_commit_message_template_v14_5.png)
You can use static text and following variables:
......@@ -49,3 +49,18 @@ Empty variables that are the only word in a line will be removed along with all
Merge commit template field has a limit of 500 characters. This limit only applies to the template
itself.
## Squash commit message template
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/345275) in GitLab 14.6.
As a project maintainer, you're able to configure squash commit message template. It will be used during merge with
squash to create squash commit message. It uses the same syntax and variables as merge commit message template.
![Custom commit message for squash commit](img/squash_commit_message_template_v14_6.png)
Default squash commit message can be recreated using following template:
```plaintext
%{title}
```
......@@ -28,9 +28,9 @@ NOTE:
The squashed commit in this example is followed by a merge commit, because the merge method for this repository uses a merge commit. You can disable merge commits in
**Project Settings > General > Merge requests > Merge method > Fast-forward merge**.
The squashed commit's default commit message is taken from the merge request title.
The squashed commit's default commit message is taken from the merge request title. It can be changed using [squash commit message template](commit_templates.md#squash-commit-message-template).
It can be customized before merging a merge request.
It can also be customized before merging a merge request.
![A squash commit message editor](img/squash_mr_message.png)
......
......@@ -315,7 +315,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 [merge and squash commit message templates](../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
......
......@@ -15,6 +15,8 @@
= render_ce 'projects/merge_request_merge_commit_template', project: @project, form: form
= render_ce 'projects/merge_request_squash_commit_template', project: @project, form: form
- if @project.forked?
= render_ce 'projects/merge_request_target_project_settings', project: @project, form: form
......
......@@ -27407,6 +27407,9 @@ msgstr ""
msgid "ProjectSettings|Snippets"
msgstr ""
msgid "ProjectSettings|Squash commit message template"
msgstr ""
msgid "ProjectSettings|Squash commits when merging"
msgstr ""
......@@ -27431,6 +27434,9 @@ 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 commit message used when squashing commits. %{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 ""
......
......@@ -92,6 +92,22 @@ RSpec.describe 'projects/edit' do
end
end
context 'squash template' do
it 'displays a placeholder if none is set' do
render
expect(rendered).to have_field('project[squash_commit_template]', placeholder: '%{title}')
end
it 'displays the user entered value' do
project.update!(squash_commit_template: '%{first_multiline_commit}')
render
expect(rendered).to have_field('project[squash_commit_template]', with: '%{first_multiline_commit}')
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