Pre-commit hooks using python library pre-commit

Pre-commit hooks using python library pre-commit

Table of Contents

Pre-commit examples used in just-do-it repository

I really need a strict pre-commit considering the number of branches and tools i’m using. Because the heart of the projects is tasks I want at the bare least .pre-commit-config.yaml to include the task --list-all command considering it compiles all the includes which may change name / location between branches.

so pre-commit-reset so designed to the bare minimum! by design in case you get stuck and i need to re-build it from scratch and on the fly…, it will only work if RESET_PRECOMMIT is not “true”

# cat<<EOF>.pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: run-custom-script
        name: Run /usr/bin/env task --list-all
        entry: /usr/bin/env task --list-all
        # entry: ./posts/pre-commit/pre-commit.sh
        language: script
        pass_filenames: false
        stages: [commit]
      - repo: https://github.com/pre-commit/pre-commit-hooks
        rev: v3.4.0
        hooks:
        - id: check-yaml
            exclude: '^charts/helm-example/.*\.yaml$|^charts/common-helm-lib/.*/test-connection.yaml$'
        - id: check-executables-have-shebangs

want to reset / rest after you tweaked with the template

RESET_PRECOMMIT="true" task pre-commit:1st-run

Available Tasks

The following tasks are available for managing pre-commit hooks:

Info

So a good place to start is the code which is available at hagzag/just-do-it

Core Tasks

  • pre-commit:1st-run - Reset pre-commit configuration to bare minimal
  • pre-commit:gen-default-pre-commit-config - Create the base configuration
  • pre-commit:get - Install pre-commit via homebrew
  • pre-commit:install - Configure pre-commit in local repo
  • pre-commit:run - Run pre-commit on staged files
  • pre-commit:run-all-files - Run pre-commit against all files

Usage Examples

Reset/initialize pre-commit configuration:

RESET_PRECOMMIT="true" task pre-commit:1st-run

Run pre-commit checks on staged files:

task pre-commit:run

Install pre-commit for the first time:

task pre-commit:get pre-commit:install

Task Dependencies

    graph TD
	    A[pre-commit:1st-run] --> B[pre-commit:run-all-files]
	    C[pre-commit:install] --> D[pre-commit:get]
comments powered by Disqus

Related Posts

A CloudNative Dev Experience 🎯 | Tikal TechRadarCon 2021

A CloudNative Dev Experience 🎯 | Tikal TechRadarCon 2021

Originally posted on the Israeli Tech Radar on medium.

TLDR; Just when we thought we’ve got it figured out! We learn there’s a better, faster way of doing things, frameworks, abstractions, and methodologies invented to make our development experience easier, and help us during our journey to building a platform. But…Do we really need one?/Should we adopt one? What impact will that have on our product? The following post will try to tackle some of these questions as we explore building a better Developer Experience.

Read More
Minkube Introduction, in my early days with Kubernetes & Youtube

Minkube Introduction, in my early days with Kubernetes & Youtube

Everyone is talking about Serverless, Functions, Lambda, DynamoDB, Firebase and more. What exactly do they mean? How does it affect the future of systems development? How can I use this new plethora of services and infrastructure?

Read More