Skip to content
Snippets Groups Projects
Commit 394d410d authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Added option to check for proper commit message formatting

parent fb41f6e9
No related branches found
No related tags found
No related merge requests found
from datetime import datetime
from functools import reduce
from typing import ClassVar, Dict, Iterable, List, Optional, Set, Union
from gitlab import Gitlab, MAINTAINER_ACCESS
......@@ -229,6 +230,30 @@ class GitlabCommit:
deletions += diff['-']
return max(insertions, deletions)
@staticmethod
def _number_of_lines_too_long(lines, subject_line_length, message_line_length):
# noinspection PyUnusedLocal
lines_too_long: int
if len(lines) == 1:
lines_too_long = 0 if len(lines[0]) <= message_line_length else 1
else:
lines_too_long = 0 if len(lines[0]) <= subject_line_length else 1
lines_too_long += reduce((lambda x, y: x + y),
list(map(lambda line: 0 if len(line) <= message_line_length else 1, lines[1:])))
return lines_too_long
@staticmethod
def _has_blank_line_after_subject(lines):
if len(lines) == 1:
return True
else:
return lines[1] == ''
def is_well_formatted(self, subject_line_length=72, message_line_length=72) -> bool:
lines: List[str] = self.get_message().rstrip('\n').split('\n')
return self._number_of_lines_too_long(lines, subject_line_length, message_line_length) == 0 \
and self._has_blank_line_after_subject(lines)
# git_commit fields:
# comments
# discussions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment