SERVER-45949 Update validate commit message client to work with new patch description standard

This commit is contained in:
Jim OLeary
2020-04-29 19:00:37 +01:00
committed by Evergreen Agent
parent b89a546076
commit 09b9e93168
2 changed files with 109 additions and 27 deletions

View File

@@ -33,12 +33,26 @@ import re
import subprocess
import sys
VALID_PATTERNS = [
re.compile(r"^Fix lint$"), # Allow "Fix lint" as the sole commit summary
re.compile(r'^(Revert ["\']?)?(EVG|SERVER|WT)-[0-9]+'), # These are public tickets
re.compile(r'^Import (wiredtiger|tools):'), # These are public tickets
]
PRIVATE_PATTERNS = [re.compile(r"^[A-Z]+-[0-9]+")]
COMMON_PUBLIC_PATTERN = r'''
((?P<revert>Revert)\s+[\"\']?)? # Revert (optional)
((?P<ticket>(?:EVG|SERVER|WT)-[0-9]+)[\"\']?\s*) # ticket identifier
(?P<body>(?:(?!\(cherry\spicked\sfrom).)*)? # To also capture the body
(?P<backport>\(cherry\spicked\sfrom.*)? # back port (optional)
'''
"""Common Public pattern format."""
COMMON_LINT_PATTERN = r'(?P<lint>Fix\slint)'
"""Common Lint pattern format."""
COMMON_IMPORT_PATTERN = r'(?P<imported>Import\s(wiredtiger|tools):\s.*)'
"""Common Import pattern format."""
COMMON_PRIVATE_PATTERN = r'''
((?P<revert>Revert)\s+[\"\']?)? # Revert (optional)
((?P<ticket>[A-Z]+-[0-9]+)[\"\']?\s*) # ticket identifier
(?P<body>(?:(?!('\s(into\s'(([^/]+))/(([^:]+)):(([^']+))'))).)*)? # To also capture the body
'''
"""Common Private pattern format."""
STATUS_OK = 0
STATUS_ERROR = 1
@@ -46,6 +60,58 @@ STATUS_ERROR = 1
GIT_SHOW_COMMAND = ["git", "show", "-1", "-s", "--format=%s"]
def new_patch_description(pattern: str) -> str:
"""
Wrap the pattern to conform to the new commit queue patch description format.
Add the commit queue prefix and suffix to the pattern. The format looks like:
Commit Queue Merge: '<commit message>' into '<owner>/<repo>:<branch>'
:param pattern: The pattern to wrap.
:return: A pattern to match the new format for the patch description.
"""
return (r"""^((?P<commitqueue>Commit\sQueue\sMerge:)\s')"""
f'{pattern}'
# r"""('\s(?P<into>into\s'((?P<owner>[^/]+))/((?P<repo>[^:]+)):((?P<branch>[^']+))'))"""
)
def old_patch_description(pattern: str) -> str:
"""
Wrap the pattern to conform to the new commit queue patch description format.
Just add a start anchor. The format looks like:
<commit message>
:param pattern: The pattern to wrap.
:return: A pattern to match the old format for the patch description.
"""
return r'^' f'{pattern}'
# NOTE: re.VERBOSE is for visibility / debugging. As such significant white space must be
# escaped (e.g ' ' to \s).
VALID_PATTERNS = [
re.compile(new_patch_description(COMMON_PUBLIC_PATTERN), re.MULTILINE | re.DOTALL | re.VERBOSE),
re.compile(old_patch_description(COMMON_PUBLIC_PATTERN), re.MULTILINE | re.DOTALL | re.VERBOSE),
re.compile(new_patch_description(COMMON_LINT_PATTERN), re.MULTILINE | re.DOTALL | re.VERBOSE),
re.compile(old_patch_description(COMMON_LINT_PATTERN), re.MULTILINE | re.DOTALL | re.VERBOSE),
re.compile(new_patch_description(COMMON_IMPORT_PATTERN), re.MULTILINE | re.DOTALL | re.VERBOSE),
re.compile(old_patch_description(COMMON_IMPORT_PATTERN), re.MULTILINE | re.DOTALL | re.VERBOSE),
]
"""valid public patterns."""
PRIVATE_PATTERNS = [
re.compile(
new_patch_description(COMMON_PRIVATE_PATTERN), re.MULTILINE | re.DOTALL | re.VERBOSE),
re.compile(
old_patch_description(COMMON_PRIVATE_PATTERN), re.MULTILINE | re.DOTALL | re.VERBOSE),
]
"""private patterns."""
def main(argv=None):
"""Execute Main function to validate commit messages."""
parser = argparse.ArgumentParser(