JSPM

@dwtechs/gitbranchvalidator

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 198
  • Score
    100M100P100Q95631F
  • License MIT

Git branch name validator for clean workflow and better readability

Package Exports

  • @dwtechs/gitbranchvalidator
  • @dwtechs/gitbranchvalidator/lib/main.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@dwtechs/gitbranchvalidator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

License: MIT npm version last version release date Jest:coverage minified size

Synopsis

GitBranchValidator is an open source git branch name validator library.

Motivation

The goal of this library is to provide an easy way to check if the current branch name is valid before pushing it to the remote.

It's a good way to help developers keep their branch names clean on the repository and facilitate the workflow of a project with strict naming rules.

The default pattern follows the principles described here.

You can also set your own rules using custom patterns.

Installation

npm

$ npm i @dwtechs/gitbranchvalidator -g

Yarn

$ yarn add @dwtechs/gitbranchvalidator -g

Locally

Alternatively, if you are planning to use GitBranchValidator within your npm package only or with npx you can install it as a devDependency in your project.

$ npm i @dwtechs/gitbranchvalidator --save-dev
$ yarn add @dwtechs/gitbranchvalidator --dev

Usage

Command line

$ cd <git-project>
$ gbvalidator

Alternatively if you did not install GitBranchValidator globally you can use npx.

$ npx gbvalidator

Or as an npm script in your package.json.

{
  "scripts": {
    "commit": "gbvalidator"
  }
}

Patterns

  • Default : ^(feat|fix|test|doc)/[A-Z0-9-#]{2,25}/([a-z0-9_-.]){3,40}$
  • Release : ^release/v[a-z0-9+-.]{3,25}$

The patterns follow the principles described here.

You can use your own custom patterns by adding an optional regexp :

$ cd <git-project>
$ gbvalidator --patterns "^(feat|fix)\/([a-z0-9_#-\.\/]){3,50}$"

If you use this option for a npm command in package.json, you may need to properly escape your regex in order to get a valid JSON file.

You can use several patterns if needed :

$ cd <git-project>
$ gbvalidator --patterns "pattern1" "pattern2" "pattern3"

If one of them is valid, the branch name will be valid.

Message

You can customize the end of the error message :

$ cd <git-project>
$ gbvalidator --message "You can learn more about branch name conventions of this project on https://dwtechs.github.io/efficient-git/branch/"

Prompt

If the branch name is not valid, the process will be blocked by default. You can use the option "--continue" to prompt the user instead.

$ cd <git-project>
$ gbvalidator --continue

In this case the user will be prompted about the invalid branch. He will be able to keep going if he choose so.

Help

You can access the documentation by passing the "help" parameter :

$ cd <git-project>
$ gbvalidator --help

Workflow integration

Validate branch name on pre-commit with Husky :

$ npm install husky --save-dev

In the package.json file :

{
  "husky": {
    "hooks": {
      "pre-commit": "gbvalidator"
    }
  }
}

You can do it with any other tool, or work on Git pre commit hook directly.

options

Option Alias Type description
--patterns -p string Use a custom regex. You can send multiple patterns
--message -m string Add a custom message at the end of the error message
--continue -c string Prompt the user if the branch name is not valid, instead of stopping the process
--help -h boolean Learn about library usage

Contributors

GitBranchValidator is still in development and I would be glad to get all the help you can provide for this project. To contribute please read NOTICE.md for detailed installation guide.

License

MIT

Stack

Purpose Choice Motivation
repository Github hosting for software development version control using Git
package manager npm default node.js package manager
unit testing Jest delightful testing with a focus on simplicity

Dependencies

Name version
@dwtechs/checkhard 2.19.0
command-line-args 5.2.1
command-line-usage 6.1.3
current-git-branch 1.1.0
prompts 2.4.2