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

gitlog-semver

v0.2.3

Published

Identify the required Semantic Versioning release type based on commit messages.

Downloads

12

Readme

gitlog-semver

Identifies the required Semantic Versioning release type based on commit messages.

Installation

$ npm install gitlog-semver

Quick start

First you need to integrate gitlog-semver into your application.

const gitlogSemver = require('gitlog-semver');

Type of next release

Then you can use the function to retrieve the type of the next release.

gitlogSemver((err, releaseType) => {
  if (err) {
    return console.log('Something went wrong...');
  }

  console.log(releaseType); // => 'major', 'minor' or 'patch'
});

In order to determine the type of the next release, messages from commits newer than the most recent tag are filtered. Only commit messages that start with a label for the corresponding release type, delimited by at least one space from the rest of the message, are taken into account. Valid labels are major:, minor:, patch:. The following samples demonstrate the rules:

| Commit message | Matching release type | |------------------|---------------------------------------| | patch: Foobar | patch | | patch:Foobar | n/a (missing space) | | patch: Foobar | patch (multiple spaces are allowed) | | Minor: Foobar | minor (match is case insensitive) | | Major: All new | major | | Mayor: All new | n/a (typo in label) | | Giant: All new | n/a (unknown label) |

Custom filter

If you want to use other labels, you can create a filter object. For each release type (major, minor, patch) define an array of labels you want to associate with.

const filter = {
  major: [ 'major:' ],
  minor: [ 'minor:', 'new:' ],
  patch: [ 'patch:', 'fix:' ]
}

To use the filter, add the object as the first parameter of the function.

gitlogSemver(filter, (err, releaseType) => {
  // ...
});

List of commit messages

The callback provides the commit messages that match the filter, too.

gitlogSemver((err, releaseType, releases) => {
  if (err) {
    return console.log('Something went wrong...');
  }

  console.log(releases); // =>
    // [{
    //   major: [ 'Breaking changes made' ],
    //   minor: [ 'Some new minor features'],
    //   patch: []
    // }]
});

The releases array contains exactly one object with an array with the commit messages for each release type. Only the first line of the commit message will be included and the preceding label is already removed from the message text.

Release history

If you want to also get the filtered commit messages for already released versions, set the property limit of the filter object. By setting it to -1, the whole commit history will be filtered.

const filter = {
  limit: -1,
  major: 'major:',
  minor: 'minor:',
  patch: 'patch:'  
}

gitlogSemver(filter, (err, releaseType, releases) => {
  if (err) {
    return console.log('Something went wrong...');
  }

  console.log(releases); // =>
    // [{
    //   version: '1.0.0',
    //   date: '2016-09-17',
    //   messages: {
    //     major: [ 'Initial release' ],
    //     minor: [],
    //     patch: []
    //   }
    // }, {
    //   version: '1.1.0',
    //   date: '2016-09-18',
    //   messages: {
    //     major: [],
    //     minor: [ 'Some bugs fixed' ],
    //     patch: []
    //   }
    // }, {
    //   messages: {
    //     major: [ 'Breaking changes made' ],
    //     minor: [ 'Some new minor features'],
    //     patch: []
    //   }
    // }]
});

The returned releases is an array of objects. An object contains the version of a release (name of the tag) and its creation date. The messages property lists all matching commit messages.

The array's last object contains only a messages property with the messages of all commits that are not yet released. It is equal to the only object returned if limit is not set or set to 1 (see section above).

By setting the limit to a positive number, you can define the maximum length of the releases array.

Of course, the returned releaseType still provides the type of the next release.