Hey everybody,
I would like to use a link for a user to create a Branch and a Merge Request. So its basically the same functionality as the Create merge request
button on an Issue but from a different source.
I already found that I can send a user to a new Merge Request an fill it with data:
nsmeenk/my-project/-/merge_requests/new?merge_request%5Bsource_branch%5D=some_branch&merge_request%5Bmaster%5D=master&merge_request%5Btitle%5D=sometitle&merge_request%5Bdescription%5D=somedes
The only Problem I still have: This only works for already existing branches.
Is there a way to create the branch when calling the URL?
I don’t want to save an access token in my other app and call the Gitlab api before redirecting to create the branch.
Thanks!
Hi,
you’ll need to call a second URL first, with a bit of form reverse engineering, I extracted this from the docs:
https://gitlab.com/everyonecancontribute/general/-/branches/new?branch_name=test
This takes the default branch as a source by default.
A more robust way would be to call the REST API in the background, and create a “proxy form URL” for your users, hiding the unnecessary parameters.
Can be further abstracted by e.g. using python-gitlab or other language clients.
Cheers,
Michael
2 Likes
Thanks a lot!
We just had a chat and decided to try to use the REST API with oauth2. Seams to be the best way - maybe not the most easy one, but it will put the right names on the created MR and do stuff in the name of a user.
Thanks again for the fast response!
1 Like