Commit 98be58f7 authored by Adrian DC's avatar Adrian DC
Browse files

chore(pre-commit): migrate to 'pre-commit-crocodile' 2.0.0-db6f0f8

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 26bb859b
Loading
Loading
Loading
Loading
Loading

.hooks/manage

deleted100755 → 0
−173
Changes for .hooks/manage: 0 added lines, 173 removed lines.
Original line number Diff line number Diff line
#!/bin/bash

# Variables
help='false'
install='false'
run='false'
result=0
uninstall='false'

# Missing arguments
if [ -z "${*:-}" ]; then
  help='true'
  result=61 # ENODATA
fi

# Parse arguments
while [ ! -z "${1:-}" ]; do
  case "${1}" in
    -h | --help)
      help='true'
      ;;
    -i | --install)
      install='true'
      ;;
    -r | --run)
      run='true'
      ;;
    -u | --uninstall)
      uninstall='true'
      ;;
    *)
      help='true'
      result=22 # EINVAL
      ;;
  esac
  shift
done

# Helper
if [ "${help}" = 'true' ] || [ "${params_unknown}" = 'true' ]; then
  echo ''
  echo -e " \033[1;33m[INFO] \033[0m\033[1mHelper usage:    \033[0m${0} [-h | --help]"
  echo -e " \033[1;33m[INFO] \033[0m\033[1mInstall usage:   \033[0m${0} [-i | --install]"
  echo -e " \033[1;33m[INFO] \033[0m\033[1mUninstall usage: \033[0m${0} [-u | --uninstall]"
  echo -e " \033[1;33m[INFO] \033[0m\033[1mHooks usage:     \033[0m${0} [-r | --run]"
  echo ''
  exit "${result}"
fi

# Header
echo ''

# Install dependencies
if [ "${install}" = 'true' ] || [ "${run}" = 'true' ]; then

  # Install pre-commit dependency
  if [ "${result}" -eq 0 ]; then
    if ! type pre-commit >/dev/null 2>&1 || [ "${install}" = 'true' ]; then
      if type pipx >/dev/null 2>&1; then
        pipx uninstall pre-commit || true
        pipx install pre-commit
        result="${?}"
      else
        sudo pip uninstall pre-commit || true
        sudo pip install pre-commit
        result="${?}"
      fi
      echo ''
    fi
  fi

  # Install commitizen dependency
  if [ "${result}" -eq 0 ]; then
    if ! type git-cz >/dev/null 2>&1 || [ "${install}" = 'true' ] || ! cz version | grep -q '^3.29.0.AdrianDC.20240813$'; then
      if type pipx >/dev/null 2>&1; then
        pipx uninstall commitizen || true
        pipx install git+https://github.com/AdrianDC/commitizen.git@prerelease
        result="${?}"
      else
        sudo pip uninstall commitizen || true
        sudo pip install git+https://github.com/AdrianDC/commitizen.git@prerelease
        result="${?}"
      fi
      echo ''
    fi
  fi

  # Install argcomplete completion
  if [ "${result}" -eq 0 ]; then
    if ! grep -q 'argcomplete' ~/.bash_completion 2>/dev/null || ! grep -q 'argcomplete' ~/.zshenv 2>/dev/null; then
      activate-global-python-argcomplete --user
      result="${?}"
      echo ''
    fi
  fi

  # Install commitizen completion
  if [ "${result}" -eq 0 ]; then
    user_bashrc=''
    if [ -e ~/.bash_user.rc ]; then
      user_bashrc="${HOME}/.bash_user.rc"
    else
      user_bashrc="${HOME}/.bashrc"
    fi
    if ! grep -q 'register-python-argcomplete cz' "${user_bashrc}"; then
      {
        echo ''
        echo '# register-python-argcomplete cz'
        echo 'eval "$(register-python-argcomplete cz)"'
      } >>"${user_bashrc}"
    fi
  fi

fi

# Install hooks
if [ "${install}" = 'true' ]; then

  # Configure local project
  if [ "${result}" -eq 0 ]; then
    git remote | xargs -i -n1 git remote set-head '{}' -a || true
    echo ''
  fi

  # Install pre-commit hooks
  if [ "${result}" -eq 0 ]; then
    pre-commit install
    result="${?}"
    echo ''
  fi

  # Update pre-commit repositories
  if [ "${result}" -eq 0 ]; then
    pre-commit autoupdate
    result="${?}"
    echo ''
  fi

fi

# Uninstall hooks
if [ "${uninstall}" = 'true' ]; then

  # Uninstall pre-commit hooks
  if [ "${result}" -eq 0 ]; then
    pre-commit uninstall
    result="${?}"
    echo ''
  fi

fi

# Run hooks
if [ "${install}" = 'true' ] || [ "${run}" = 'true' ]; then

  # Run pre-commit hooks
  if [ "${result}" -eq 0 ]; then
    pre-commit run -a
    result="${?}"
    echo ''
  fi

  # Run commitizen checks
  if [ "${result}" -eq 0 ]; then
    cz check --rev-range HEAD^..HEAD
    result="${?}"
    echo ''
  fi

fi

# Result
exit "${result}"
+2 −2
Changes for .pre-commit-config.yaml: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -62,8 +62,8 @@ repos:
          - push

  # Repository: pre-commit-crocodile
  - repo: https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile.git
    rev: 1.1.0
  - repo: https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile
    rev: db6f0f8
    hooks:
      - id: prepare-commit-message

+2
Changes for README.md: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=AdrianDC_pexpect-executor&metric=alert_status)](https://sonarcloud.io/dashboard?id=AdrianDC_pexpect-executor)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](https://commitizen-tools.github.io/commitizen/)
[![pre-commit-crocodile](https://img.shields.io/badge/pre--commit--crocodile-enabled-brightgreen?logo=gitlab)](https://radiandevcore.gitlab.io/tools/pre-commit-crocodile)

Automate interactive CLI tools actions to create previews or tests in Python.

@@ -172,6 +173,7 @@ pexpect-executor --settings
- [gcil](https://pypi.org/project/gcil/): Launch .gitlab-ci.yml jobs locally
- [mypy](https://pypi.org/project/mypy/): Optional static typing for Python
- [pre-commit](https://pre-commit.com/): A framework for managing and maintaining pre-commit hooks
- [pre-commit-crocodile](https://radiandevcore.gitlab.io/tools/pre-commit-crocodile): Git hooks intended for developers using pre-commit
- [PyPI](https://pypi.org/): The Python Package Index
- [termtosvg](https://pypi.org/project/termtosvg/): Record terminal sessions as SVG animations
- [twine](https://pypi.org/project/twine/): Utility for publishing on PyPI