Skip to content

feat: Add support for auto-merge and squash options in merge requests#235

Closed
kriakiku wants to merge 2 commits into
un-ts:mainfrom
kriakiku:main
Closed

feat: Add support for auto-merge and squash options in merge requests#235
kriakiku wants to merge 2 commits into
un-ts:mainfrom
kriakiku:main

Conversation

@kriakiku

@kriakiku kriakiku commented Apr 17, 2026

Copy link
Copy Markdown

Summary

Adds three optional inputs to support auto-merge and squash behavior for merge requests:

  • INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS
  • INPUT_SQUASH
  • INPUT_SQUASH_COMMIT_MESSAGE

Why these options are set via accept

This is implemented through the accept API path because GitLab API support for these merge options is handled there, not through a regular merge request update in the same way.

Reference: GitBeaker issue comment

Behavior

  • INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS
    Sets auto-merge on the created merge request (merge when all checks pass).
    If not set, no changes are made.

  • INPUT_SQUASH
    Enables or disables squash commits for the merge request.
    If not set, no changes are made.

  • INPUT_SQUASH_COMMIT_MESSAGE
    Optional squash commit message used when squash is enabled.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added three new optional configuration inputs for managing GitLab merge request behavior: automatically merge when pipeline succeeds, toggle commit squashing for merge requests, and customize squash commit messages.
  • Documentation

    • Updated README with documentation for the new GitLab CI configuration inputs.

@changeset-bot

changeset-bot Bot commented Apr 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1b2e758

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
changesets-gitlab Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Apr 17, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request introduces three new optional GitLab CI inputs for controlling merge request auto-merge and squash behavior: INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS, INPUT_SQUASH, and INPUT_SQUASH_COMMIT_MESSAGE. These are parsed from inputs, passed through the runVersion function, and applied to merge request acceptance.

Changes

Cohort / File(s) Summary
Changelog & Documentation
.changeset/gold-rice-cry.md, README.md
Added changelog entry and documented three new optional GitLab CI inputs for merge request auto-merge and squash configuration.
Input Parsing
src/main.ts, src/utils.ts
Added getOptionalBooleanInput utility function and refactored input parsing to use typed boolean parsing for new merge request options; reordered boolean value constants.
Merge Request Logic
src/run.ts
Extended VersionOptions interface with mergeWhenPipelineSucceeds, squash, and squashCommitMessage parameters; added conditional merge request acceptance logic to update merge-time settings when values differ from current state.

Sequence Diagram(s)

sequenceDiagram
    participant Input as GitHub Actions<br/>Inputs
    participant Main as src/main.ts
    participant Utils as src/utils.ts
    participant Run as src/run.ts
    participant GitLab as GitLab API

    Input->>Main: Provide CI inputs
    Main->>Utils: getOptionalBooleanInput()
    Utils-->>Main: Parse boolean values
    Main->>Run: Call runVersion() with<br/>merge options
    Run->>GitLab: Create/Edit Merge Request
    GitLab-->>Run: Return MergeRequestSchema
    Run->>Run: Compare current vs desired<br/>merge options
    alt Options differ
        Run->>GitLab: Accept MergeRequest<br/>with AcceptOptions
        GitLab-->>Run: Updated merge request
    end
    Run-->>Main: Completion status
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • JounQin

Poem

🐰 Merges dance with pipelines true,
Squash and merge—fresh automated brew!
GitLab bows to inputs three,
Control flows through, wild and free!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: Add support for auto-merge and squash options in merge requests' accurately and specifically describes the main feature addition throughout the changeset—introducing three new optional inputs (INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS, INPUT_SQUASH, INPUT_SQUASH_COMMIT_MESSAGE) to control merge request behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
README.md (1)

32-34: Consider documenting the behavioral caveat.

Worth noting that INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS=true results in GitLab auto-merging the MR when the pipeline succeeds (i.e., it will be merged without further user action), since the implementation uses the "accept" API. Users who only want to flip the checkbox state may be surprised.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` around lines 32 - 34, Add a note to the README explaining that
setting INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS=true will trigger GitLab to accept
(auto-merge) the merge request when the pipeline succeeds (using the "accept"
API), meaning the MR will be merged automatically rather than merely toggling a
UI checkbox; reference the INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS variable name and
mention the accept API behavior so users who only want to change the checkbox
state are warned.
src/run.ts (2)

338-343: Setting squash on edit but not squashCommitMessage.

mergeRequestOptions persists the squash flag on the MR via edit, but squashCommitMessage is only applied through the accept path. If users want the squash commit message pre-populated on the MR (visible in the GitLab UI before merging), consider including it in EditMergeRequestOptions too, which also avoids relying on the accept endpoint for this setting.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/run.ts` around lines 338 - 343, mergeRequestOptions currently sets squash
but never includes squashCommitMessage, so the MR edit won't pre-populate the
squash commit message in the GitLab UI; update the code that builds
EditMergeRequestOptions (the mergeRequestOptions object) to add
squashCommitMessage when available (the same source/value used in the accept
path) so EditMergeRequestOptions includes both squash and squashCommitMessage,
ensuring the MR is edited to contain the commit message prior to accept.

