guibranco / gstraccini-bot-api

πŸ€– :octocat: GStraccini-bot automates repository management, ensuring organization and health by handling pull requests, issues, comments, and commits.
https://gstraccini.bot
MIT License
1 stars 0 forks source link

Implement pre-commit hook for branch name validation #11

Closed guibranco closed 3 days ago

guibranco commented 3 days ago

User description

Closes #

πŸ“‘ Description

βœ… Checks

☒️ Does this introduce a breaking change?

β„Ή Additional Information


Description


Changes walkthrough πŸ“

Relevant files
Enhancement
pre-commit
Implement pre-commit hook for branch name validation         

.githooks/pre-commit
  • Added a pre-commit hook script.
  • Validates branch names against a regex pattern.
  • Rejects commits if branch names do not conform to the specified
    format.
  • +14/-0   

    πŸ’‘ Penify usage: Comment /help on the PR to get a list of all available Penify tools and their descriptions

    penify-dev[bot] commented 3 days ago

    PR Review πŸ”

    ⏱️ Estimated effort to review [1-5] 2, because the changes are straightforward and involve a simple script for branch name validation.
    πŸ§ͺ Relevant tests No
    ⚑ Possible issues No
    πŸ”’ Security concerns No
    penify-dev[bot] commented 3 days ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Add a check to ensure the script is running inside a git repository ___ **It is a good practice to ensure that the script is executed in a git repository to avoid
    errors when running git commands.** [.githooks/pre-commit [4]](https://github.com/guibranco/gstraccini-bot-api/pull/11/files#diff-87320095d7c4f39eed5d8f3866b512eb910e4eec8e7926faaeef6a53ab786fcbR4-R4) ```diff -local_branch="$(git rev-parse --abbrev-ref HEAD)" +if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then echo "Not a git repository."; exit 1; fi; local_branch="$(git rev-parse --abbrev-ref HEAD)" ```
    Suggestion importance[1-10]: 9 Why: Adding a check to ensure the script is running inside a git repository is crucial for preventing runtime errors, making this a strong suggestion.
    9
    Use double quotes around variable expansions for safety ___ **Consider using double quotes around variable expansions to prevent word splitting and
    globbing issues.** [.githooks/pre-commit [10]](https://github.com/guibranco/gstraccini-bot-api/pull/11/files#diff-87320095d7c4f39eed5d8f3866b512eb910e4eec8e7926faaeef6a53ab786fcbR10-R10) ```diff -if [[ ! $local_branch =~ $valid_branch_regex ]] +if [[ ! "$local_branch" =~ $valid_branch_regex ]] ```
    Suggestion importance[1-10]: 8 Why: Using double quotes around variable expansions is a good practice that enhances safety and prevents potential bugs, making this a valuable suggestion.
    8
    Explicitly set the exit status to indicate successful execution ___ **The exit status of the script should be explicitly set to 0 at the end to indicate
    successful execution if no errors occur.** [.githooks/pre-commit [13]](https://github.com/guibranco/gstraccini-bot-api/pull/11/files#diff-87320095d7c4f39eed5d8f3866b512eb910e4eec8e7926faaeef6a53ab786fcbR13-R13) ```diff -exit 1 +exit 0 ```
    Suggestion importance[1-10]: 5 Why: While explicitly setting the exit status to 0 can improve clarity, the current implementation already exits with a non-zero status on failure, making this suggestion less critical.
    5
    Possible issue
    Enhance the regex pattern for stricter branch name validation ___ **Consider using a more specific regex pattern to prevent potential edge cases and ensure
    branch names are strictly validated.** [.githooks/pre-commit [6]](https://github.com/guibranco/gstraccini-bot-api/pull/11/files#diff-87320095d7c4f39eed5d8f3866b512eb910e4eec8e7926faaeef6a53ab786fcbR6-R6) ```diff -valid_branch_regex="^(dependabot|feature|fix|docs|style|refactor|perf|hotfix|test|chore|create)(\/[a-zA-Z0-9._-]+)+$" +valid_branch_regex="^(dependabot|feature|fix|docs|style|refactor|perf|hotfix|test|chore|create)(\/[a-zA-Z0-9._-]+{1,})$" ```
    Suggestion importance[1-10]: 6 Why: While enhancing the regex pattern can improve validation, the current pattern is already functional for most use cases. This suggestion addresses a minor improvement rather than a critical issue.
    6