Skip to content

Commit bceedb3

Browse files
committed
github: automation: fixed rules for commit scope check
1 parent 7e450f8 commit bceedb3

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

.github/automation/commit-msg-check.py

+9-18
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,24 @@
2020

2121
import argparse
2222
import subprocess
23+
import re
2324

24-
# * Ensuring the scopes end in colon and same level scopes are comma delimited.
25+
# Ensure the scope ends in a colon and that same level scopes are
26+
# comma delimited.
27+
# Current implementation only checks the first level scope as ':' can be used
28+
# in the commit description (ex: TBB::tbb or bf16:bf16).
2529
# TODO: Limit scopes to an acceptable list of tags.
2630
def __scopeCheck(msg: str):
2731
status = "Message scope: "
2832

29-
firstLine = (msg.partition("\n")[0]).strip()
30-
31-
if not ":" in firstLine:
32-
print(f"{status} FAILED: Commit message does not include scope")
33+
if not re.match('^[a-z0-9]+(, [a-z0-9]+)*: ', msg):
34+
print(f"{status} FAILED: Commit message must follow the format <scope>:[ <scope>:] <short description>")
3335
return False
3436

35-
# The last element of the split is the title, which we don't care about.
36-
scopesArray = firstLine.split(":")[:-1]
37-
38-
for scopes in scopesArray:
39-
numWords = len(scopes.split())
40-
numCommas = scopes.count(",")
41-
42-
if numWords != numCommas + 1:
43-
print(f"{status} FAILED: Same-level scopes must be comma-separated. Bad token: '{scopes}'")
44-
return False
45-
4637
print(f"{status} OK")
4738
return True
4839

49-
# * Ensuring a character limit for the first line.
40+
# Ensuring a character limit for the first line.
5041
def __numCharacterCheck(msg: str):
5142
status = "Message length:"
5243
summary = msg.partition("\n")[0]
@@ -79,7 +70,7 @@ def main():
7970
is_ok = is_ok and result
8071

8172
if is_ok:
82-
print("All commmit messages are formtted correctly. ")
73+
print("All commmit messages are formatted correctly. ")
8374
else:
8475
print("Some commit message checks failed. Please align commit messages with Contributing Guidelines and update the PR.")
8576
exit(1)

0 commit comments

Comments
 (0)