GitLab Merge Request Automation: Auto-Create & Close Existing MRs
Automate your GitLab merge request lifecycle, reducing manual setup time by 100% and ensuring only fresh, active merge requests are awaiting review and merge.
Manual management of GitLab merge requests can be time-consuming, lead to stale MRs, and slow down development cycles. This workflow automatically checks for existing merge requests, closes outdated ones, creates fresh MRs with custom notes, and sets them up for merging, ensuring continuous integration.

Documentation
GitLab Merge Request Lifecycle Automation
Manual management of GitLab merge requests, including creating new ones, adding comments, and ensuring they're ready for merge, can be repetitive and error-prone. This n8n workflow fully automates this process, maintaining a clean and active merge request queue for your development branches.
Key Features
- Automatically checks for existing open merge requests for a specific source branch.
- Intelligently closes any outdated or existing merge requests to prevent duplication.
- Seamlessly creates new merge requests with configurable titles and target branches.
- Adds custom, descriptive notes to newly created merge requests for better context.
- Configures merge requests for pipeline success merging and automated source branch removal.
- Schedules regular checks to ensure merge requests are always up-to-date and ready.
How It Works
This workflow operates on a scheduled basis, typically checking your GitLab project at defined intervals. It first queries GitLab to see if an open merge request already exists for the specified source branch. If an open merge request is found, the workflow proceeds to close it, ensuring that only a single, up-to-date merge request will exist for that branch. If no open MR is found (or after closing an existing one), the workflow then creates a brand new merge request, specifying the source and target branches, along with a custom title. Immediately after creation, it adds predefined custom notes to the new merge request, providing essential information to reviewers. The workflow then introduces a short waiting period (e.g., 30 seconds) to allow for initial pipeline setup or manual approvals. Finally, it sets the merge request to remove the source branch upon a successful merge, streamlining your repository hygiene.