From 38a36f14a8210527969e445d1d2772f260ddbd6a Mon Sep 17 00:00:00 2001 From: Heanh Sok Date: Fri, 18 Jul 2025 00:58:11 -0400 Subject: [PATCH 1/2] Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pre-commit checks: All checks passed ✅ --- .../git/git_hooks/pre-commit.py | 2 + dev_scripts_helpers/git/git_hooks/utils.py | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/dev_scripts_helpers/git/git_hooks/pre-commit.py b/dev_scripts_helpers/git/git_hooks/pre-commit.py index 0906ebb1c..dada29e5e 100755 --- a/dev_scripts_helpers/git/git_hooks/pre-commit.py +++ b/dev_scripts_helpers/git/git_hooks/pre-commit.py @@ -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() diff --git a/dev_scripts_helpers/git/git_hooks/utils.py b/dev_scripts_helpers/git/git_hooks/utils.py index 476269512..f13f176ad 100644 --- a/dev_scripts_helpers/git/git_hooks/utils.py +++ b/dev_scripts_helpers/git/git_hooks/utils.py @@ -476,6 +476,47 @@ 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 # ############################################################################# From 0f6f1f6d96e22e5f579de1b408650577966400ac Mon Sep 17 00:00:00 2001 From: Heanh Sok Date: Fri, 18 Jul 2025 01:03:21 -0400 Subject: [PATCH 2/2] Lint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pre-commit checks: All checks passed ✅ --- dev_scripts_helpers/git/git_hooks/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev_scripts_helpers/git/git_hooks/utils.py b/dev_scripts_helpers/git/git_hooks/utils.py index f13f176ad..fc02db56a 100644 --- a/dev_scripts_helpers/git/git_hooks/utils.py +++ b/dev_scripts_helpers/git/git_hooks/utils.py @@ -484,6 +484,7 @@ def check_python_compile( 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 """ @@ -491,7 +492,7 @@ def check_branch_name(abort_on_error: bool = True) -> None: # Get current branch name. verbose = True cmd = "git rev-parse --abbrev-ref HEAD" - _ , branch_name = _system_to_string(cmd, verbose=verbose) + _, 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.