ci: Check for issue/MR URLs in commit messages

Commit messages should include the full URL to an issue or merge
request to keep associated information easily available in future
log digging.

Jonas came up with a script to enforce that policy for mutter and
gnome-shell. It's an excellent idea, so adopt it here as well.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/52
This commit is contained in:
Florian Müllner
2019-02-15 23:59:36 +01:00
parent 434185ba03
commit cbd981351e
2 changed files with 48 additions and 0 deletions

View File

@@ -1,15 +1,31 @@
stages:
- commit_check
- source_check
- build
variables:
LINT_LOG: "eslint-report.txt"
.only_default: &only_default
only:
- branches
- tags
- merge_requests
check_commit_log:
image: registry.gitlab.gnome.org/gnome/gjs:fedora.static-analysis
stage: commit_check
script:
- ./.gitlab-ci/check-commit-log.sh
only:
- merge_requests
eslint:
image: registry.gitlab.gnome.org/gnome/gjs:fedora.static-analysis
stage: source_check
script:
- sh lint/generate-report.sh -o $LINT_LOG || { cat $LINT_LOG; false; }
<<: *only_default
artifacts:
paths:
- ${LINT_LOG}
@@ -23,3 +39,4 @@ build-shell-extensions:
script:
- meson _build .
- ninja -C _build test install
<<: *only_default

31
.gitlab-ci/check-commit-log.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/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)
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]\+\)"
return $?
}
for commit in $commits; do
if ! commit_message_has_url $commit; then
echo "Missing merge request or issue URL on commit $(echo $commit | cut -c -8)"
exit 1
fi
done