3.2.3 • Published 4 years ago

parse-commit-message v3.2.3

Weekly downloads
192
License
Apache-2.0
Repository
github
Last release
4 years ago

parse-commit-message npm version github release License

An extensible parser for commit message that follows Conventional Commits v1 spec

XAXA code style CircleCI linux build CodeCov coverage status DavidDM dependency status Renovate App Status Make A Pull Request Semantically Released

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.

Conventional Commits PayPal Author Support Share Love Tweet NPM Downloads Weekly NPM Downloads Monthly NPM Downloads Total

Project is semantically & automatically released on CircleCI with new-release and its New Release GitHub App.

Highlights

  • Conventional Commits compliant
  • Fast and lightweight in few lines of code
  • Infinitely extensible through plugins, two built-in
  • Collecting mentions from commit message
  • Detection of breaking changes in commit

Table of Contents

Install

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

API

.parse

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 message
  • plugins {Array}: optional, a list of functions that are passed with commit object
  • returns {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'

.mappers

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.

  1. The 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'
  1. The mappers.mentions adds mentions property to the end result object
  • mentions is an array of objects like { handle: String, mention: String, index: Number }, see collect-mentions

Example

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' }

.plugins

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)

back to top

Related Projects

Some of these projects are used here or were inspiration for this one, others are just related. So, thanks for your existance!

back to top

Contributing

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

Contributors

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:

Users

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:

License

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.

4.0.0-canary.20

4 years ago

4.0.0-canary.11

4 years ago

4.0.0-canary.7

4 years ago

4.0.0-canary.6

4 years ago

4.0.0-canary.5

4 years ago

4.0.0-canary.4

4 years ago

4.0.0-canary.2

4 years ago

4.0.0-canary.3

4 years ago

4.0.0-canary.1

4 years ago

4.0.0-alpha.12

4 years ago

4.0.0-alpha.10

5 years ago

4.0.0-alpha.9

5 years ago

4.0.0-alpha.8

5 years ago

4.0.0-alpha.7

5 years ago

4.0.0-alpha.6

5 years ago

4.0.0-alpha.5

5 years ago

4.0.0-alpha.4

5 years ago

4.0.0-alpha.3

5 years ago

4.0.0-alpha.2

5 years ago

4.0.0-alpha.1

5 years ago

4.0.0-alpha.0

5 years ago

4.0.0-next.0

5 years ago

4.0.0-rc.3

5 years ago

4.0.0-rc.2

5 years ago

4.0.0-rc.1

5 years ago

4.1.3

5 years ago

4.1.2

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

3.2.4-alpha.209

5 years ago

4.0.0-alpha.207

5 years ago

4.0.0

5 years ago

3.3.0

5 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

3.0.0-next.rc11

5 years ago

3.0.0-next.rc10

6 years ago

3.0.0-next.rc9

6 years ago

3.0.0-next.rc8

6 years ago

3.0.0-next.rc7

6 years ago

3.0.0-next.rc6

6 years ago

3.0.0-next.rc4

6 years ago

3.0.0-next.rc3

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.4

6 years ago

2.0.6

6 years ago

2.0.5-testing-ts

6 years ago

2.0.4-testing-ts

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago