12 def fset(self, value):
16 return [
'feat',
'fix',
'perf',
'revert',
'docs',
'chore',
'style',
'refactor',
'test',
'merge']
18 return property(**locals())
25 def unpushed_commit_message():
28 if command_result.status != 0:
31 return command_result.out.split(
'\n')
34 def commit_in_path(old_path=None, new_path=None):
35 git_command =
'git log --first-parent --pretty=format:%h:%aE:%s' 37 if old_path
is not None and len(old_path) > 0:
38 git_command +=
' ' + old_path
40 if new_path
is not None and len(new_path) > 0:
41 git_command +=
'..' + new_path
45 if command_result.status != 0:
48 return command_result.out.split(
'\n')
52 def __check_commit_title(commit_hash, commit_title):
54 title_pattern = re.compile(
r'(?P<type>' +
'|'.join(CONST.TYPES) +
')\((?P<scope>\S+)\):(?P<subject>.*)')
55 title_match = title_pattern.match(commit_title)
58 title_have_not_matched = title_match
is None 60 if title_have_not_matched
is True:
66 +
"' does not follow Sheldon rules: '<" +
"|".join(CONST.TYPES) +
">(<scope>): <subject>'.")
68 return title_have_not_matched
72 def __check_commit_author(commit_hash, commit_author):
74 author_pattern = re.compile(
r'\.*anonymous\.*')
75 author_match = author_pattern.match(commit_author.lower())
78 author_have_matched = author_match
is not None 80 if author_have_matched
is True:
84 +
"' has anonymous author.")
86 return author_have_matched
89 def check_commit_messages(commit_messages):
92 for commit_message
in commit_messages:
94 split_message = commit_message.split(
':', 2)
96 if len(split_message) == 3:
98 commit_hash = split_message[0]
99 commit_author = split_message[1]
100 commit_title = split_message[2]
102 results.append(__check_commit_title(commit_hash, commit_title))
103 results.append(__check_commit_author(commit_hash, commit_author))
105 common.note(
'%d commit(s) checked, %d error(s) found.' % (len(commit_messages), results.count(
True)))
def execute_command(proc)