[gnome-shell] gitlab-ci.yml: Add check for issue or MR URL



commit 27d0d9f2b39d2be5cf518e7475893ba5a6292e7a
Author: Jonas Ådahl <jadahl gmail com>
Date:   Wed Feb 13 20:34:07 2019 +0100

    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.
    
    Taken from https://gitlab.gnome.org/GNOME/mutter/merge_requests/440.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/410

 .gitlab-ci.yml                 | 14 ++++++++++++++
 .gitlab-ci/check-commit-log.sh | 19 +++++++++++++++++++
 2 files changed, 33 insertions(+)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 07c9144af..46d86f85c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,9 +1,20 @@
 stages:
+ - review
  - source_check
 
 variables:
     JS_LOG: "js-report.txt"
 
+check_commit_log:
+    image: registry.fedoraproject.org/fedora:latest
+    stage: review
+    before_script:
+        - dnf install -y git
+    script:
+        - ./.gitlab-ci/check-commit-log.sh
+    only:
+        - merge_requests
+
 js_check:
     image: registry.fedoraproject.org/fedora:latest
     stage: source_check
@@ -16,3 +27,6 @@ js_check:
         paths:
             - ${JS_LOG}
         when: on_failure
+    only:
+        - merge_requests
+        - /^.*$/
diff --git a/.gitlab-ci/check-commit-log.sh b/.gitlab-ci/check-commit-log.sh
new file mode 100755
index 000000000..87f1978ce
--- /dev/null
+++ b/.gitlab-ci/check-commit-log.sh
@@ -0,0 +1,19 @@
+#!/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)
+
+test -z "$commits" && { echo Commit range empty; exit 1; }
+
+for commit in $commits; do
+  git show -s --format='format:%b' $commit | grep -qe 
"\($CI_MERGE_REQUEST_PROJECT_URL/\(issues\|merge_requests\)/[0-9]\+\|https://bugzilla.gnome.org/show_bug.cgi?id=[0-9]\+\)"
 ||
+    { echo "Missing merge request or issue URL on commit $(echo $commit | cut -c -8)"; exit 1; }
+done


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]