2019-02-05 17:19:43 +00:00
|
|
|
#!/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_url() {
|
|
|
|
commit=$1
|
|
|
|
commit_message=$(git show -s --format='format:%b' $commit)
|
2020-02-25 23:18:17 +00:00
|
|
|
echo "$commit_message" | grep -qe "\($CI_MERGE_REQUEST_PROJECT_URL/\(-/\)\?\(issues\|merge_requests\)/[0-9]\+\|https://bugzilla.gnome.org/show_bug.cgi?id=[0-9]\+\)"
|
2019-02-05 17:19:43 +00:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2019-04-01 11:10:10 +00:00
|
|
|
function commit_message_subject_is_compliant() {
|
|
|
|
commit=$1
|
|
|
|
commit_message_subject=$(git show -s --format='format:%s' $commit)
|
|
|
|
|
|
|
|
if echo "$commit_message_subject" | grep -qe "\(^meta-\|^Meta\)"; then
|
|
|
|
echo " - message subject should not be prefixed with 'meta-' or 'Meta'"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-04-02 08:47:06 +00:00
|
|
|
if echo "$commit_message_subject" | grep -qe "\.[ch]:"; then
|
|
|
|
echo " - message subject prefix should not include .c, .h, etc."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-04-01 11:10:10 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-10-21 11:19:16 +00:00
|
|
|
RET=0
|
2019-02-05 17:19:43 +00:00
|
|
|
for commit in $commits; do
|
2019-04-01 11:10:10 +00:00
|
|
|
commit_short=$(echo $commit | cut -c -8)
|
|
|
|
|
2019-02-05 17:19:43 +00:00
|
|
|
if ! commit_message_has_url $commit; then
|
2019-10-21 11:06:25 +00:00
|
|
|
echo "Commit $commit_short needs a merge request or issue URL"
|
2019-04-01 11:10:10 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
errors=$(commit_message_subject_is_compliant $commit)
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Commit message for $commit_short is not compliant:"
|
|
|
|
echo "$errors"
|
2019-10-21 11:19:16 +00:00
|
|
|
RET=1
|
2019-02-05 17:19:43 +00:00
|
|
|
fi
|
|
|
|
done
|
2019-10-21 11:19:16 +00:00
|
|
|
|
|
|
|
exit $RET
|