Add commits_count variable to commit message templates
Merge and squash commit templates can list every commit message with %{all_commits}, but there is no way to include just the number of commits, which is a common thing to want in a merge commit subject (for example Merge branch 'x' (3 commits)).
This MR adds %{commits_count}, backed by MergeRequest#commits_count. It is also allowed in new merge request description templates (ALLOWED_NEW_MR_PLACEHOLDERS), where the count comes from the compared commits, the same source %{all_commits} uses there.
Documentation lists the new variable with a version note.
Resolves #383062
Differences
Before: A template such as %{title} (%{commits_count} commits) leaves the variable unexpanded.
After: The same template renders as Bugfix (3 commits). In a new MR description template the count reflects the commits being compared at creation time.
How to set up and Validate locally:
- In a project, go to Settings > Merge requests > Merge commit message template and set it to
%{title} - %{commits_count} commit(s). - Merge a merge request with more than one commit and check the merge commit subject.
- Specs:
bundle exec rspec spec/lib/gitlab/merge_requests/message_generator_spec.rb