gitlab CI: make the commit check errors more verbose and useful
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 4 Dec 2019 23:01:02 +0000 (09:01 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 5 Dec 2019 00:40:40 +0000 (10:40 +1000)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
.gitlab-ci/check-commit.py

index e7e4e375ead3708ea9cd9847500d9cb963d9ce6c..5833b2010ea97d7a6fe04e8cad1d54dc7ba9fd24 100755 (executable)
@@ -1,4 +1,6 @@
 #!/usr/bin/env python3
+# vim: set expandtab shiftwidth=4:
+# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
 #
 # This script tests a few things against the commit messages, search for
 # `def test_` to see the actual tests run.
@@ -26,10 +28,22 @@ commits = list(repo.iter_commits(f'upstream/{branch}..{sha}'))
 
 
 def error(commit, message, long_message=''):
-    if long_message:
-        long_message = '\n\n\t' + long_message.replace('\n', '\n\t')
-    return f'on commit {str(commit)[:8]} "{commit.summary}": {message}{long_message}'
+    info = ('After correcting the above issue(s), force-push to the same branch.\n'
+            'This will re-trigger the CI.\n\n'
+            'A list of requirements for commit messages is available at\n'
+            'https://gitlab.freedesktop.org/libinput/libinput/blob/master/CODING_STYLE.md')
 
+    msg = (f'\n'
+           f'Commit message check failed: {message}\n\n'
+           f'  commit: {str(commit)}\n'
+           f'  author: {commit.author.name} <{commit.author.email}>\n'
+           f'\n'
+           f'  {commit.summary}\n'
+           f'\n'
+           f'\n'
+           f'{long_message}\n\n'
+           f'{info}\n\n')
+    return msg
 
 @pytest.mark.parametrize('commit', commits)
 class TestCommits:
@@ -44,7 +58,8 @@ class TestCommits:
         if not commit.message.startswith('Revert "'):
             assert 'Signed-off-by:' in commit.message, \
                 error(commit, 'missing Signed-off-by tag',
-                      'Please add the required "Signed-off-by: author information" line to the commit message')
+                      'Please add the required "Signed-off-by: author information" line\n'
+                      'to the commit message')
 
     def test_fixup(self, commit):
         assert not commit.message.startswith('fixup!'), \