In Github there are environment variables like GITHUB_VIA that expose the action that originated a git commit. In the example below, taken from here, this is used to protect default branches.
Is there something similar for Gitlab? I’m coding a pre-receive hook and I can’t find this documented anywhere on Gitlab’s doc.
#!/bin/bash
#
# This hook restricts changes on the default branch to those made with the GUI Pull Request Merge button, or the Pull Request Merge API.
#
DEFAULT_BRANCH=$(git symbolic-ref HEAD)
while read -r oldrev newrev refname; do
if [[ "${refname}" != "${DEFAULT_BRANCH:=refs/heads/master}" ]]; then
continue
else
if [[ "${GITHUB_VIA}" != 'pull request merge button' && \
"${GITHUB_VIA}" != 'pull request merge api' ]]; then
echo "Changes to the default branch must be made by Pull Request. Direct pushes, edits, or merges are not allowed."
exit 1
else
continue
fi
fi
done
I’m looking for environment variables I could use within the context of a pre-receive on Gitlab, such as these ones on GHE.