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

ScoutSuite - lightning talk

ScoutSuite - lightning talk

This is a brief of a tech talk about the scoutesuite project. It was part of out DevOps teck forum which meets every 2 weeks. This tool helped me give quick value to analize a few security issues in an aws cloud environment in addition to some initial cost analysis, like identifying unused resources or as I like to call it the iimidiate suspects.

Read More
Planning a production ready kubernetes with fundamental Controllers & Operators — Part 5 — Scheduling

Planning a production ready kubernetes with fundamental Controllers & Operators — Part 5 — Scheduling

Originally posted on the Israeli Tech Radar on medium.

TL;DR A brief overview of scheduling in Kubernetes, “the almighty” controller loop, and additional “influencers” that enhance workload management.

Read More
Kubexperience for developers

Kubexperience for developers

Originally posted on the Israeli Tech Radar on medium.

TL;DR Kubernetes is much more than just a container orchestration platform … alongside The Cloud Native Landscape Kubernetes is the equivalent to Linux’s kernel with an ecosystem of apps/util which enriched it.

Read More