guibranco / PIX-BACEN-SDK-dotnet

๐Ÿ‡ง๐Ÿ‡ท :bank: :gear: PIX/SPI contracts from @bacen/pix-api/
https://guibranco.github.io/PIX-BACEN-SDK-dotnet/
MIT License
20 stars 7 forks source link

Implement pre-commit hook for branch validation #122

Closed guibranco closed 2 weeks ago

guibranco commented 2 weeks ago

Description


Changes walkthrough ๐Ÿ“

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

.githooks/pre-commit
  • Added a pre-commit hook script.
  • Validates branch names against a regex pattern.
  • Provides a message for invalid branch names.
  • Restores .NET tools and checks code formatting.
  • +16/-0   
    penify-dev[bot] commented 2 weeks ago

    PR Review ๐Ÿ”

    โฑ๏ธ Estimated effort to review [1-5] 2, because the changes are straightforward and involve a simple script with clear functionality.
    ๐Ÿงช Relevant tests No
    โšก Possible issues No
    ๐Ÿ”’ Security concerns No
    penify-dev[bot] commented 2 weeks ago

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Enable immediate exit on command failure for better error handling ___ **Consider using set -e at the beginning of the script to ensure that the script exits
    immediately if any command fails, improving error handling.** [.githooks/pre-commit [1]](https://github.com/guibranco/PIX-BACEN-SDK-dotnet/pull/122/files#diff-87320095d7c4f39eed5d8f3866b512eb910e4eec8e7926faaeef6a53ab786fcbR1-R1) ```diff +#!/usr/bin/env bash ++set -e ```
    Suggestion importance[1-10]: 9 Why: This is a best practice that significantly improves error handling by preventing the script from continuing after a failure, which is essential for reliable script execution.
    9
    Possible issue
    Add a check for the availability of the dotnet command before executing it ___ **Consider adding a check to ensure that the dotnet command is available before attempting
    to run it, to prevent potential errors if the tool is not installed.** [.githooks/pre-commit [16]](https://github.com/guibranco/PIX-BACEN-SDK-dotnet/pull/122/files#diff-87320095d7c4f39eed5d8f3866b512eb910e4eec8e7926faaeef6a53ab786fcbR16-R16) ```diff ++command -v dotnet >/dev/null 2>&1 || { echo "dotnet is not installed. Please install it to proceed." >&2; exit 1; } +dotnet tool restore && dotnet csharpier . --check ```
    Suggestion importance[1-10]: 8 Why: This suggestion addresses a potential runtime error by ensuring that the `dotnet` command is available before execution, which is crucial for the script's functionality.
    8
    Enhancement
    Improve the branch name regex to prevent leading or trailing slashes ___ **The regex used for branch validation could be enhanced to ensure it does not allow invalid
    characters or patterns, such as leading or trailing slashes.** [.githooks/pre-commit [6]](https://github.com/guibranco/PIX-BACEN-SDK-dotnet/pull/122/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._-]+)*$" ```
    Suggestion importance[1-10]: 7 Why: Improving the regex for branch validation enhances the robustness of branch name checks, preventing invalid patterns, which is important for maintaining naming conventions.
    7
    Add a success message for valid branch names to enhance user feedback ___ **It may be beneficial to include a message indicating successful validation of the branch
    name after the check passes, to provide feedback to the user.** [.githooks/pre-commit [10-14]](https://github.com/guibranco/PIX-BACEN-SDK-dotnet/pull/122/files#diff-87320095d7c4f39eed5d8f3866b512eb910e4eec8e7926faaeef6a53ab786fcbR10-R14) ```diff -+if [[ ! $local_branch =~ $valid_branch_regex ]] ++if [[ ! $local_branch =~ $valid_branch_regex ]]; then ++ echo "$message" ++ exit 1 ++else ++ echo "Branch name is valid." ++fi ```
    Suggestion importance[1-10]: 5 Why: While adding user feedback is helpful for clarity, it is not critical to the functionality of the script, making this a minor enhancement.
    5
    codacy-production[bot] commented 2 weeks ago

    Coverage summary from Codacy

    See diff coverage on Codacy

    Coverage variation Diff coverage
    :white_check_mark: +0.00% (target: -1.00%) :white_check_mark: โˆ…
    Coverage variation details | | Coverable lines | Covered lines | Coverage | | ------------- | ------------- | ------------- | ------------- | | Common ancestor commit (a9df1f137fb101e2775938d0ca6311ce863bbf41) | 75 | 1 | 1.33% | | | Head commit (d39fad634e75f30d107e6d94a420765f6e22eb61) | 75 (+0) | 1 (+0) | 1.33% (**+0.00%**) | **Coverage variation** is the difference between the coverage for the head and common ancestor commits of the pull request branch: ` - `
    Diff coverage details | | Coverable lines | Covered lines | Diff coverage | | ------------- | ------------- | ------------- | ------------- | | Pull request (#122) | 0 | 0 | **โˆ… (not applicable)** | **Diff coverage** is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: `/ * 100%`

    See your quality gate settings    Change summary preferences

    Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

    AppVeyorBot commented 2 weeks ago

    :white_check_mark: Build PIX-BACEN-SDK-dotnet 1.1.338 completed (commit https://github.com/guibranco/PIX-BACEN-SDK-dotnet/commit/aeababd95a by @guibranco)

    codecov[bot] commented 2 weeks ago

    Codecov Report

    All modified and coverable lines are covered by tests :white_check_mark:

    Project coverage is 1.33%. Comparing base (a9df1f1) to head (d39fad6). Report is 1 commits behind head on main.

    Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #122 +/- ## ===================================== Coverage 1.33% 1.33% ===================================== Files 17 17 Lines 75 75 ===================================== Hits 1 1 Misses 74 74 ```

    :umbrella: View full report in Codecov by Sentry.
    :loudspeaker: Have feedback on the report? Share it here.

    github-actions[bot] commented 2 weeks ago

    Infisical secrets check: :white_check_mark: No secrets leaked!

    Scan results:

    1:18PM INF scanning for exposed secrets...
    1:18PM INF 145 commits scanned.
    1:18PM INF scan completed in 100ms
    1:18PM INF no leaks found
    
    sonarcloud[bot] commented 2 weeks ago

    Quality Gate Passed Quality Gate passed

    Issues
    0 New issues
    0 Accepted issues

    Measures
    0 Security Hotspots
    0.0% Coverage on New Code
    0.0% Duplication on New Code

    See analysis details on SonarCloud

    AppVeyorBot commented 2 weeks ago

    :white_check_mark: Build PIX-BACEN-SDK-dotnet 1.1.355 completed (commit https://github.com/guibranco/PIX-BACEN-SDK-dotnet/commit/dfaf8a625e by @gstraccini[bot])