diff --git a/api/gitlab_classes.py b/api/gitlab_classes.py index d41c96a3e09e0b18fb7d8bf71f793ee6e3daf1dc..a797d77926ba899ea1e6a5c457b5a7638d248df5 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