summaryrefslogtreecommitdiff
path: root/.gitlab-ci
diff options
context:
space:
mode:
authorJonas Ådahl <jadahl@gmail.com>2019-02-05 18:19:43 +0100
committerJonas Ådahl <jadahl@gmail.com>2019-02-14 17:10:32 +0100
commitb70c0eb9a5db9479408ed5102b1bf346749aec1f (patch)
tree0c36d6c46b30d66ddc43444fd0e9b75c2d5349bc /.gitlab-ci
parentf3dd97e67b778e0a510b989a820bd3e0820449e6 (diff)
downloadmutter-b70c0eb9a5db9479408ed5102b1bf346749aec1f.tar.gz
gitlab-ci.yml: Add check for issue or MR URL
This adds a pipeline stage for merge requests that checks that the commit message contains an URL to either a issue or a merge request. This means that for merge requests without corresponding issues will always fail initially, as the merge request URL is not known until after it is created. This is still arguably better than accidentally merging merge requests without URLs. https://gitlab.gnome.org/GNOME/mutter/merge_requests/440
Diffstat (limited to '.gitlab-ci')
-rwxr-xr-x.gitlab-ci/check-commit-log.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/.gitlab-ci/check-commit-log.sh b/.gitlab-ci/check-commit-log.sh
new file mode 100755
index 000000000..cc3bcee60
--- /dev/null
+++ b/.gitlab-ci/check-commit-log.sh
@@ -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