зеркало из https://github.com/AvaloniaUI/angle.git
Change how commit messages are taken + multiple commits handling
Multiple commits are separated and format-checked separately. Commit message is now taken solely from input_api. Tags paragraph now covers the very last paragraph until the first line that doesn't have a ":" Bug: angleproject:4662 Change-Id: I84fe3fd1ffc30f6892a5c9dbe545acf24b0fc595 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2241617 Commit-Queue: Manh Nguyen <nguyenmh@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
This commit is contained in:
Родитель
12ed3b6e4f
Коммит
31bbe1ba08
187
PRESUBMIT.py
187
PRESUBMIT.py
|
@ -41,97 +41,124 @@ def _CheckCommitMessageFormatting(input_api, output_api):
|
|||
while len(lines) > 0 and _IsLineBlank(lines[0]):
|
||||
lines.pop(0)
|
||||
|
||||
def _IsTagLine(line):
|
||||
return ":" in line
|
||||
|
||||
whitelist_strings = ['Revert "', 'Roll ', 'Reland ']
|
||||
summary_linelength_warning_lower_limit = 65
|
||||
summary_linelength_warning_upper_limit = 70
|
||||
description_linelength_limit = 72
|
||||
|
||||
if input_api.change.issue:
|
||||
git_output = input_api.gerrit.GetChangeDescription(input_api.change.issue)
|
||||
else:
|
||||
git_output = subprocess.check_output(["git", "log", "-n", "1", "--pretty=format:%B"])
|
||||
commit_msg_lines = git_output.splitlines()
|
||||
commit_msg_line_numbers = {}
|
||||
for i in range(len(commit_msg_lines)):
|
||||
commit_msg_line_numbers[commit_msg_lines[i]] = i + 1
|
||||
_PopBlankLines(commit_msg_lines, True)
|
||||
_PopBlankLines(commit_msg_lines, False)
|
||||
if len(commit_msg_lines) > 0:
|
||||
for whitelist_string in whitelist_strings:
|
||||
if commit_msg_lines[0].startswith(whitelist_string):
|
||||
return []
|
||||
git_output = input_api.change.DescriptionText()
|
||||
|
||||
multiple_commits = re.split(r"Change-Id: [a-zA-Z0-9]*\n", git_output)
|
||||
errors = []
|
||||
if git_output.find("\t") != -1:
|
||||
errors.append(output_api.PresubmitError("Tabs are not allowed in commit message."))
|
||||
|
||||
# get rid of the last paragraph, which we assume to always be the tags
|
||||
last_paragraph_line_count = 0
|
||||
while len(commit_msg_lines) > 0 and not _IsLineBlank(commit_msg_lines[-1]):
|
||||
last_paragraph_line_count += 1
|
||||
commit_msg_lines.pop()
|
||||
if last_paragraph_line_count == 0:
|
||||
errors.append(
|
||||
output_api.PresubmitError(
|
||||
"Please ensure that there are tags (e.g., Bug:, Test:) in your description."))
|
||||
if len(commit_msg_lines) > 0:
|
||||
# pop the blank line between tag paragraph and description body
|
||||
commit_msg_lines.pop()
|
||||
if len(commit_msg_lines) > 0 and _IsLineBlank(commit_msg_lines[-1]):
|
||||
errors.append(
|
||||
output_api.PresubmitError('Please ensure that there exists only 1 blank line '
|
||||
'between tags and description body.'))
|
||||
# pop all the remaining blank lines between tag and description body
|
||||
for k in range(len(multiple_commits)):
|
||||
commit = multiple_commits[k]
|
||||
commit_number = len(multiple_commits) - k
|
||||
commit_tag = "Commit " + str(commit_number) + ":"
|
||||
commit_msg_lines = commit.splitlines()
|
||||
commit_msg_line_numbers = {}
|
||||
for i in range(len(commit_msg_lines)):
|
||||
commit_msg_line_numbers[commit_msg_lines[i]] = i + 1
|
||||
_PopBlankLines(commit_msg_lines, True)
|
||||
if len(commit_msg_lines) == 0:
|
||||
errors.append(
|
||||
output_api.PresubmitError('Please ensure that your description summary'
|
||||
' and description body are not blank.'))
|
||||
return errors
|
||||
|
||||
if summary_linelength_warning_lower_limit <= len(commit_msg_lines[0]) \
|
||||
<= summary_linelength_warning_upper_limit:
|
||||
errors.append(
|
||||
output_api.PresubmitPromptWarning(
|
||||
"Your description summary should be on one line of " +
|
||||
str(summary_linelength_warning_lower_limit - 1) + " or less characters."))
|
||||
elif len(commit_msg_lines[0]) > summary_linelength_warning_upper_limit:
|
||||
errors.append(
|
||||
output_api.PresubmitError(
|
||||
"Please ensure that your description summary is on one line of " +
|
||||
str(summary_linelength_warning_lower_limit - 1) + " or less characters."))
|
||||
commit_msg_lines.pop(0) # get rid of description summary
|
||||
if len(commit_msg_lines) == 0:
|
||||
return errors
|
||||
if not _IsLineBlank(commit_msg_lines[0]):
|
||||
errors.append(
|
||||
output_api.PresubmitError('Please ensure the summary is only 1 line and '
|
||||
' there is 1 blank line between the summary '
|
||||
'and description body.'))
|
||||
else:
|
||||
commit_msg_lines.pop(0) # pop first blank line
|
||||
if len(commit_msg_lines) == 0:
|
||||
return errors
|
||||
if _IsLineBlank(commit_msg_lines[0]):
|
||||
errors.append(
|
||||
output_api.PresubmitError('Please ensure that there exists only 1 blank line '
|
||||
'between description summary and description body.'))
|
||||
# pop all the remaining blank lines between description summary and description body
|
||||
_PopBlankLines(commit_msg_lines)
|
||||
|
||||
# loop through description body
|
||||
while len(commit_msg_lines) > 0:
|
||||
line = commit_msg_lines.pop(0)
|
||||
# lines starting with 4 spaces or lines without space(urls) are exempt from length check
|
||||
if line.startswith(" ") or " " not in line:
|
||||
_PopBlankLines(commit_msg_lines, False)
|
||||
whitelisted = False
|
||||
if len(commit_msg_lines) > 0:
|
||||
for whitelist_string in whitelist_strings:
|
||||
if commit_msg_lines[0].startswith(whitelist_string):
|
||||
whitelisted = True
|
||||
break
|
||||
if whitelisted:
|
||||
continue
|
||||
if len(line) > description_linelength_limit:
|
||||
|
||||
if commit.find("\t") != -1:
|
||||
errors.append(
|
||||
output_api.PresubmitError(commit_tag + "Tabs are not allowed in commit message."))
|
||||
|
||||
# the tags paragraph is at the end of the message
|
||||
# the break between the tags paragraph is the first line without ":"
|
||||
# this is sufficient because if a line is blank, it will not have ":"
|
||||
last_paragraph_line_count = 0
|
||||
while len(commit_msg_lines) > 0 and _IsTagLine(commit_msg_lines[-1]):
|
||||
last_paragraph_line_count += 1
|
||||
commit_msg_lines.pop()
|
||||
if last_paragraph_line_count == 0:
|
||||
errors.append(
|
||||
output_api.PresubmitError(
|
||||
'Line ' + str(commit_msg_line_numbers[line]) + ' is too long.\n' + '"' + line +
|
||||
'"\n' + 'Please wrap it to ' + str(description_linelength_limit) +
|
||||
' characters. ' +
|
||||
"Lines without spaces or lines starting with 4 spaces are exempt."))
|
||||
return errors
|
||||
commit_tag +
|
||||
"Please ensure that there are tags (e.g., Bug:, Test:) in your description."))
|
||||
if len(commit_msg_lines) > 0:
|
||||
if not _IsLineBlank(commit_msg_lines[-1]):
|
||||
output_api.PresubmitError(commit_tag +
|
||||
"Please ensure that there exists 1 blank line " +
|
||||
"between tags and description body.")
|
||||
else:
|
||||
# pop the blank line between tag paragraph and description body
|
||||
commit_msg_lines.pop()
|
||||
if len(commit_msg_lines) > 0 and _IsLineBlank(commit_msg_lines[-1]):
|
||||
errors.append(
|
||||
output_api.PresubmitError(
|
||||
commit_tag + 'Please ensure that there exists only 1 blank line '
|
||||
'between tags and description body.'))
|
||||
# pop all the remaining blank lines between tag and description body
|
||||
_PopBlankLines(commit_msg_lines, True)
|
||||
if len(commit_msg_lines) == 0:
|
||||
errors.append(
|
||||
output_api.PresubmitError(commit_tag +
|
||||
'Please ensure that your description summary'
|
||||
' and description body are not blank.'))
|
||||
continue
|
||||
|
||||
if summary_linelength_warning_lower_limit <= len(commit_msg_lines[0]) \
|
||||
<= summary_linelength_warning_upper_limit:
|
||||
errors.append(
|
||||
output_api.PresubmitPromptWarning(
|
||||
commit_tag + "Your description summary should be on one line of " +
|
||||
str(summary_linelength_warning_lower_limit - 1) + " or less characters."))
|
||||
elif len(commit_msg_lines[0]) > summary_linelength_warning_upper_limit:
|
||||
errors.append(
|
||||
output_api.PresubmitError(
|
||||
commit_tag + "Please ensure that your description summary is on one line of " +
|
||||
str(summary_linelength_warning_lower_limit - 1) + " or less characters."))
|
||||
commit_msg_lines.pop(0) # get rid of description summary
|
||||
if len(commit_msg_lines) == 0:
|
||||
continue
|
||||
if not _IsLineBlank(commit_msg_lines[0]):
|
||||
errors.append(
|
||||
output_api.PresubmitError(commit_tag +
|
||||
'Please ensure the summary is only 1 line and '
|
||||
'there is 1 blank line between the summary '
|
||||
'and description body.'))
|
||||
else:
|
||||
commit_msg_lines.pop(0) # pop first blank line
|
||||
if len(commit_msg_lines) == 0:
|
||||
continue
|
||||
if _IsLineBlank(commit_msg_lines[0]):
|
||||
errors.append(
|
||||
output_api.PresubmitError(commit_tag +
|
||||
'Please ensure that there exists only 1 blank line '
|
||||
'between description summary and description body.'))
|
||||
# pop all the remaining blank lines between
|
||||
# description summary and description body
|
||||
_PopBlankLines(commit_msg_lines)
|
||||
|
||||
# loop through description body
|
||||
while len(commit_msg_lines) > 0:
|
||||
line = commit_msg_lines.pop(0)
|
||||
# lines starting with 4 spaces or lines without space(urls)
|
||||
# are exempt from length check
|
||||
if line.startswith(" ") or " " not in line:
|
||||
continue
|
||||
if len(line) > description_linelength_limit:
|
||||
errors.append(
|
||||
output_api.PresubmitError(
|
||||
commit_tag + 'Line ' + str(commit_msg_line_numbers[line]) +
|
||||
' is too long.\n' + '"' + line + '"\n' + 'Please wrap it to ' +
|
||||
str(description_linelength_limit) + ' characters. ' +
|
||||
"Lines without spaces or lines starting with 4 spaces are exempt."))
|
||||
break
|
||||
return errors
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче