elgg-conventional-changelog
Advanced tools
Comparing version
19
index.js
@@ -24,6 +24,6 @@ | ||
if (err || !tag) return done('Failed to read git tags.\n'+err); | ||
getChangelogCommits(tag); | ||
writeChangelog(tag); | ||
}); | ||
function getChangelogCommits(latestTag) { | ||
function writeChangelog(latestTag) { | ||
options.from = options.from || latestTag; | ||
@@ -34,14 +34,17 @@ options.to = options.to || 'HEAD'; | ||
git.getCommits({ | ||
git.getLog({ | ||
from: options.from, | ||
to: options.to, | ||
}, function(err, commits) { | ||
}, function(err, gitLog) { | ||
if (err) return done('Failed to read git log.\n'+err); | ||
writeLog(commits); | ||
writeGitLog(gitLog); | ||
}); | ||
} | ||
function writeLog(commits) { | ||
options.log('Parsed %d commits.', commits.length); | ||
writer.writeLog(commits, options, function(err, changelog) { | ||
function writeGitLog(gitLog) { | ||
options.log('Parsed %d commits.', gitLog.commits.length); | ||
options.log('Parsed %d contributors.', gitLog.contributors.length); | ||
writer.writeLog(gitLog, options, function(err, changelog) { | ||
if (err) return done('Failed to write changelog.\n'+err); | ||
@@ -48,0 +51,0 @@ |
@@ -7,6 +7,24 @@ var extend = require('lodash.assign'); | ||
parseRawCommit: parseRawCommit, | ||
getCommits: getCommits, | ||
getLog: getLog, | ||
latestTag: latestTag | ||
}; | ||
function getLog(options, done) { | ||
var log = {}; | ||
getCommits(options, function(err, commits) { | ||
log.commits = commits; | ||
if (log.contributors) { | ||
done(null, log); | ||
} | ||
}); | ||
getContributors(options, function(err, contributors) { | ||
log.contributors = contributors; | ||
if (log.commits) { | ||
done(null, log); | ||
} | ||
}); | ||
} | ||
//Get latest tag, or if no tag first commit | ||
@@ -40,2 +58,42 @@ function latestTag(done) { | ||
function getContributors(options, done) { | ||
options = extend({ | ||
from: '', | ||
to: 'HEAD' | ||
}, options || {}); | ||
var cmd = 'git shortlog -sne %s --no-merges'; | ||
cmd = util.format( | ||
cmd, | ||
options.from ? options.from + '..' + options.to : '' | ||
); | ||
var CONTRIBUTOR_PATTERN = /\s+([0-9]+)\s+(.*)\s<(.*)>/; | ||
return es.child(cp.exec(cmd)) | ||
.pipe(es.split('\n')) | ||
.pipe(es.map(function(data, cb) { | ||
if (!data) { | ||
cb(); | ||
return; | ||
} | ||
var match = data.match(CONTRIBUTOR_PATTERN); | ||
if (match) { | ||
var contributor = { | ||
commits: match[1], | ||
name: match[2], | ||
email: match[3] | ||
}; | ||
cb(null, contributor); | ||
} else { | ||
cb("Couldn't match: " + data); | ||
} | ||
})) | ||
.pipe(es.writeArray(done)); | ||
} | ||
function getCommits(options, done) { | ||
@@ -42,0 +100,0 @@ options = extend({ |
@@ -27,3 +27,3 @@ var es = require('event-stream'); | ||
function writeLog(commits, options, done) { | ||
function writeLog(gitLog, options, done) { | ||
options = extend({ | ||
@@ -50,3 +50,3 @@ issueLink: getIssueLink.bind(null, options.repository), | ||
commits.forEach(function(commit) { | ||
gitLog.commits.forEach(function(commit) { | ||
var sectionName = options.types[commit.type]; | ||
@@ -78,2 +78,4 @@ var component = commit.component || EMPTY_COMPONENT; | ||
writer.contributors(gitLog.contributors); | ||
var orderedSections = {}, | ||
@@ -106,2 +108,13 @@ sectionName, type; | ||
}; | ||
this.contributors = function(contributors) { | ||
stream.write('#### Contributors\n'); | ||
contributors.forEach(function(contributor) { | ||
stream.write(util.format('\n* [%s](mailto:%s) (%s)', | ||
contributor.name, contributor.email, contributor.commits)); | ||
}); | ||
stream.write('\n'); | ||
}; | ||
@@ -108,0 +121,0 @@ this.section = function(title, section) { |
{ | ||
"name": "elgg-conventional-changelog", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Generate a markdown changelog from git commit metadata", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ conventional-changelog | ||
```sh | ||
$ npm install conventional-changelog | ||
$ npm install elgg-conventional-changelog | ||
``` | ||
@@ -11,3 +11,3 @@ | ||
View [CONVENTIONS.md](https://github.com/ajoslin/conventional-changelog/blob/master/CONVENTIONS.md) for a synposis of the conventions with commit examples. | ||
View [CONVENTIONS.md](https://github.com/Elgg/elgg-conventional-changelog/blob/master/CONVENTIONS.md) for a synposis of the conventions with commit examples. | ||
@@ -17,7 +17,5 @@ Adapted from code originally written by @vojtajina, from grunt-conventional-changelog. | ||
## Example output | ||
- https://github.com/ajoslin/conventional-changelog/blob/master/CHANGELOG.md | ||
- https://github.com/Elgg/elgg-conventional-changelog/blob/master/CHANGELOG.md | ||
- https://github.com/karma-runner/karma/blob/master/CHANGELOG.md | ||
Recommended usage: use in your workflow with [https://github.com/btford/grunt-conventional-changelog](grunt-conventional-changelog). | ||
## Documentation | ||
@@ -24,0 +22,0 @@ |
19896
8.78%482
13.41%72
-2.7%