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 the squash flag.
  • The merge_request_squash_commit_message beta 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 defaultSquashCommitMessage field (template placeholder expansion, which can call Gitaly for commit placeholders). The field is marked calls_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_sha for the exact commit.

References

Screenshots or screen recordings

Not applicable, this MR has no UI changes.

How to set up and validate locally

  1. In a Rails console, enable the feature flag:

    Feature.enable(:merge_request_squash_commit_message)
  2. Open GraphiQL at http://127.0.0.1:3000/-/graphql-explorer and run the query below for a merge request you can update:

    {
      project(fullPath: "gitlab-org/gitlab-test") {
        mergeRequest(iid: "1") {
          squash
          squashOnMerge
          defaultSquashCommitMessage
          squashCommitMessage
        }
      }
    }
  3. With squash disabled on the merge request and no project squash option, squashCommitMessage is null.

  4. Enable Squash commits when merge request is accepted. squashCommitMessage is the title, or the rendered project squash commit template.

  5. Set auto-merge with a custom squash commit message. squashCommitMessage returns that message.

  6. Run the query as a Guest, Reporter or signed out on a public project. squashCommitMessage returns the same message.

  7. Disable the flag with Feature.disable(:merge_request_squash_commit_message). squashCommitMessage is null.

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.

Edited by Joe Woodward

Merge request reports

Loading
Loading