Skip to content
Draft
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: 2 additions & 0 deletions dev_scripts_helpers/git/git_hooks/pre-commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def _write_output_to_file(lines: List[str]) -> None:
#
dshgghout.check_master()
#
dshgghout.check_branch_name()
#
dshgghout.check_author()
#
dshgghout.check_file_size()
Expand Down
42 changes: 42 additions & 0 deletions dev_scripts_helpers/git/git_hooks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,48 @@ def check_python_compile(
_handle_error(func_name, error, abort_on_error)


# #############################################################################
# check_branch_name
# #############################################################################


def check_branch_name(abort_on_error: bool = True) -> None:
"""
Check if the current branch name follows the expected naming convention.

- Expected format: {Prefix}Task{Number}_{Description}
- Example: HelpersTask123_Add_new_feature
"""
func_name = _report()
# Get current branch name.
verbose = True
cmd = "git rev-parse --abbrev-ref HEAD"
_, branch_name = _system_to_string(cmd, verbose=verbose)
branch_name = branch_name.strip()
print(f"Branch is '{branch_name}'")
# Skip validation for master/main branches.
if branch_name in ["master", "main"]:
print("Skipping branch name validation for master/main branch")
error = False
else:
# Check if branch name follows the expected pattern.
# Pattern: {Prefix}Task{Number}_{Description}
# Examples: HelpersTask123_Add_feature, AmpTask456_Fix_bug
pattern = r"^\S+Task\d+_\S+$"
if not re.match(pattern, branch_name):
msg = (
f"Branch name '{branch_name}' does not follow the expected naming convention.\n"
f"Expected format: {{Prefix}}Task{{Number}}_{{Description}}\n"
f"Examples: HelpersTask123_Add_feature, AmpTask456_Fix_bug"
)
_LOG.error(msg)
error = True
else:
error = False
# Handle error.
_handle_error(func_name, error, abort_on_error)


# #############################################################################
# check_gitleaks
# #############################################################################
Expand Down