Skip to content

NTT-DATA-Cloud-Transformation/central-repo-git-hooks

Repository files navigation

central-repo-git-hooks

This is Flux7 Centralized repository for git pre-commit hooks.

What is git-hooks

Git hooks are scripts that Git executes automaticaly on occurance of events like commit, push, and receive.

pre-commit tool

Pre-Requisites

  • You need to have the pre-commit package manager installed.

How to use pre-commit

create a direcotry for your project repository and and initiliaze the git using git init command.
$ git init
Initialized empty Git repository in /home/kishor_flux7/mywork/testing/.git/

create  .pre-commit-config.yaml file .
$ vi .pre-commit-config.yaml

Add the reference to use this repo and the rev as the brach or git tag , and under hooks list add the hooks you wish to call.
$ cat .pre-commit-config.yaml
- repo: https://github.com/NTT-DATA-Cloud-Transformation/central-repo-git-hooks
  rev: master
  hooks:
    - id: terraform-fmt

Run the pre-commit install command to initialize the pre-commit.
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit

Run the following command to test if the pre-commit hook executes.
$ pre-commit run -a
Terraform fmt........................................(no files to check)Skipped

Hooks available

Following are the available hooks -

- id: check-readme
  description: Validate for readme file presence

- id: validate-author-email
  description: Validate the author flux7 email address

- id: terraform-fmt
  description: Runs `terraform fmt` on all Terraform files

- id: security-check
  description: 'Scans Terraform, AWS CloudFormation and Kubernetes configuration files.'

- id: packer-validate
  description: Runs `packer validate` on all staged packer files

- id: cfn-lint
  description: Runs cfn-lint on CloudFormation Templates

- id: flake8-lint
  description: '`flake8` is a command-line utility for enforcing style consistency across Python projects.'

- id: check-prtemplate
  description: Validate for PR template file presence

# The below hooks are only required or used by a PR build and not required to be used by developers
- id: prbuild-cfn-lint
  description: Runs cfn-lint on CloudFormation Templates when a pr build is invoked

Developer - How to trigger hooks validation

The pre-commit hooks from this central-repo-git-hooks repo can be triggered to run against any repository.

How this repo can be used as a part of the Server based PR Builds?

Makefile : The makefile is developed as a part of this repository for the flexibility to use the pre-commit hooks as a part of server based pr builds on multiple repositories. For eg At Flux7, this make file is used by a centralized CI System which runs the code linting as a check on all the repositories irrespective of the language used by the code repository and this "Code-Linter" CI check could be possibly used to block merges to master.