GithubHelp home page GithubHelp logo

cezudas / validate-branch-name Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jsonma/validate-branch-name

0.0 0.0 0.0 111 KB

Git branch name validation tool(welcome to star this project). Git分支名校验工具(如果喜欢请点赞支持).

License: MIT License

JavaScript 98.38% Shell 1.62%

validate-branch-name's Introduction

validate-branch-name

GitHub license npm version Build Status codecov PRs Welcome Known Vulnerabilities npm download npm

中文文档

Git branch name validator.

Description

validate-branch-name can be used through command line directly. When using with Husky, you should make sure husky version >= v1.0.0.

Install

# local install
$ npm i validate-branch-name -D

# global install
$ npm i validate-branch-name -g

Usage

Use through command line

npx validate-branch-name

# test target branch name
npx validate-branch-name -t test/branch/name

# define regexp to test branch name
npx validate-branch-name -r regexp -t test/branch/name

# use -h for more usage detail
npx validate-branch-name -h

Use with husky

First way:

Configure hooks and pattern using package.json.

// {app_root}/package.json
{
  "husky": {
    "hooks": {
      "pre-commit": "npx validate-branch-name"
    }
  },
  "validate-branch-name": {
    "pattern": "^(master|develop){1}$|^(feature|fix|hotfix|release)\/.+$",
    "errorMsg": "your own error message"
  }
}

Second way:

Define pre-commit file under .husky direcotory.

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# valite branch name before commit

npx validate-branch-name 

We have set pattern and errorMsg by default, but you can still defined them as you like.

Default pattern: ^(master|develop){1}$|^(feature|fix|hotfix|release)/.+$

Example: feature/test/pattern-test would be passed.

Avaliable patterns:

  • ^(feature|fix|hotfix|release)/.+ - branch has to start with feature/, fix/, release/ or hotfix/
  • (feature|release|hotfix)/(JIRA-\d+) - it should look like feature/JIRA-1234
  • (feature|release|hotfix)/(JIRA-\d+/)?[a-z-]+ - it should look like feature/branch-name or include JIRA's code like feature/JIRA-1234/branch-name

  • custom patterns, visit regex.

You can also use .validate-branch-namerc, .validate-branch-namerc.json, .validate-branch-namerc.yaml, .validate-branch-namerc.yml, .validate-branch-namerc.js, .validate-branch-namerc.cjs, validate-branch-name.config.js or validate-branch-name.config.cjs file to define config.

Questions & Suggestions

Please open an issue here.

License

MIT

validate-branch-name's People

Contributors

jsonma avatar bertdeblock avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.