Skip to content

Git Hygiene Validator

Actions

About

Zero-dependency metadata validator for Commits, Branches, and PR Titles
v0.4.12
Latest
Starย (0)
Git Hygiene Hero Banner

git-hygiene ๐ŸŒŠ

The ultimate zero-dependency metadata validator for modern Git workflows.

CI Status Best Practices Scorecard Status OpenSSF Scorecard Gitleaks Hardened Zizmor Audited Code Coverage SLSA Level 3 License

Buy me a coffee at ko-fi.com

Features โ€ข Installation โ€ข Usage โ€ข Architecture โ€ข Contributing


git-hygiene is a high-performance, zero-dependency engine designed to enforce perfect metadata across your entire Git lifecycle. Built for Node.js 24+, it leverages native TypeScript type-stripping for microsecond startup times and zero-compilation runtime performance.


๐Ÿ“ฆ Registries & Links

Registry Package URL
NPM @chitrank2050/git-hygiene npmjs.com/package/@chitrank2050/git-hygiene
JSR @chitrank2050/git-hygiene jsr.io/@chitrank2050/git-hygiene
Marketplace git-hygiene-validator github.com/marketplace/actions/git-hygiene-validator
Core (NPM) @chitrank2050/git-hygiene-core npmjs.com/package/@chitrank2050/git-hygiene-core
Core (JSR) @chitrank2050/git-hygiene-core jsr.io/@chitrank2050/git-hygiene-core

Features โœจ

Feature Description
๐Ÿงผ Unified Engine Define your standards once. Enforce them in commits, branches, and PRs.
โšก Zero Dependencies Built using native Node.js APIs. No commander, yargs, or chalk bloat.
๐Ÿ›ก๏ธ Hardened Security 100% SHA-pinned workflows & OpenSSF Scorecard verified.
๐Ÿ“ฆ Universal Distribution Native support for NPM, JSR, and GitHub Actions.
๐Ÿง  Context Aware Automatically detects .git environment and CI context.

Installation ๐Ÿ“ฆ

# Using pnpm (Recommended)
pnpm add -D @chitrank2050/git-hygiene

# Using JSR (For Deno / Modern Node)
npx jsr add @chitrank2050/git-hygiene

# Using npm
npm install --save-dev @chitrank2050/git-hygiene

Usage ๐Ÿ› ๏ธ

1. Local Hooks (Lefthook)

The recommended way to use git-hygiene locally.

# lefthook.yml
commit-msg:
  commands:
    hygiene:
      run: npx @chitrank2050/git-hygiene commit {1}

pre-push:
  commands:
    hygiene:
      run: npx @chitrank2050/git-hygiene branch

2. Local Hooks (Husky)

For projects using Husky 9+.

# .husky/commit-msg
npx @chitrank2050/git-hygiene commit $1

# .husky/pre-push
npx @chitrank2050/git-hygiene branch

3. GitHub Actions (CI) ๐Ÿค–

Validate your metadata natively in CI. We recommend pinning to a specific SHA.

Smart Zero-Config Mode (Recommended)

Just drop the action into your PR workflow. It will automatically detect the context, validate your PR title and branch name, and suggest a version bump.

- name: Git Hygiene ๐ŸŒŠ
  uses: chitranklabs/git-hygiene@8abac926a6afcde68889b34f9ec3d1acefd69538

Manual Mode

For granular control over specific commands.

# Validate PR Title explicitly
- name: Validate PR Title ๐Ÿท๏ธ
  uses: chitranklabs/git-hygiene@8abac926a6afcde68889b34f9ec3d1acefd69538
  with:
    command: 'title'
    value: '${{ github.event.pull_request.title }}'

# Validate Branch Name
- name: Validate Branch Name ๐ŸŒฟ
  uses: chitranklabs/git-hygiene@8abac926a6afcde68889b34f9ec3d1acefd69538
  with:
    command: 'branch'
    value: '${{ github.head_ref }}'

4. Manual / Script Usage

Run any check manually from the terminal.

# Check a specific commit message
npx @chitrank2050/git-hygiene commit "feat: my awesome commit"

# Check a branch name string
npx @chitrank2050/git-hygiene branch "feature/cool-stuff"

# Check a PR title
npx @chitrank2050/git-hygiene title "fix(core): resolve memory leak"

# Suggest the next semantic version bump
npx @chitrank2050/git-hygiene bump

# Output result as JSON (useful for automation)
npx @chitrank2050/git-hygiene bump --json

๐Ÿ™ GitHub Action

You can easily integrate git-hygiene into your CI/CD pipeline using the official GitHub Action. This allows you to validate PR titles, branch names, and commit messages automatically.

Usage Example

jobs:
  hygiene:
    runs-on: ubuntu-latest
    steps:
      - name: Validate PR Title ๐ŸŒŠ
        id: hygiene
        uses: chitranklabs/git-hygiene@8abac926a6afcde68889b34f9ec3d1acefd69538
        with:
          command: 'title'
          value: ${{ github.event.pull_request.title }}

### Action Outputs ๐Ÿ“ค

