Automate GitLab Merge Requests with n8n HTTP Nodes

This workflow automates managing GitLab merge requests, saving you hours of manual tracking and updates by automatically checking, creating, commenting, closing, waiting, and merging requests via GitLab APIs using n8n’s HTTP Request nodes.
httpRequest
if
splitInBatches
+3
Workflow Identifier: 1553
NODES in Use: HTTP Request, If, Split In Batches, Wait, Set, Schedule Trigger
Automate GitLab merge requests with n8n and HTTP nodes

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What This Workflow Does

This workflow automates managing GitLab merge requests. It looks for open merge requests on specific source branches to stop duplicates. It makes new merge requests when none found. It adds notes to new merge requests. It waits some seconds for approval and pipeline to finish. It merges requests only after pipeline passes, and can delete the source branch. It can also close old merge requests in batches.

This way, users save time and avoid mistakes. Merges happen safely after CI is complete.


Who Should Use This Workflow

This workflow is for people who use GitLab often with many branches. It fits developers or DevOps working with multiple merge requests. It helps those who want less manual checking and faster merges. It works for anyone needing reliable automation for merge requests and CI pipelines.


Tools and Services Used

  • GitLab API: To read and modify merge requests.
  • n8n automation platform: To build and run the workflow.
  • HTTP Request nodes: To connect with GitLab API endpoints.
  • Schedule Trigger node: To run the workflow regularly.
  • Wait node: To pause before merge actions.
  • Split In Batches node: To close multiple merge requests efficiently.

self-host n8n can be used if preferring own server hosting.


Beginner Step-by-Step: How to Use This Workflow in n8n

Import Workflow

  1. Click the Download button on this page to get the workflow file.
  2. Open n8n editor and choose Import from File.
  3. Select the downloaded workflow file to load it.

Configure Workflow

  1. Add your GitLab API Key in the credentials for HTTP Request nodes.
  2. Change the <projectid> placeholders to your real GitLab project ID.
  3. Update source branch, target branch, merge title, and comments if you want customized inputs.

Test and Activate

  1. Run the workflow manually to check it works well.
  2. Fix any errors by checking the tokens and dynamic fields.
  3. When ready, activate the workflow to run on schedule.

Inputs, Processing Steps, and Output

Inputs

  • GitLab project ID.
  • Source and target branch names.
  • Merge request title and optional comments.
  • GitLab personal access API Key.

Processing Steps

  • Schedule trigger starts workflow on chosen interval.
  • Check if open merge requests exist for given source branch using API.
  • If none found, create new merge request with given title.
  • Add comment notes to the new merge request.
  • Wait 30 seconds for manual approval and CI pipeline finish.
  • Set options for when to merge and if branch is removed.
  • Send API request to merge MR when pipeline succeeds.
  • Split batches to loop over older merge requests and close them.

Output

  • New or updated merge requests with comments.
  • Merged merge requests after successful pipeline.
  • Older unneeded merge requests closed.

Edge Cases and Failures

  • Errors if API Key is missing or wrong.
  • Wrong project ID or branch names cause no merge requests found.
  • Merge does not happen if pipeline fails or flags are wrongly set.
  • Watch for API rate limits when running often.

Debug by testing API calls separately.


Customization Ideas

  • Switch merge_when_pipeline_succeeds flag to true to merge exactly post pipeline.
  • Change should_remove_source_branch to false to keep branches after merging.
  • Add dynamic content in merge comments, like author name or timestamps.
  • Increase wait time after comment to match longer pipeline durations.

Summary of Benefits and Results

✓ Saves time by automating merge request checks and creation.

✓ Avoids duplicate merge requests.

✓ Adds helpful comments automatically.

✓ Ensures merges only happen after pipeline success.

✓ Closes old merge requests in batches for cleaner project.


Automate GitLab merge requests with n8n and HTTP nodes

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

A 401 Unauthorized error happens when the GitLab API Key is missing, incorrect, or lacks proper API scopes.
If the project ID or source branch name sent in API calls is wrong or misspelled, the workflow shows no merge requests.
Merge requests won’t merge if the merge flags are set wrong, the pipeline is not successful, or the API request uses wrong data.
Use n8n’s credential manager to store API Keys securely instead of placing keys directly in HTTP Request nodes.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.