# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Jayson Reis <santosdosreis@gmail.com>

pkgname=commitizen
pkgver=2.20.0
pkgrel=2
pkgdesc="A tool for enforcing descriptive commit messages and version/changelog management"
arch=('any')
url="https://github.com/commitizen-tools/commitizen"
license=('MIT')
depends=(
  'python'
  'python-questionary'
  'python-decli'
  'python-colorama'
  'python-termcolor'
  'python-packaging'
  'python-tomlkit'
  'python-jinja'
  'python-pyaml'
  'python-argcomplete'
  'python-prompt_toolkit'
)
makedepends=(
  'python-pip'
  'python-build'
  'python-poetry'
)
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha512sums=('e32d9a3dc077631dfc7ab323138e328ace55a85fd2d7c8f491dca65c74553fb5567abcf7205de8bd2265e2894658e9bae1ca6c345b5ea72ab394156d43052574')
b2sums=('ad135d23ffb2b4e84eaadf27923cbf2fb50cff36ce80540d7a7ec96789fe201dc2d06f71895a094ae8e9282b208456dce55d95f73afffb6e617a5a3b3e630455')

prepare () {
  cd "$pkgname-$pkgver"

  # create completions
  mkdir completions
  register-python-argcomplete --shell bash cz > completions/bash
  register-python-argcomplete --shell fish cz > completions/fish
}

build() {
  cd "$pkgname-$pkgver"

  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "$pkgname-$pkgver"

  PIP_CONFIG_FILE=/dev/null pip \
    install \
    --isolated \
    --root="$pkgdir" \
    --ignore-installed \
    --no-deps \
    dist/*.whl

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE

  # shell completions
  install -vDm644 completions/bash "$pkgdir/usr/share/bash-completion/completions/cz"
  install -vDm644 completions/fish "$pkgdir/usr/share/fish/vendor_completions.d/cz.fish"
}