When using the `bump` command, the action provides the following outputs:

| Output        | Description                                     |
| ------------- | ----------------------------------------------- |
| `releaseType` | Recommended bump (`patch`, `minor`, or `major`) |
| `reason`      | Explanation for the recommendation              |

```yaml
- name: Get Bump ๐Ÿš€
  id: bump
  uses: chitranklabs/git-hygiene@8abac926a6afcde68889b34f9ec3d1acefd69538
  with:
    command: 'bump'

- name: Tag Release ๐Ÿท๏ธ
  run: echo "Next version is ${{ steps.bump.outputs.releaseType }}"

Note on Pinning to a SHA: For maximum security and stability, we highly recommend pinning the uses directive to a specific commit SHA instead of a branch like @main. You can get the commit SHA by navigating to the Commits page of this repository and copying the 40-character hash (e.g. uses: chitranklabs/git-hygiene@8f3d...).


5. Programmatic Usage (Library)

Import the engine directly into your TypeScript project.

import { validateBranch, resolveConfig } from '@chitrank2050/git-hygiene-core';

// Standard usage (auto-loads package.json)
const { valid } = await validateBranch('feat/new-ui');

// Programmatic usage with config override
const customConfig = await resolveConfig({ types: ['feat', 'fix'] });
const result = await validateBranch('feat/new-ui', customConfig);

๐Ÿš€ Automated Releases

git-hygiene isn't just a validator-it's a release companion. You can use its outputs to automate your entire versioning pipeline. Check out our own release-prepare.yml to see how we use the bump output to automate version increments.


Configuration โš™๏ธ

git-hygiene is designed to be zero-config, but you can easily customize the engine by adding a git-hygiene block to your root package.json.

Reference Table

Property Description Default Possible Values
types Allowed commit types feat, fix, chore, etc. string[]
ignoreBranches Branches to skip validation (e.g. main) main, master, development, gh-pages string[]
maxHeaderLength Max length of the commit header 100 number
maxBodyLength Max length of a single body line 1000 number
minBodyLength Min length of the commit body 0 number
typeCase Case requirement for types lower-case lower-case, upper-case, camel-case, etc.
scopeCase Case requirement for scopes lower-case lower-case, upper-case, camel-case, etc.
allowEmptyScope Whether scope is optional true boolean
subjectFullStop Whether subject can end with a period never always, never
extends Standard configs to extend from [] ['@commitlint/config-conventional']
rules Raw commitlint rules to merge/override {} Record<string, unknown>

Example package.json

{
  "git-hygiene": {
    "extends": ["@commitlint/config-conventional"],
    "types": ["feat", "fix", "chore", "docs", "refactor", "test", "renovate"],
    "ignoreBranches": ["main", "develop", "release/*"],
    "maxHeaderLength": 100,
    "allowEmptyScope": false,
    "rules": {
      "subject-case": [2, "always", "sentence-case"],
      "header-max-length": [2, "always", 72]
    }
  }
}

Extending Configurations ๐Ÿ”Œ

git-hygiene now supports extending standard configurations. The most common use case is extending @commitlint/config-conventional to inherit the industry-standard types and rules.

When you extend a configuration:

  • Types are merged: Your local types are combined with the types from the extended config.
  • Rules are inherited: Standard rules (like header-max-length) are automatically applied.
  • Parser Presets: Advanced syntax (like the ! breaking change indicator) is automatically supported.

Raw Commitlint Rules ๐Ÿ› ๏ธ

For power users, the rules property allows you to pass any raw commitlint rule directly to the underlying engine. This gives you full control over every aspect of your commit validation.

"rules": {
  "body-leading-blank": [2, "always"],
  "footer-leading-blank": [1, "always"]
}

Architecture ๐Ÿ›๏ธ

graph TD
    A[Consumer Project] -->|CLI| B["@chitrank2050/git-hygiene"]
    A -->|Action| C["GitHub Action (Root)"]
    B --> D["@chitrank2050/git-hygiene-core"]
    C --> D
    D -->|Engine| E["Conventional Commits & Regex"]
Loading

๐Ÿ™ Credits

git-hygiene stands on the shoulders of giants. Special thanks to:

  • commitlint: For the industry-standard commit validation logic we use under the hood.

Contributing ๐Ÿค

We โค๏ธ contributions! Whether you're fixing a bug, adding a feature, or improving documentation, please see our Contributing Guide to get started.


Community & Support ๐ŸŒ


๐Ÿ›ก๏ธ Security & Quality

  • Secret Scanning: Gitleaks prevents credential leaks in every commit.
  • Workflow Auditing: Zizmor ensures GitHub Actions follow security best practices.
  • Supply Chain: All GitHub Actions are pinned to secure commit SHAs.
  • Provenace: Automated build attestations for every release.

Developed with โค๏ธ by Chitrank Agnihotri

If you use this in your project, a credit or star is appreciated. โœจ

Git Hygiene Validator is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Zero-dependency metadata validator for Commits, Branches, and PR Titles
v0.4.12
Latest

Git Hygiene Validator is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.