337-343: Use ExpandedMergeRequestSchema for more accurate type annotation.

mergeRequest is typed as MergeRequestSchema, but @gitbeaker/core's MergeRequests.create() and MergeRequests.edit() both return ExpandedMergeRequestSchema. The accessed fields (iid, merge_when_pipeline_succeeds, squash_commit_message) exist on both types, so this compiles, but the expanded type is the actual return type and would be more precise.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/run.ts` around lines 337 - 343, Change the type of the local variable
mergeRequest from MergeRequestSchema to ExpandedMergeRequestSchema to match the
actual return type of MergeRequests.create() and MergeRequests.edit(); import
ExpandedMergeRequestSchema from `@gitbeaker/core` if not already imported and keep
the existing mergeRequest usage (fields like iid, merge_when_pipeline_succeeds,
squash_commit_message) and the mergeRequestOptions (EditMergeRequestOptions,
mrBodyPromise, removeSourceBranch, labels, squash) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/run.ts`:
- Around line 365-390: The current logic builds acceptRequest and calls
api.MergeRequests.accept which will immediately merge the MR unless
merge_when_pipeline_succeeds=true; change this to only call
api.MergeRequests.accept when mergeWhenPipelineSucceeds === true (and include
that field in acceptRequest), and when mergeWhenPipelineSucceeds is undefined or
false but only squash/squashCommitMessage need updating, call
api.MergeRequests.edit (the MR edit endpoint) to persist
squash_commit_message/squash settings instead of accept; locate the accept flow
(acceptRequest variable, MergeRequests.accept call, and the checks around
mergeWhenPipelineSucceeds, squash, and squashCommitMessage) and split the logic
so accept is used exclusively for the auto-merge-when-pipeline-succeeds case
while edits use MergeRequests.edit for settings-only updates.

---

Nitpick comments:
In `@README.md`:
- Around line 32-34: Add a note to the README explaining that setting
INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS=true will trigger GitLab to accept
(auto-merge) the merge request when the pipeline succeeds (using the "accept"
API), meaning the MR will be merged automatically rather than merely toggling a
UI checkbox; reference the INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS variable name and
mention the accept API behavior so users who only want to change the checkbox
state are warned.

In `@src/run.ts`:
- Around line 338-343: mergeRequestOptions currently sets squash but never
includes squashCommitMessage, so the MR edit won't pre-populate the squash
commit message in the GitLab UI; update the code that builds
EditMergeRequestOptions (the mergeRequestOptions object) to add
squashCommitMessage when available (the same source/value used in the accept
path) so EditMergeRequestOptions includes both squash and squashCommitMessage,
ensuring the MR is edited to contain the commit message prior to accept.
- Around line 337-343: Change the type of the local variable mergeRequest from
MergeRequestSchema to ExpandedMergeRequestSchema to match the actual return type
of MergeRequests.create() and MergeRequests.edit(); import
ExpandedMergeRequestSchema from `@gitbeaker/core` if not already imported and keep
the existing mergeRequest usage (fields like iid, merge_when_pipeline_succeeds,
squash_commit_message) and the mergeRequestOptions (EditMergeRequestOptions,
mrBodyPromise, removeSourceBranch, labels, squash) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 40357d2b-280c-4928-b6e8-9022c96cf4f6

📥 Commits

Reviewing files that changed from the base of the PR and between eccf474 and 1b2e758.

📒 Files selected for processing (5)
  • .changeset/gold-rice-cry.md
  • README.md
  • src/main.ts
  • src/run.ts
  • src/utils.ts

Comment thread src/run.ts
Comment on lines +365 to 390
const acceptRequest: AcceptMergeRequestOptions = {}
if (
mergeWhenPipelineSucceeds !== undefined &&
mergeRequest.merge_when_pipeline_succeeds !== mergeWhenPipelineSucceeds
) {
acceptRequest.mergeWhenPipelineSucceeds = mergeWhenPipelineSucceeds
}
if (
squash === true &&
squashCommitMessage !== undefined &&
mergeRequest.squash_commit_message !== squashCommitMessage
) {
acceptRequest.squashCommitMessage = squashCommitMessage
}

if (Object.keys(acceptRequest).length > 0) {
console.log(
`updating merge request !${mergeRequest.iid} with options:`,
acceptRequest,
)
await api.MergeRequests.accept(
context.projectId,
mergeRequest.iid,
acceptRequest,
)
}

@coderabbitai coderabbitai Bot Apr 17, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Calling MergeRequests.accept can merge the MR immediately — guard against unintended merges.

GitLab's accept endpoint (PUT /merge_requests/:iid/merge) performs a merge, not a settings update. It only defers to auto-merge when merge_when_pipeline_succeeds=true is sent and there is a pipeline in progress. Otherwise, if the MR is mergeable, it will be merged immediately. This produces at least two problematic scenarios with the current logic:

  1. User sets only INPUT_SQUASH_COMMIT_MESSAGE (no INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS). acceptRequest ends up as { squashCommitMessage }, and accept is invoked → the MR can be merged right now, even though the user only wanted to set a squash commit message.
  2. User explicitly sets INPUT_MERGE_WHEN_PIPELINE_SUCCEEDS=false while the MR currently has it true. The diff check passes, accept is called with mergeWhenPipelineSucceeds=false → immediate merge.

Suggested guards:

  • Only call accept when mergeWhenPipelineSucceeds === true (the only case this API was meant to cover here).
  • When mergeWhenPipelineSucceeds !== true but squash/squashCommitMessage differ, persist those via MergeRequests.edit instead (the squash_commit_message field is editable on the MR resource), not via accept.
🔒 Proposed guard
-  const acceptRequest: AcceptMergeRequestOptions = {}
-  if (
-    mergeWhenPipelineSucceeds !== undefined &&
-    mergeRequest.merge_when_pipeline_succeeds !== mergeWhenPipelineSucceeds
-  ) {
-    acceptRequest.mergeWhenPipelineSucceeds = mergeWhenPipelineSucceeds
-  }
-  if (
-    squash === true &&
-    squashCommitMessage !== undefined &&
-    mergeRequest.squash_commit_message !== squashCommitMessage
-  ) {
-    acceptRequest.squashCommitMessage = squashCommitMessage
-  }
-
-  if (Object.keys(acceptRequest).length > 0) {
+  // Only invoke accept when explicitly opting into auto-merge; accept will
+  // otherwise merge the MR immediately.
+  if (
+    mergeWhenPipelineSucceeds === true &&
+    mergeRequest.merge_when_pipeline_succeeds !== true
+  ) {
+    const acceptRequest: AcceptMergeRequestOptions = {
+      mergeWhenPipelineSucceeds: true,
+      ...(squash === true && squashCommitMessage !== undefined
+        ? { squashCommitMessage }
+        : {}),
+    }
     console.log(
       `updating merge request !${mergeRequest.iid} with options:`,
-      acceptRequest,
+      acceptRequest,
     )
     await api.MergeRequests.accept(
       context.projectId,
       mergeRequest.iid,
       acceptRequest,
     )
   }
GitLab API PUT /projects/:id/merge_requests/:merge_request_iid/merge behavior with merge_when_pipeline_succeeds false vs true
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/run.ts` around lines 365 - 390, The current logic builds acceptRequest
and calls api.MergeRequests.accept which will immediately merge the MR unless
merge_when_pipeline_succeeds=true; change this to only call
api.MergeRequests.accept when mergeWhenPipelineSucceeds === true (and include
that field in acceptRequest), and when mergeWhenPipelineSucceeds is undefined or
false but only squash/squashCommitMessage need updating, call
api.MergeRequests.edit (the MR edit endpoint) to persist
squash_commit_message/squash settings instead of accept; locate the accept flow
(acceptRequest variable, MergeRequests.accept call, and the checks around
mergeWhenPipelineSucceeds, squash, and squashCommitMessage) and split the logic
so accept is used exclusively for the auto-merge-when-pipeline-succeeds case
while edits use MergeRequests.edit for settings-only updates.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kriakiku Is this true?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the only way to specify squashCommitMessage and mergeWhenPipelineSucceeds is by calling the Accept endpoint. This may trigger an immediate merge of the request if no additional rules are set up in the repository (such as requiring an approval from someone other than the author). The GitLab API doesn’t allow doing this any other way. Should I update the README to clarify that setting these parameters via the Accept endpoint might result in an immediate merge?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I update the README to clarify that setting these parameters via the Accept endpoint might result in an immediate merge?

Yes, this is a bit confusing to me.

@pkg-pr-new

pkg-pr-new Bot commented Apr 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/changesets-gitlab@235

commit: 1b2e758

@JounQin JounQin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new optional inputs to control GitLab merge request auto-merge and squash behavior when creating/updating the versioning MR.

Changes:

  • Introduces getOptionalBooleanInput for optional boolean inputs (supports "true"/"false" and "1"/"0").
  • Extends MR creation/update flow to optionally set squash, and attempts to set auto-merge / squash commit message via the GitLab “accept” API.
  • Documents the new inputs and adds a changeset entry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/utils.ts Adds optional boolean input parsing helper and repositions truthy/falsy constants.
src/main.ts Wires new optional inputs into runVersion options.
src/run.ts Adds MR options (mergeWhenPipelineSucceeds, squash, squashCommitMessage) and calls MergeRequests.accept with derived options.
README.md Documents new INPUT_* variables for auto-merge and squash.
.changeset/gold-rice-cry.md Declares a minor release for the new feature inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/run.ts
Comment thread src/run.ts
Comment thread src/utils.ts
@kriakiku kriakiku closed this by deleting the head repository Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants