Code coverage report for ggit/src/commits.js

Statements: 58.82% (10 / 17)      Branches: 100% (0 / 0)      Functions: 0% (0 / 2)      Lines: 58.82% (10 / 17)      Ignored: none     

All files » ggit/src/ » commits.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 521 1 1 1 1 1 1                       1                                       1             1            
require('lazy-ass');
var check = require('check-more-types');
var getOneLineLog = require('./get-one-line-log');
la(check.fn(getOneLineLog), 'missing one line log function');
var fs = require('fs');
var folders = require('chdir-promise');
var R = require('ramda');
 
/*
  // returns commits from given repo folder
  // latest commits first
 
  // get last 2 commits and print them
  commits.all(gitRepoFolder)
    .then(R.take(2))
    .then(console.table)
    .done();
*/
function commits(gitRepoRootFolder) {
  la(check.unemptyString(gitRepoRootFolder), 'missing git repo folder');
  la(fs.existsSync(gitRepoRootFolder), 'cannot find folder', gitRepoRootFolder);
 
  return folders.to(gitRepoRootFolder)
    .then(getOneLineLog)
    .tap(folders.back);
}
 
/*
  zips list of commits into object where keys = ids, values = messages
 
  For example to get an object with 2 commit ids as keys
 
  commits.all(gitRepoFolder)
    .then(R.take(2))
    .then(commits.byId)
    .then(console.log)
    .done();
*/
function byId(commits) {
  var ids = R.map(R.prop('id'))(commits);
  var messages = R.map(R.prop('message'))(commits);
  var commitInfo = R.zipObj(ids, messages);
  return commitInfo;
}
 
module.exports = {
  all: commits,
  byId: check.defend(byId,
    check.array, 'need array of commit info objects to zip')
};