#!/usr/bin/env node
/*jshint shelljs:true, lastsemic:true, -W101*/

"use strict";

var version = require("../package.json").version;
require("shelljs/make");

exec("git log --format='%H|%h|%an|%s' " + version + "..HEAD", { silent: true }, function (code, output) {
  if (code !== 0)
    return void console.log("git log return code is non-zero");

  var commits = output.split("\n")
    .filter(function (cmt) { return cmt.trim() !== ""; })
    .map(function (cmt) { return cmt.split("|"); });

  var markdown = "";
  var authors = {};

  commits.forEach(function (cmt) {
    if (cmt[3].indexOf("Merge") === 0) {
      return;
    }
    markdown += "| https://github.com/jshint/jshint/commit/" + cmt[0] + " | " + cmt[3] + " |\n";
  });

  echo("<!-- auto-generated -->");
  echo("| Commit | Message/Description |");
  echo("| ------ | ------------------- |");
  echo(markdown);
});
