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

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

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

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.


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 Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free