Reputation: 613
my GitLab is installed in one of the server. multiple Developers develop the source code in their branch and push the sources from thier local machines to GitLab. later on developers will login to GitLab account and create a merge request to the default branch.
Now how can i achieve to create an automated merge request to the default branch, when developers push their code from their local machine to GitLab.
Upvotes: 7
Views: 18594
Reputation: 5299
You can use push options to automatically create a merge-request in GitLab, like so:
$ git push -o merge_request.create ...
I managed to further automate this by adding an alias to my ~/.gitconfig
which states:
mr = push -o merge_request.create -o merge_request.remove_source_branch --set-upstream origin HEAD
Then, all I have to do is switch to the branch I want to create a new merge request from and run:
# notice that I don't even need to mention the branch name
$ git mr
The current branch will be pushed, it will be followed locally, a merge request based on that branch will be created, and the option to "Remove source branch" after merge checked on GitLab. There are further options you can explore to configure this as you prefer.
Upvotes: 9
Reputation: 6659
Unfortunately, there is no feature on GitLab to auto-create merge requests. You have to create them yourself using a bash or python script, for example. I usually just call a create_merge_request
job in a setup
stage that runs at the start of each pipeline. The steps go something like this:
As @mnestorov mentioned, there is an open-source version available here that executes those steps in a bash script. I think the only variable you need to create in your GitLab Variables section is GITLAB_PRIVATE_TOKEN
and enter your Personal Access Token.
Alternatively, you can write a Python script using the GitLab API, but you may have to write that yourself. You can find some information at How to create a merge request at the end of a successful pipeline in Gitlab?.
Upvotes: 5