diff options
author | Jeff Zambory <jeff.zambory@mongodb.com> | 2021-07-13 15:55:44 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-07-14 17:32:48 +0000 |
commit | ab08cdc4f20317a42a91be150d89c684d5dd4cf5 (patch) | |
tree | 4f118bfb19f2083b7f925874fde30e9f704ec189 /buildscripts/validate_commit_message.py | |
parent | 987dfecbced2a5f8f84e0197c68649bb1c20e8c4 (diff) | |
download | mongo-ab08cdc4f20317a42a91be150d89c684d5dd4cf5.tar.gz |
SERVER-55279: Commit queue message validation got tricked by merging multiple commits
Diffstat (limited to 'buildscripts/validate_commit_message.py')
-rwxr-xr-x | buildscripts/validate_commit_message.py | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/buildscripts/validate_commit_message.py b/buildscripts/validate_commit_message.py index 51ac1e26b15..0fcb0fbe536 100755 --- a/buildscripts/validate_commit_message.py +++ b/buildscripts/validate_commit_message.py @@ -28,12 +28,12 @@ # """Validate that the commit message is ok.""" import argparse -import os import re -import subprocess import sys import logging +from evergreen import RetryingEvergreenApi +EVG_CONFIG_FILE = "./.evergreen.yml" LOGGER = logging.getLogger(__name__) COMMON_PUBLIC_PATTERN = r''' @@ -121,29 +121,28 @@ def main(argv=None): usage="Validate the commit message. " "It validates the latest message when no arguments are provided.") parser.add_argument( - "message", - metavar="commit message", - nargs="*", - help="The commit message to validate", + "version_id", + metavar="version id", + help="The id of the version to validate", ) args = parser.parse_args(argv) - - if not args.message: - print('Validating last git commit message') - result = subprocess.check_output(GIT_SHOW_COMMAND) - message = result.decode('utf-8') - else: - message = " ".join(args.message) - - if any(valid_pattern.match(message) for valid_pattern in VALID_PATTERNS): - return STATUS_OK - else: - if any(private_pattern.match(message) for private_pattern in PRIVATE_PATTERNS): - error_type = "Found a reference to a private project" - else: - error_type = "Found a commit without a ticket" - LOGGER.error(f"{error_type}\n{message}") # pylint: disable=logging-fstring-interpolation - return STATUS_ERROR + evg_api = RetryingEvergreenApi.get_api(config_file=EVG_CONFIG_FILE) + + code_changes = evg_api.patch_by_id(args.version_id).module_code_changes + + for change in code_changes: + for message in change.commit_messages: + if any(valid_pattern.match(message) for valid_pattern in VALID_PATTERNS): + continue + elif any(private_pattern.match(message) for private_pattern in PRIVATE_PATTERNS): + error_type = "Found a reference to a private project" + else: + error_type = "Found a commit without a ticket" + if error_type: + LOGGER.error(f"{error_type}\n{message}") # pylint: disable=logging-fstring-interpolation + return STATUS_ERROR + + return STATUS_OK if __name__ == "__main__": |