git-commit-markdown

1.0.1 • Public • Published

Git Commit Markdown

A NodeJS package wich reads from the git history to render a parsed JSON or write a Markdown file (Changelog). It is based on the Karma Git Commit Message Convention, so make sure to have your commits following that convention.

Package Version NodeJS Version

Usage

First install the package with npm as a developement dependency:

npm install -D git-commit-markdown

Then require the package and set up the options:

var gitCMD = require('git-commit-markdown');
 
var options = {
    // The link to the remote git repository (currently only github and bitbucket)
    remote: 'https://github.com/EastolfiWebDev/GitCommitMarkdown',
    // Fields to extract from the commit
    fields: ['shortHash', 'subject', 'commitDate'],
    // TRUE to generate a Markdown output, instead a JSON
    //markdown: true,
    // TRUE to generate a file with the markdown or a string specifyng the file path
    file: path.join(__dirname, '../CHANGELOG.md'),
    // TRUE to ignore commits of doc, test,...
    ignoreIrrelevants: true,
    // To generate the markdown with a "priority" sorting: features, fixes,...
    sort: true
};

And finally, use it asynchronously (or not):

// If no callback is passed, then it will be executed synchronously, 
// returning the result
gitCMD(options, function(err, result) {
    if (err) throw err;
    
    console.log(result.data);
});

Having the following set of commits (only relevants commits):

$ git log --grep "feat(\|feat:\|fix(\|fix:\|refactor(\|refactor:"
commit 28fb6bed9495cc749f62768c21c8f006ffb09ef9
Author: eastolfi <astolfi_wotc@hotmail.com>
Date:   Wed Oct 5 11:12:05 2016 +0000

    fix: Fixe the markdown generation when several commits

commit 32bc36b3c461dc029cc166e4e36a55750d1656fc
Author: eastolfi <astolfi_wotc@hotmail.com>
Date:   Wed Oct 5 11:01:29 2016 +0000

    feat(module): Write the markdown to a file

commit f9a30830f6bd5cfc35791d14c0440e43662fc490
Author: eastolfi <astolfi_wotc@hotmail.com>
Date:   Tue Oct 4 14:57:42 2016 +0000

    feat(module): Create the module

If no options.markdown or options.file is passed, it will return a JSON with the commits formated:

{
    "fix":[{
        "shortHash":"28fb6be",
        "subject":"fix: Fixe the markdown generation when several commits",
        "commitDate":"Wed Oct 5 11:12:05 2016 +0000",
        "type":"fix",
        "subjectMessage":"Fixe the markdown generation when several commits"
    }],
    "feat":[{
        "shortHash":"32bc36b",
        "subject":"feat(module): Write the markdown to a file",
        "commitDate":"Wed Oct 5 11:01:29 2016 +0000",
        "type":"feat",
        "scope":"module",
        "subjectMessage":"Write the markdown to a file"
    }, {
        "shortHash":"f9a3083",
        "subject":"feat(module): Create the module",
        "commitDate":"Tue Oct 4 14:57:42 2016 +0000",
        "type":"feat",
        "scope":"module",
        "subjectMessage":"Create the module"
    }]
}

If options.markdown: true is passed, it will return a markdown string:

#### New Features
* **module**: Write the markdown to a file ([32bc36b](https://github.com/EastolfiWebDev/GitCommitMarkdown/commit/32bc36b))
* **module**: Create the module ([f9a3083](https://github.com/EastolfiWebDev/GitCommitMarkdown/commit/f9a3083))
 
#### Bug Fixes
* Fixe the markdown generation when several commits ([28fb6be](https://github.com/EastolfiWebDev/GitCommitMarkdown/commit/28fb6be))
-----
*Changelog generated at Wed, 05 Oct 2016 11:58:24 GMT by [GitCommitMarkdown](https://github.com/EastolfiWebDev/GitCommitMarkdown)*

And if options.file: [path] is passed (or options.file: true for the default path), it will write to a CHANGELOG.md file the markdown, returning a success object:

New Features

  • module: Write the markdown to a file (32bc36b)
  • module: Create the module (f9a3083)

Bug Fixes

  • Fixe the markdown generation when several commits (28fb6be)

Changelog generated at Wed, 05 Oct 2016 11:58:24 GMT by GitCommitMarkdown

Package Sidebar

Install

npm i git-commit-markdown

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • eastolfi