Coder Social home page Coder Social logo

commit-context's Introduction

commit-context

Gives context to commit messages from branch name

  • Supports Git flow branch naming conventions
  • Builds commit message based on conventional commits

How it works?

After properly configured with git hooks, your commit messages will be concatenated with informations based in your branch name. The default configuration is set to expect a branch naming with type/ticket (example: feature/ID-1249), and have the following template message: {{type}}: [{{ticket}}] {{message}}.

So, from this branch, when you commit with the message:

"My awesome commits"

The final commit message will be:

"feat: [ID-1249] My awesome commits"

Note that "feature" was converted to "feat" to match the conventional commits specifications.

You can customize these options to follow any pattern.

Setup with Husky

  1. Install commit-context and husky
npm install husky commit-context
  1. Init husky
npx husky-init && npm install 

Note: This step will create a pre-commit git hook. You can remove it from .husky/pre-commit.

  1. Add a commit-msg git hook
npx husky add .husky/commit-msg 'npx commit-context $1' 

Customization

You can add custom configurations in your package.json:

{
  "commitContext": {
     "branchVars": ["type", "ticketId"],
     "messageTemplate": "{{type}}: [{{ticketId}}] {{message}}",
     "separator": "/",
     "useConventionalTypes": true,
  }
}

Options

prop type descrption default value
branchVars array set the name of each item in your branch name (split by the separator) ["type", "ticketId"]
messageTemplate string set the template for the commit messages (gets variables from branchVars) "{{type}}: [{{ticketId}}] {{message}}"
separator string separator to split values from branch name "/"
useConventionalTypes boolean converts types from branch name to match conventional commits true

commit-context's People

Contributors

raelbr avatar

Watchers

 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.