Skip to content

Commit

Permalink
github: automation: fixed rules for commit scope check
Browse files Browse the repository at this point in the history
  • Loading branch information
vpirogov committed Dec 18, 2024
1 parent 7e450f8 commit 1a93cc3
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions .github/automation/commit-msg-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,17 @@

import argparse
import subprocess
import re

# * Ensuring the scopes end in colon and same level scopes are comma delimited.
# TODO: Limit scopes to an acceptable list of tags.
def __scopeCheck(msg: str):
status = "Message scope: "

firstLine = (msg.partition("\n")[0]).strip()

if not ":" in firstLine:
print(f"{status} FAILED: Commit message does not include scope")
if not re.match('^[a-z0-9]+: ', msg):
print(f"{status} FAILED: Commit message must follow the format <scope>:[ <scope>:] <short description>")
return False

# The last element of the split is the title, which we don't care about.
scopesArray = firstLine.split(":")[:-1]

for scopes in scopesArray:
numWords = len(scopes.split())
numCommas = scopes.count(",")

if numWords != numCommas + 1:
print(f"{status} FAILED: Same-level scopes must be comma-separated. Bad token: '{scopes}'")
return False

print(f"{status} OK")
return True

Expand Down Expand Up @@ -79,7 +67,7 @@ def main():
is_ok = is_ok and result

if is_ok:
print("All commmit messages are formtted correctly. ")
print("All commmit messages are formatted correctly. ")
else:
print("Some commit message checks failed. Please align commit messages with Contributing Guidelines and update the PR.")
exit(1)
Expand Down

0 comments on commit 1a93cc3

Please sign in to comment.