Skip to main content

Hook to validate branch name and issue

Project description

Nabla nabla-hooks

Nabla custom git hooks

License Gitter

Quality Gate Status GitHub pull requests

This project intend to be uses by all Nabla products

Table of contents

// spell-checker:disable

// spell-checker:enable

Initialize

Using pipenv Pipfile

direnv allow
pyenv install 3.10.9
pyenv local 3.10.9
python -m pipenv install --dev --ignore-pipfile
direnv allow
pre-commit install

Using poetry pyproject.toml

pip install -U poetry pipenv-poetry-migrate
pipenv-poetry-migrate -f Pipfile -t pyproject.toml --no-use-group-notation

Requirements

This hooks requires the following to run:

See requirements.txt for mandatory packages.

This pre-commit hooks requires the following to run:

Install nabla-hooks as a developer

Using virtualenv

Install python 3.10 and virtualenv

virtualenv --no-site-packages /opt/ansible/env310 -p python3.10
source /opt/ansible/env310/bin/activate

Install python 3.8 and pyenv

curl -L https://pyenv.run | bash
echo 'export PATH="~/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc

pyenv install 3.10.9

and integrate it with direnv

#pip3.8 install -r hooks/requirements.txt -r requirements.testing.txt
pipenv check
python -m pipenv install --dev
python -m pipenv install --dev --ignore-pipfile

Install nabla-hooks to use it

Using Pip

pip install nabla-hooks

From Source

pip install git+https://github.com/AlbanAndrieu/nabla-hooks.git

Add .pre-commit-config.yaml in you git project

  1. create .pre-commit-config.yaml in you git project

example .pre-commit-config.yaml as following:

-   repo: https://github.com/AlbanAndrieu/nabla-hooks.git
    rev: v1.0.3
    hooks:
    - id: git-branches-check

Testing locally

-   repo: local
    hooks:
    -   id: git-branches-check
        name: GIT branches check
        description: Check for old stale and already merged branches from the current repo with user friendly messages and colors
        entry: pre_commit_hooks/git-branches-check.sh
        language: script
        types: [shell]
        always_run: true
        verbose: true
        args: [--max=1, --verbose]

$ pre-commit try-repo . git-branches-check --verbose

  1. Install in your repo

Run pre-commit install pre-commit install -f --install-hooks

  1. enjoy it

Run pre-commit run --all-files

Run SKIP=flake8 git commit -am 'Add key' Run git commit -am 'Add key' --no-verify

Override global environment variable

Login

See jira

With user/pass
export JIRA_USER=aandrieu
export JIRA_PASSWORD=XXX
export JIRA_URL=https://localhost/jira
export JIRA_CERT_PATH=/etc/ssl/certs/NABLA-CA-1.crt
export JIRA_CERT_PATH=/etc/ssl/certs/ca-certificates.crt
With email/token
export JIRA_USER=alban.andrieu@free.fr
export JIRA_PASSWORD=XXX # the token you generated
export JIRA_URL==https://localhost/jira
export JENKINS_URL=https://localhost/jenkins/
export JENKINS_USER=aandrieu
export JENKINS_USER_TOKEN=XXX

The Templates Directories

See git-hooks-using-python

Local

First time run

cp -r hooks/* .git/hooks/` or `rm -Rf ./.git/hooks/ && ln -s ../hooks ./.git/hooks && git checkout repo hooks/

Global

We have two directories that interest us:

The /usr/share/git-core/templates/ directory on Linux and C:/Program Files (x86)/Git/share/git-core/templates/ directory on Windows (Note that on 32bit machines msysGit is installed by default on 'C:/Program Files/…') in which the default hooks are being copied from. If you installed Git using another configuration the installation might reside in a different folder. Adjust the path accordingly.

The .git/hooks/ directory is the directory in which the hooks templates are being copied to.

The hooked are being copied from the [...]/share/git-core/templates/ directory. There are other types of templates but they are out of scope for this post.

Note: If you change the templates directory the hooks directory must be a subdirectory of the templates directory. Do not set the templates directory to the desired hooks directory instead.

Run

git config --global --get init.templatedir
rm -Rf .git/hooks
git config --global init.templatedir /workspace/users/albandrieu30/nabla-hooks/

Package nabla-hooks as a developer

See setup-cfg

Build a source distribution (a tar archive of all the files needed to build and install the package):

python3 setup.py sdist Builds wheels: python3 setup.py bdist_wheel Build from source: python3 setup.py build And install: /opt/ansible/env38/bin/python3 setup.py install

sudo python setup.py develop pip install . pip install -e ./

Upload a source distribution

See api-tokens

rm -Rf dist/
python3 setup.py sdist bdist_wheel
# Check package
twine check dist/*
nano $HOME/.pypirc
export TWINE_PASSWORD=pypi-
python3 -m twine upload --repository nabla-hooks dist/* --verbose

All in one

python setup.py register sdist upload

Uploaded nabla-hooks

Test nabla-hooks as a developer

shell usage

python

from hooks import get_msg
match_msg

versioneer

versioneer

versioneer install
#check with
python setup.py version
python setup.py install

Test

source deactivate
tox --notest
tox -e py  # Run tox using the version of Python in PATH
tox py310

From root directory

pytest --cache-clear --setup-show hooks/test/test_pytest.py
pytest --cache-clear --setup-show test/package.py

Poetry

poetry install
poetry env info
poetry shell
poetry run pytest
poetry build
#poetry publish --build

Pdm

pdm

pdm init
pdm run flake8

Update README.md

npm install --save markdown-toc
markdown-toc README.md -i
markdown-toc CHANGELOG.md -i
pre-commit install
git add README.md
pre-commit run markdown-toc

Check syntax remark-lint

npm run lint-md

npm-groovy-lint groovy formatting for Jenkinsfile

Tested with nodejs 12 and 16 on ubuntu 20 and 21 (not working with nodejs 11 and 16)

npm install -g npm-groovy-lint@8.2.0
npm-groovy-lint --format
ll .groovylintrc.json

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nabla_hooks-1.0.5.tar.gz (137.1 kB view details)

Uploaded Source

Built Distribution

nabla_hooks-1.0.5-py2.py3-none-any.whl (57.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file nabla_hooks-1.0.5.tar.gz.

File metadata

  • Download URL: nabla_hooks-1.0.5.tar.gz
  • Upload date:
  • Size: 137.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.9

File hashes

Hashes for nabla_hooks-1.0.5.tar.gz
Algorithm Hash digest
SHA256 82f9911c7cc302f0b47156e9a1280fe1512f26f96aea0982b4f4f8d55d6332a8
MD5 1de6dbe82b507654b696e86fd28e6911
BLAKE2b-256 54254c02f99775810f64f82f696b4ce5414a32d57707b100da629f1bbb6c2712

See more details on using hashes here.

File details

Details for the file nabla_hooks-1.0.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for nabla_hooks-1.0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 13642adb8dcad208abc5e3a5e6f5aec0296e4ceeffec7bfde85763be79113f2a
MD5 5a2bc98f1f6aa3398ced56e8e487d571
BLAKE2b-256 4c3115c176a97f31ecefb1dba6bee89a1395eeab7a9f222f38e2068e991f5348

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page