5f7615d3fc
Instead of making sure there is a reference to a bug or merge request, make sure there isn't. The reason for this is that marge-bot will always append a merge request URL in the end of the commit message. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1491>
32 lines
836 B
Bash
Executable File
32 lines
836 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
if [ -z "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ]; then
|
|
echo Cannot review non-merge request
|
|
exit 1
|
|
fi
|
|
|
|
git fetch $CI_MERGE_REQUEST_PROJECT_URL.git $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
|
|
|
|
branch_point=$(git merge-base HEAD FETCH_HEAD)
|
|
|
|
commits=$(git log --format='format:%H' $branch_point..$CI_COMMIT_SHA)
|
|
|
|
if [ -z "$commits" ]; then
|
|
echo Commit range empty
|
|
exit 1
|
|
fi
|
|
|
|
function commit_message_has_mr_url() {
|
|
commit=$1
|
|
commit_message=$(git show -s --format='format:%b' $commit)
|
|
echo "$commit_message" | grep -qe "^$CI_MERGE_REQUEST_PROJECT_URL\/\(-\/\)\?merge_requests\/$CI_MERGE_REQUEST_IID$"
|
|
return $?
|
|
}
|
|
|
|
for commit in $commits; do
|
|
if commit_message_has_mr_url $commit; then
|
|
echo "Commit $(echo $commit | cut -c -8) message must not contain a link to its own merge request"
|
|
exit 1
|
|
fi
|
|
done
|