A simple tool for automatically creating merge requests in GitLab
Project description
GitLab Auto MR
This script is meant to be used in GitLab CI to automatically open Merge Requests for feature branches, if there is none yet. This project provides a docker image you can use for ease of use, but also a Python library.
It is based on the script and idea of Riccardo Padovani, which he introduced with his blog post How to automatically create new MR on Gitlab with Gitlab CI.
This is a simple Python script that allows you create MR in GitLab automatically. It is intended to be used in CI/CD as a Docker image. However you can use it as a separate Python library if you would like. An example CI using this can be found here.
It is based on the script and idea of Riccardo Padovani, which he introduced with his blog post How to automatically create new MR on Gitlab with Gitlab CI. Thanks for providing this.
This package was intended to be used by GitLab CI hence using environments provided by the GitLab CI. You can however use it as a CLI tool if you would like.
Usage
First you need to create a personal access token, more information here. With the scope api, so it can create the MR using your API.
pip install gitlab-auto-mr
Usage: gitlab_auto_mr [OPTIONS]
Options:
--private-token TEXT Private GITLAB token, used to authenticate when
calling the MR API. [required]
--source-branch TEXT The source branch to merge into. [required]
--project-id INTEGER The project ID on GitLab to create the MR for.
[required]
--project-url TEXT The project URL on GitLab to create the MR for.
[required]
--user-id INTEGER The GitLab user ID to assign the created MR to.
[required]
--target-branch TEXT The target branch to merge onto.
--commit-prefix TEXT Prefix for the MR title i.e. WIP.
--remove-branch BOOLEAN Set to True if you want the source branch to be
removed after MR.
--squash-commits BOOLEAN Set to True if you want commits to be squashed.
--description TEXT Description in the MR.
--help Show this message and exit.
gitlab_auto_mr --private-token $(private_token) --source-branch feature/test --project-id 5
--project-url https://gitlab.com/hmajid2301/stegappasaurus --user-id 5
GitLab CI
GITLAB_PRIVATE_TOKEN Set a secret variable in your GitLab project with your private token. Name it GITLAB_PRIVATE_TOKEN (CI/CD > Environment Variables). This is necessary to raise the Merge Request on your behalf. More information click here. An example CI using this can be found here.
Add the following to your .gitlab-ci.yml file:
stages:
- open
open_merge_request:
image: registry.gitlab.com/hmajid2301/gitlab-auto-merge-request
before_script: [] # We do not need any setup work, let's remove the global one (if any)
variables:
GIT_STRATEGY: none # We do not need a clone of the GIT repository to create a Merge Request
stage: open
only:
- /^feature\/*/ # We have a very strict naming convention
script:
- gitlab_auto_mr
You can set extra variables like so.
variables:
GIT_STRATEGY: none # We do not need a clone of the GIT repository to create a Merge Request
TARGET_BRANCH: master # Target branch for MR
COMMIT PREFIX: Prefix for the MR i.e. WIP
REMOVE_BRANCH_AFTER_MERGE: Will delete branch after merge
SQUASH: Will squash commits after merge
AUTO_MERGE: Will auto merge request after being reviewed and CI passes
TARGET_BRANCH: The target branch for the MR
DESCRIPTION: Description of the Mr
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for gitlab-auto-mr-0.1.1.post4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39afeadc93c0d5d6c22f93889d9da5c960fb4ff05ffc766e4596a34ae86767ed |
|
MD5 | 68172e44adb5dc099915ad9f6d48137f |
|
BLAKE2b-256 | 1064a57ed40596bd0e4bdeccd1c17be424a443f8ee643dc27c085ed51f379f10 |