npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dwtechs/gitbranchvalidator

v2.1.0

Published

Git branch name validator for clean workflow and better readability

Downloads

349

Readme

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

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.

You can validate commit messages as well with GitCommitValidator

Installation

This library is written in Node.js. You must install Node.js and npm in order to run it.

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

This library is meant to be used in "pre-commit", "commit-msg" or/and "pre-push" Git hook. Thus it is not bound to Javasrcipt applications only and can be used by any git repository.

You can learn more about Git hooks and how ti cutomize them in the Git Manual

Because hooks aren’t transferred with a clone of a project, you must distribute these scripts some other way and then have your users copy them to their .git/hooks directory and make them executable. You can distribute these hooks within the project or in a separate project, but Git will not set them up automatically for you.

Command line

$ 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}$"

You can use several patterns if needed :

$ 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 :

$ 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.

$ 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.

Git hooks are not run in an interactive environment. So this option will fail if used in a Git hook.

Help

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

$ gbvalidator --help

Workflow integration

Validate branch name on pre-push hook by adding the following code in the .git/hooks/pre-push file :

gbvalidator

Or with tools like Husky In the package.json file :

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

You can do it with any other tool, or work on Git hooks directly.

You can use GitCommitValidator in the "commit-msg" hook as well :

gbvalidator && gcvalidator -src "$1"

You can find git hooks examples in the ./hooks/ folder. To install them just paste them in the .git/hooks/ folder of your repositories.

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. Does not work if used in Git hooks | | --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 contributor.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 |