Skip to content

Commit

Permalink
Gruntfile: new changelog task
Browse files Browse the repository at this point in the history
- All changelogs will omit merge commits and the version release commit itself.
- `grunt changelog`: This will build a changelog of commits from the latest release tag to the previous release tag.
- `grunt changelog:old--new`: This will build a changelog of commits from the new tag to old tag.

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Apr 5, 2016
1 parent 183d173 commit 28296f8
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// System Objects
var cp = require('child_process');

// Third Party Dependencies
var tags = require('common-tags');

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
nodeunit: {
tests: [
Expand Down Expand Up @@ -103,4 +108,43 @@ module.exports = function(grunt) {

grunt.task.run('nodeunit');
});


grunt.registerTask('changelog', '`changelog:0.0.0--0.0.2` or `changelog`', function(range) {
var done = this.async();

if (!range) {
// grunt changelog
range = cp.execSync('git tag --sort version:refname').toString().split('\n');
} else {
// grunt changelog:previous--present
range = range.split('--');
}

range = range.filter(Boolean).reverse();

cp.exec(`git log --format='|%h|%s|' ${range[1]}..${range[0]}`, (error, result) => {
if (error) {
console.log(error.message);
return;
}

var rows = result.split('\n').filter(commit => {
return !commit.includes('|Merge ') && !commit.includes(range[0]);
}).join('\n');

// Extra whitespace above and below makes it easier to quickly copy/paste from terminal
grunt.log.writeln(`\n\n${changelog(rows)}\n\n`);

done();
});
});
};

function changelog(rows) {
return tags.stripIndent`
| Commit | Message/Description |
| ------ | ------------------- |
${rows}
`;
}

0 comments on commit 28296f8

Please sign in to comment.