Add experimental GraphQL field for squash commit message
What does this MR do and why?
Adds an experimental MergeRequest.squashCommitMessage GraphQL field (milestone 19.6) that returns the message the squash commit will have when the merge request is merged.
This lets gitlab-dangerfiles lint the real squash commit message instead of replicating the squash message logic on the Danger side. Today Danger::CommitMessages only reads mr_json["squash"] and assumes the oldest multi-line commit message survives the squash.
The field returns null when:
- The merge request is not going to be squashed. This uses
MergeRequest#squash_on_merge?, so project squash options that force or forbid squashing are respected, not only thesquashflag. - The
merge_request_squash_commit_messagebeta feature flag is disabled. The flag is disabled by default and is checked per target project.
Like defaultSquashCommitMessage, the field has no field-level authorization, so anyone who can read the merge request can read it. This includes a custom message stored on the merge request by another user.
Otherwise it returns the custom squash_commit_message stored in the merge params (set with auto-merge), falling back to default_squash_commit_message, which is the project squash commit template or the merge request title. This follows the same order as MergeRequests::CreateRefService#squash_commit_message and MergeRequests::SquashService#message.
Implementation notes
MergeRequest#squash_commit_message_on_merge(user:)holds the logic, and the GraphQL type delegates to it.- There is no caching. The cost is the same as the existing
defaultSquashCommitMessagefield (template placeholder expansion, which can call Gitaly for commit placeholders). The field is markedcalls_gitaly: true. - Known limitation: a message typed into the merge widget is only persisted on the merge request when auto-merge is set. For a plain "Merge" click nothing is stored beforehand, so the field returns the default message.
- Known limitation: for a merged merge request the field recomputes the message from current data, so it can differ from the commit that was created. The REST API exposes
squash_commit_shafor the exact commit.
References
- Rollout issue: #636015
- gitlab-dangerfiles
Danger::CommitMessages: https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/blob/master/lib/danger/plugins/commit_messages.rb
Screenshots or screen recordings
Not applicable, this MR has no UI changes.
How to set up and validate locally
-
In a Rails console, enable the feature flag:
Feature.enable(:merge_request_squash_commit_message) -
Open GraphiQL at
http://127.0.0.1:3000/-/graphql-explorerand run the query below for a merge request you can update:{ project(fullPath: "gitlab-org/gitlab-test") { mergeRequest(iid: "1") { squash squashOnMerge defaultSquashCommitMessage squashCommitMessage } } } -
With squash disabled on the merge request and no project squash option,
squashCommitMessageisnull. -
Enable Squash commits when merge request is accepted.
squashCommitMessageis the title, or the rendered project squash commit template. -
Set auto-merge with a custom squash commit message.
squashCommitMessagereturns that message. -
Run the query as a Guest, Reporter or signed out on a public project.
squashCommitMessagereturns the same message. -
Disable the flag with
Feature.disable(:merge_request_squash_commit_message).squashCommitMessageisnull.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.