|
20 | 20 |
|
21 | 21 | import argparse
|
22 | 22 | import subprocess
|
| 23 | +import re |
23 | 24 |
|
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). |
25 | 29 | # TODO: Limit scopes to an acceptable list of tags.
|
26 | 30 | def __scopeCheck(msg: str):
|
27 | 31 | status = "Message scope: "
|
28 | 32 |
|
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>") |
33 | 35 | return False
|
34 | 36 |
|
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 |
| - |
46 | 37 | print(f"{status} OK")
|
47 | 38 | return True
|
48 | 39 |
|
49 |
| -# * Ensuring a character limit for the first line. |
| 40 | +# Ensuring a character limit for the first line. |
50 | 41 | def __numCharacterCheck(msg: str):
|
51 | 42 | status = "Message length:"
|
52 | 43 | summary = msg.partition("\n")[0]
|
@@ -79,7 +70,7 @@ def main():
|
79 | 70 | is_ok = is_ok and result
|
80 | 71 |
|
81 | 72 | if is_ok:
|
82 |
| - print("All commmit messages are formtted correctly. ") |
| 73 | + print("All commmit messages are formatted correctly. ") |
83 | 74 | else:
|
84 | 75 | print("Some commit message checks failed. Please align commit messages with Contributing Guidelines and update the PR.")
|
85 | 76 | exit(1)
|
|
0 commit comments