Skip to content

Commit

Permalink
Adding a script for writing change logs WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
MKHenson committed Apr 22, 2016
1 parent 27b42f4 commit 97691a6
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions git-logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var util = require('util')
var fs = require('fs')
var exec = require('child_process').exec;
var child;

var prevTag = "v0.0.22";
var nextTag = "v0.0.23";


// Executes the git log command
child = exec('git log '+ prevTag +'...'+ nextTag +' --pretty=format:"{ \\"author\\" : \\"%an\\", \\"commit\\" : \\"%h\\", \\"date\\" : \\"%ar\\", \\"title\\" : \\"%s\\" },"', function (error, stdout, stderr) {

var jsonStr = "{ \"data\" : [ " + stdout.toString();
jsonStr = jsonStr.substr(0, jsonStr.length - 1) + " ] } ";

try {
var json = JSON.parse(jsonStr);
json = json.data;

console.log("Parsed JSON" )

var changes = "";
for ( var i = 0, l = json.length; i < l; i++ )
changes += `* ${json[i].title} - see ${json[i].commit} \n`;

try {
fs.writeFile( 'changes.md', changes, function(err){
if (err)
throw err;
console.log('It\'s saved!');
});
}
catch(err){
console.log('Could not write file: ' + err);
}
}
catch(err){
console.log('Could not parse JSON: ' + err);
console.log('JSON STRING: ' + jsonStr);
}


if (error !== null) {
console.log('exec error: ' + error);
}
});

0 comments on commit 97691a6

Please sign in to comment.