thunderbird
thunderbird

Reputation: 121

Lock branch but allow gitlab merge request

We are using GitLab version 8.5.0. I am writing a custom server side update hook to lock specific branches. It works great, however, I would like to allow GitLab merge requests to be processed. All GitLab merge requests will usually have "See Merge request" comment in the commit description. Hence, I thought to allow only those commits, which contains commit message "See Merge request". However, it doesnt work the way I thought.

Any other possible ways to allow only gitlab merge requests?

#!/usr/bin/env bash

GIT_COMMIT_MSG=`git log -1 HEAD --pretty=format:%s`

if [[ "$1" == refs/heads/master ]]; then
if [[ "$GIT_COMMIT_MSG" =~ *"See Merge request"* ]]; then
    echo "This is GitLab Merge Request"
else
    echo $GIT_COMMIT_MSG
    echo "ERROR:  you are not allowed to update master" >&2
    exit 1
fi

fi

Upvotes: 3

Views: 3891

Answers (1)

VonC
VonC

Reputation: 1324347

I understand you are using GitLab 8.5, but if possible, consider upgrading to 8.11 where this has been natively (and more securely) implemented.
See "Using the Allowed to merge and Allowed to push settings"

You could set "Allowed to push" to "No one", and "Allowed to merge" to "Developers + Masters", to require everyone to submit a merge request for changes going into the protected branch.

enter image description here

Then all you need is to protect some branches, and they will be modified only through merge request.

Upvotes: 9

Related Questions