Skip to content

Commit bfa96e8

Browse files
smcclure15MongoDB Bot
authored andcommitted
SERVER-92729 Ignore whitespace for commit message validation comparisons (#25191)
GitOrigin-RevId: 4b0e45d
1 parent aa11c7f commit bfa96e8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

buildscripts/tests/test_validate_commit_message.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def test_invalid(self):
5959
binsha=b"deadbeefdeadbeefdead",
6060
message="SERVER-123 asdf\nAnything in this description will be included in the commit message. Replace or delete this text before merging. Add links to testing in the comments of the PR.",
6161
), # Contains some banned strings
62+
Commit(
63+
repo=fake_repo,
64+
binsha=b"deadbeefdeadbeefdead",
65+
message="SERVER-123 asdf\nAnything\n\n in this description will be included in the commit message.\nReplace or delete this text before merging. Add links to testing in the\ncomments of the PR.",
66+
), # Contains some banned strings with extra newlines
6267
]
6368

6469
self.assertTrue(all(is_valid_commit(message) == False for message in messages))

buildscripts/validate_commit_message.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ def is_valid_commit(commit: Commit) -> bool:
7070
)
7171
return False
7272

73+
# Remove all whitespace from comparisons. GitHub line-wraps commit messages, which adds
74+
# newline characters that otherwise would not match verbatim such banned strings.
75+
stripped_message = "".join(commit.message.split())
7376
for banned_string in BANNED_STRINGS:
74-
if banned_string in commit.message:
77+
if "".join(banned_string.split()) in stripped_message:
7578
LOGGER.error(
76-
"Commit contains banned string",
79+
"Commit contains banned string (ignoring whitespace)",
7780
banned_string=banned_string,
7881
commit_hexsha=commit.hexsha,
7982
commit_message=commit.message,

0 commit comments

Comments
 (0)