<commit_before>var _ = require('lodash');
var async = require('async');
var fs = require('fs');
var http = require('http');
var watch = require('watch');
var sass = require("node-sass");
var path = require('path');
var green = '\u001b[42m \u001b[0m';
var red = '\u001b[41m \u001b[0m';
var exec = require('child_process').exec;
var figlet = require('figlet');
var moment = require('moment');
var utils;

module.exports = {
	name:'summary',
	description:'Outputs a summary of activity on the repos',
	example:'bosco summary -r <repoPattern>',
	cmd:cmd
}

function cmd(bosco, args, next) {

	var repoPattern = bosco.options.repo;
	var repoRegex = new RegExp(repoPattern);

	var since = args['since'];

	if (!since) {
		bosco.warn('Using --since argument as last 24 hours since no option was passed. You may be experiencing https://github.com/TSLEducation/bosco/issues/10');
		since = moment().subtract(1, 'day').format();
	}

	var repos = bosco.config.get('github:repos');
	if(!repos) return bosco.error("You are repo-less :( You need to initialise bosco first, try 'bosco clone'.");

	var activityForRepos = function(cb) {

		async.mapLimit(repos, bosco.options.cpus, function(repo, repoCb) {

		  if(!repo.match(repoRegex)) return repoCb();

		  var repoPath = bosco.getRepoPath(repo);
		  repoActivity(bosco, repoPath, repo, since, repoCb);

		}, function(err) {
			cb();
		});

	}

	activityForRepos(function() {
		bosco.log("Complete");

		if (next) next();
	});

}

function repoActivity(bosco, orgPath, repo, since, next) {

  if(!bosco.exists([orgPath,".git"].join("/"))) {
  	bosco.warn("Doesn't seem to be a git repo: "+ orgPath.blue);
  	return next();
  }

  firstRepoCommit(bosco, orgPath, repo, function(err, firstCommit){
  	if (err) return next(err);

  	exec('git log --pretty=format:"%H - %an, %ar : %s" --no-merges --since=' + since, {
	  	cwd: orgPath
		}, function(err, stdout, stderr) {
			if(err) {
				bosco.error(orgPath.blue + " >> " + stderr);
			} else {
				if (!stdout.length) return next();
				
				figlet(repo, function(err, data) {
					if (!err) bosco.log(data);
					else bosco.log(repo);

					bosco.log('\n' + stdout);
					if (_.contains(stdout, '\n' + firstCommit)) bosco.log('Repo was created'.green);
				});
			}
			
			next(err);
		});
  });
}

function firstRepoCommit(bosco, orgPath, repo, next) {
	exec('git rev-list --max-parents=0 HEAD', {
	  cwd: orgPath
	}, function(err, stdout, stderr) {
		if(err) {
			bosco.error(orgPath.blue + " >> " + stderr);
			return next(err);
		}

		return next(null, stdout.replace(/(\r\n|\n|\r)/gm,""));
	});
}
<commit_msg>Added a bit more sauce to the example<commit_after>var _ = require('lodash');
var async = require('async');
var fs = require('fs');
var http = require('http');
var watch = require('watch');
var sass = require("node-sass");
var path = require('path');
var green = '\u001b[42m \u001b[0m';
var red = '\u001b[41m \u001b[0m';
var exec = require('child_process').exec;
var figlet = require('figlet');
var moment = require('moment');
var utils;

module.exports = {
	name:'summary',
	description:'Outputs a summary of activity on the repos',
	example:'bosco summary -r <repoPattern> --since 2014-09-22T23:36:26-07:00',
	cmd:cmd
}

function cmd(bosco, args, next) {

	var repoPattern = bosco.options.repo;
	var repoRegex = new RegExp(repoPattern);

	var since = args['since'];

	if (!since) {
		bosco.warn('Using --since argument as last 24 hours since no option was passed. You may be experiencing https://github.com/TSLEducation/bosco/issues/10');
		since = moment().subtract(1, 'day').format();
	}

	var repos = bosco.config.get('github:repos');
	if(!repos) return bosco.error("You are repo-less :( You need to initialise bosco first, try 'bosco clone'.");

	var activityForRepos = function(cb) {

		async.mapLimit(repos, bosco.options.cpus, function(repo, repoCb) {

		  if(!repo.match(repoRegex)) return repoCb();

		  var repoPath = bosco.getRepoPath(repo);
		  repoActivity(bosco, repoPath, repo, since, repoCb);

		}, function(err) {
			cb();
		});

	}

	activityForRepos(function() {
		bosco.log("Complete");

		if (next) next();
	});

}

function repoActivity(bosco, orgPath, repo, since, next) {

  if(!bosco.exists([orgPath,".git"].join("/"))) {
  	bosco.warn("Doesn't seem to be a git repo: "+ orgPath.blue);
  	return next();
  }

  firstRepoCommit(bosco, orgPath, repo, function(err, firstCommit){
  	if (err) return next(err);

  	exec('git log --pretty=format:"%H - %an, %ar : %s" --no-merges --since=' + since, {
	  	cwd: orgPath
		}, function(err, stdout, stderr) {
			if(err) {
				bosco.error(orgPath.blue + " >> " + stderr);
			} else {
				if (!stdout.length) return next();
				
				figlet(repo, function(err, data) {
					if (!err) bosco.log(data);
					else bosco.log(repo);

					bosco.log('\n' + stdout);
					if (_.contains(stdout, '\n' + firstCommit)) bosco.log('Repo was created'.green);
				});
			}
			
			next(err);
		});
  });
}

function firstRepoCommit(bosco, orgPath, repo, next) {
	exec('git rev-list --max-parents=0 HEAD', {
	  cwd: orgPath
	}, function(err, stdout, stderr) {
		if(err) {
			bosco.error(orgPath.blue + " >> " + stderr);
			return next(err);
		}

		return next(null, stdout.replace(/(\r\n|\n|\r)/gm,""));
	});
}

{'fraction_non_alphanumeric': 0.1832699619771863, 'fraction_numerical': 0.012547528517110267, 'mean_word_length': 3.8399264029438824, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '311194', 'n_tokens_mistral': 2127, 'n_tokens_neox': 1886, 'n_words': 449}