
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
parse-commit-message
Advanced tools
An extensible parser for commit message that follows Conventional Commits v1 spec
An extensible parser for commit message that follows Conventional Commits v1 spec
If you have any how-to kind of questions, please read the Contributing Guide and Code of Conduct documents.
For bugs reports and feature requests, please create an issue or ping @tunnckoCore at Twitter.
Project is semantically & automatically released on CircleCI with new-release and its New Release GitHub App.
This project requires Node.js ^6.9.0 || ^8.9.0 || ^10.6.0. Install it using yarn or npm.
We highly recommend to use Yarn when you think to contribute to this project.
$ yarn add parse-commit-message
Parses given commitMessage
to an object which can be populated with more things if needed, through plugins
.
Plugins are functions like (commit) => {}
and can return object with additional
properties that will be included in the returned "commit" object.
There are two built-in plugins - increment
and mentions
which are exposed
as array at exposed plugins
named export.
The commit.header
has also a toString()
method concatinates
the header.scope
, header.type
and header.subject
properties.
Params
commitMessage
{string}: required, a whole commit messageplugins
{Array}: optional, a list of functions that are passed with commit
objectreturns
{Object}: with { header: { type, scope, subject }, body, footer }
Example
import { parse } from 'parse-commit-message';
const commit = parse(`fix(crit): some huge change
Some awesome
body here.
resolves #333
`);
console.log(commit)
// => {
// header: {
// type: 'fix',
// scope: 'crit',
// subject: 'some huge change'
// toString: [Function: toString],
// },
// body: 'Some awesome\nbody here.',
// footer: 'resolves #333',
// }
console.log(commit.header.toString())
// => 'fix(crit): some huge change'
// or adding one more plugin to the builtin ones
const customPlugin = (commit) => {
if (commit.header.type === 'fix') {
return { fixed: 'yeah' };
}
return null;
};
const commit = parse('fix(wat): foo bar baz', plugins.concat(customPlugin));
console.log(commit.isBreaking) // => false
console.log(commit.increment) // => 'patch'
console.log(commit.header); // => { type: 'fix', subject: 'wat', subject: 'foo bar baz' }
console.log(commit.fixed); // => 'yeah'
An object with all mappers, such as plugins
array, but named. This objects is like { increment, mentions }
where they are plugins that can be passed as second argument to .parse
.
mappers.increment
adds isBreaking
and increment
properties
to the final returned "commit" object:isBreaking
is Boolean
that indicates if commit is containing BREAKING CHANGE:
or
the type
of the commit is break
, breaking
or major
increment
is a String
that can be 'patch'
, 'minor'
or 'major'
mappers.mentions
adds mentions
property to the end result objectmentions
is an array of objects like { handle: String, mention: String, index: Number }
,
see collect-mentionsExample
import { parse, mappers } from 'parse-commit-message';
const commit = parse('fix: BREAKING CHANGE: huge refactor', mappers.increment);
console.log(commit);
// => {
// header: { type: 'fix', scope: undefined, subject: 'BREAKING CHANGE: huge refactor' },
// body: null,
// footer: null,
// isBreaking: true,
// increment: 'major'
// }
const str = `feat(whoa): thanks to @foobie for this
awesome @zazzy and @quxie make this release to happen
resolves #123
`
const cmt = parse(str, mappers.mentions);
console.log(cmt.header.type); // => 'feat'
console.log(cmt.header.scope); // => 'whoa'
console.log(cmt.header.subject); // => 'hanks to @foobie for this'
console.log(cmt.body); // => 'awesome @zazzy and @quxie make this release to happen'
console.log(cmt.footer); // => 'resolves #123'
console.log(cmt.mentions[0]); // => { handle: '@foobie', mention: 'foobie' }
console.log(cmt.mentions[1]); // => { handle: '@zazzy', mention: 'zazzy' }
console.log(cmt.mentions[2]); // => { handle: '@quxie', mention: 'quxie' }
A list of all plugins, such as mappers
but no names, so can be passed directly to the .parse
as second argument.
Example
import { parse, plugins } from 'parse-commit-message';
const commit = parse('fix: okey', plugins)
console.log(commit)
Some of these projects are used here or were inspiration for this one, others are just related. So, thanks for your existance!
mentions-regex
package | homepagegit commit
replacement. Conventional Commits compliant. | homepagePlease read the Contributing Guide and Code of Conduct documents for advices.
For bugs reports and feature requests, please create an issue or ping @tunnckoCore at Twitter.
Thanks to the hard work of these wonderful people this project is alive and it also follows the all-contributors specification.
Pull requests, stars and all kind of contributions are always welcome. :stars:
You can see who uses parse-commit-message
in the USERS.md file. Please feel free adding this file if it not exists.
If you or your organization are using this project, consider adding yourself to the list of users.
Thank You! :heart:
Copyright (c) 2017-present, Charlike Mike Reagent <olsten.larck@gmail.com>
.
Released under the Apache-2.0 License.
This file was generated by verb-generate-readme, v0.7.0, on July 25, 2018.
FAQs
Extensible parser for git commit messages following Conventional Commits Specification
The npm package parse-commit-message receives a total of 1,309 weekly downloads. As such, parse-commit-message popularity was classified as popular.
We found that parse-commit-message demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.