0.2.2 • Published 1 year ago

commit-context v0.2.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

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

proptypedescrptiondefault value
branchVarsarrayset the name of each item in your branch name (split by the separator)"type", "ticketId"
messageTemplatestringset the template for the commit messages (gets variables from branchVars)"{{type}}: {{ticketId}} {{message}}"
separatorstringseparator to split values from branch name"/"
useConventionalTypesbooleanconverts types from branch name to match conventional commitstrue
0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago