Skip to content

Add squash commit message template

What does this MR do and why?

This adds squash commit message templates and solves #345275 (closed)

This is the same feature as in !64437 (merged), but for squash commits instead of merge commits.

For now it supports only the same variables as merge commits, I think it's better to add more in separate MRs.

This is MR is a step in solving #330646 (closed) - in next MR we could just add %{first_multiline_commit} variable to templating in order to allow using existing commit message.

There's also issue for adding all commit messages - #26303 (closed) - we could later possibly solve it by adding %{all_commit_messages} variable.

Screenshots or screen recordings

Screen recording (some copy is out of date for recording):

2021-11-12_10-42__Display__OC_Studio_

Updated screenshots:

Screenshots - click to expand

Project settings - squash commit message template is right after merge one:

image

Without restructure_mr_widget feature enabled:

Note the "To change this default message(s)" hint, it depends on what's visible now:

image

image

image

With restructure_mr_widget feature enabled:

image

image

image

Docs:

image

How to set up and validate locally

I have some problems on gdk with getting merge widget to show for existing preseeded MRs, so I always create new MRs.

Here's how I validated it:

  1. Push a branch with more than one commit to any project.
  2. Create a MR with that branch.
  3. Expand MR widget, validate the docs link in templates hint.
  4. Check "squash commits", make sure that the templates hint now mentions squash template.
  5. Check the linked docs from that hint.
  6. Change project settings to FF merge.
  7. Make sure that the docs hint in merge widget doesn't mention merge commit now.
  8. Change squash commit template in project settings.
  9. Validate that it changes default value for squash commit message in merge widget.
  10. Enable restructured_mr_widget feature flag and repeat testing.
There are also some API endpoints that are worth a check:

Make sure that fetching project response have squash_commit_template:

GET http://localhost:3000/api/v4/projects/6
Accept: application/json
Authorization: Bearer gogYNH8yySDrQUX9VNZB

Make sure that updating squash_commit_template through API works:

PUT http://localhost:3000/api/v4/projects/6
Accept: application/json
Content-Type: application/json
Authorization: Bearer ypCa3Dzb23o5nvsixwPA

{
  "squash_commit_template": "%{title}\n\nSquashed branch %{source_branch}\n\nMR: %{reference}"
}

Make sure that, when merging through API without specifying squash message, it uses template:

PUT http://localhost:3000/api/v4/projects/6/merge_requests/11/merge
Accept: application/json
Content-Type: application/json
Authorization: Bearer ypCa3Dzb23o5nvsixwPA

{
  "squash": true
}

Make sure that squashCommitTemplate can be fetched using graphql:

query {
  project(fullPath: "flightjs/Flight") {
    squashCommitTemplate
  }
}

Database migration

This MR:

  • Adds column squash_commit_template to project_settings in AddSquashCommitTemplateToProjectSettings.
  • Sets 500 character length limit for that column in AddSquashCommitTemplateLimitToProjectSettings.
Migration log:
$ rake db:migrate
== 20211111164025 AddSquashCommitTemplateToProjectSettings: migrating =========
-- add_column(:project_settings, :squash_commit_template, :text)
   -> 0.0008s
== 20211111164025 AddSquashCommitTemplateToProjectSettings: migrated (0.0008s)

== 20211111164047 AddSquashCommitTemplateLimitToProjectSettings: migrating ====
-- transaction_open?()
   -> 0.0000s
-- current_schema()
   -> 0.0001s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE project_settings\nADD CONSTRAINT check_b09644994b\nCHECK ( char_length(squash_commit_template) <= 500 )\nNOT VALID;\n")
   -> 0.0006s
-- current_schema()
   -> 0.0001s
-- execute("SET statement_timeout TO 0")
   -> 0.0003s
-- execute("ALTER TABLE project_settings VALIDATE CONSTRAINT check_b09644994b;")
   -> 0.0004s
-- execute("RESET statement_timeout")
   -> 0.0003s
== 20211111164047 AddSquashCommitTemplateLimitToProjectSettings: migrated (0.0048s)

$ rake db:migrate:down VERSION=20211111164047
== 20211111164047 AddSquashCommitTemplateLimitToProjectSettings: reverting ====
-- transaction_open?()
   -> 0.0000s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE project_settings\nDROP CONSTRAINT IF EXISTS check_b09644994b\n")
   -> 0.0006s
== 20211111164047 AddSquashCommitTemplateLimitToProjectSettings: reverted (0.0053s)

$ rake db:migrate:down VERSION=20211111164025
== 20211111164025 AddSquashCommitTemplateToProjectSettings: reverting =========
-- remove_column(:project_settings, :squash_commit_template, :text)
   -> 0.0007s
== 20211111164025 AddSquashCommitTemplateToProjectSettings: reverted (0.0022s)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Piotr Stankowski

Merge request reports

Loading