Page MenuHomePhabricator

GitLab's default commit templates often lose the text of existing commit messages
Closed, ResolvedPublic

Description

Writing this up after discussion with @thcipriani and @Aklapper.

Problem: GitLab has a concept of commit templates. The default, especially for squashed MRs, is bad.

Docs:

https://gitlab.wikimedia.org/help/user/project/merge_requests/commit_templates

The default message for squashed commits, in its entirety:

%{title}

This is just the title of the merge request, and it tends to lose nearly all of the information in commit bodies. This is a bad default. It results in a less useful history and discourages good commit message practices.

Proposed hack: Use gitlab-settings/configure-projects to set a better template.

It's possible to define custom commit message templates on, at least, a per project basis:

GitLab uses commit templates to create default messages for specific types of commits. These templates encourage commit messages to follow a particular format, or contain specific information. Users can override these templates when merging a merge request.

We could use the configure-projects script to set sensible defaults for all projects on the instance.

There's an %{all_commits} value available for everything in the merge request (up to 100 commits, anyway).

The projects API has:

"suggestion_commit_message": null,
"merge_commit_template": null,
"squash_commit_template": null,

Upstream alternatives: It would be ideal to instead get the default fixed upstream. Maybe this has already occurred to someone, but I haven't found anything yet.

I didn't find any existing issues under these searches:

I'll do some more looking or write an issue.

Event Timeline

Mentioned in SAL (#wikimedia-releng) [2024-06-18T20:53:32Z] <brennen> gitlab: squash commit templates: update all projects to use %{all_commits} (T366624)

Filed upstream: https://gitlab.com/gitlab-org/gitlab/-/issues/468067

...and closed as "won't do". There's some background here, for future reference.

Mentioned in SAL (#wikimedia-releng) [2024-07-01T17:06:51Z] <brennen> gitlab: once again setting default squash commit template for all projects, per MR discussion on T366624

Change #1051178 had a related patch set uploaded (by Brennen Bearnes; author: Brennen Bearnes):

[operations/puppet@production] gitlab-settings: v1.6.0 for squash commit templates

https://gerrit.wikimedia.org/r/1051178

Change #1051178 merged by Jelto:

[operations/puppet@production] gitlab-settings: v1.6.0 for squash commit templates

https://gerrit.wikimedia.org/r/1051178

brennen claimed this task.
brennen moved this task from Waiting Response to Done or Declined on the User-brennen board.