Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .commit-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[header]
# header line regex:
pattern = ^(option: |requirements: |ci: |doc: |release: ).+$
pattern = ^(option: |requirements: |ci: |doc: |release: |script: ).+$

[body]
# Allow empty body commit message. (i.e. single line commit message).
Expand Down
35 changes: 25 additions & 10 deletions commit_format/commit_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,26 @@
BLUE = '\033[94m'
RESET = '\033[0m'

def is_url(url):
def is_url(url: str) -> bool:
try:
result = urlparse(url)
return all([result.scheme, result.netloc])
except ValueError:
return False

def contains_url(string: str) -> bool:
if '/' not in string:
return False

# Split on '(', ')', '[', ']', and space ' '
word_list = re.split(r'[()\[\]\s]', string)

for w in word_list:
if is_url(w):
return True

return False

class CommitFormat:
def __init__(self, verbosity=False):
self.verbosity = verbosity
Expand Down Expand Up @@ -143,12 +156,13 @@ def lines_length(self, commit: str, commit_message: str, length_limit) -> bool:

line_length = len(line)
if line_length > length_limit:

# Check for lines containing URLs
if is_url(line.split()[-1]):
if len(line.split()) == 2:
# Expected format for URL: [index] url://...
continue
if contains_url(line):
# Check for lines containing URLs
if is_url(line.split()[-1]):
if len(line.split()) == 2:
# Comply with expected format for URL:
# [index] url://...
continue
url_format_error = True

length_exceeded += 1
Expand All @@ -171,10 +185,11 @@ def lines_length(self, commit: str, commit_message: str, length_limit) -> bool:
highlighted_commit_message += f"{self.highlight_words_in_txt(line, removed_words)}"

if length_exceeded:
self.warning(f"Commit {commit}: exceeds {length_limit} chars limit")
self.info(f"---\n{highlighted_commit_message}\n---")
if url_format_error is True:
self.warning("---\nURL format:\n[index] url://...\n---")
self.warning(f"Commit {commit}: bad URL format:\n[index] url://...")
else:
self.warning(f"Commit {commit}: exceeds {length_limit} chars limit")
self.info(f"---\n{highlighted_commit_message}\n---")

return length_exceeded

Expand Down