From c753d8f356c6b292239c76acc12f0f1659d15f02 Mon Sep 17 00:00:00 2001
From: Christopher Bohn <bohn@unl.edu>
Date: Tue, 28 Apr 2020 13:25:24 -0500
Subject: [PATCH] Added option to check to explain message formatting problems

---
 api/gitlab_classes.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/api/gitlab_classes.py b/api/gitlab_classes.py
index d41c96a..a797d77 100644
--- a/api/gitlab_classes.py
+++ b/api/gitlab_classes.py
@@ -254,6 +254,30 @@ class GitlabCommit:
         return self._number_of_lines_too_long(lines, subject_line_length, message_line_length) == 0 \
             and self._has_blank_line_after_subject(lines)
 
+    def detail_formatting_problems(self, subject_line_length=72, message_line_length=72) -> str:
+        lines: List[str] = self.get_message().rstrip('\n').split('\n')
+        commit_id: str = f'Commit {self.gitlab_commit.short_id}'
+        if self.is_well_formatted():
+            return f'{commit_id} is well-formatted'
+        else:
+            if self._has_blank_line_after_subject(lines):
+                blank_line_comment = ''
+            else:
+                blank_line_comment = 'is missing a blank line after the subject'
+            overlong_lines = self._number_of_lines_too_long(lines,subject_line_length,message_line_length)
+            if overlong_lines == 0:
+                overlong_line_comment = ''
+            elif overlong_lines == 1:
+                overlong_line_comment = 'has 1 line too long'
+            else:
+                overlong_line_comment = f'has {overlong_lines} lines too long'
+            if blank_line_comment == '' or overlong_line_comment == '':
+                conjunction = ''
+            else:
+                conjunction = ' and '
+            return f'{commit_id} {blank_line_comment}{conjunction}{overlong_line_comment}.'
+
+
     # git_commit fields:
     # comments
     # discussions
-- 
GitLab