Last active
August 29, 2015 14:17
-
-
Save dancrumb/1b437d2d1da8b88ea62b to your computer and use it in GitHub Desktop.
node-git #497 demo file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var chalk = require('chalk'); | |
var error = chalk.red.bold; | |
var warn = chalk.yellow.bold; | |
var info = chalk.blue.bold; | |
var debug = chalk.gray.bold; | |
var LOG_ERROR = 0; | |
var LOG_WARN = 1; | |
var LOG_INFO = 2; | |
var LOG_DEBUG = 3; | |
var LOG_TRACE = 4; | |
var logLevel = LOG_INFO; | |
module.exports = { | |
getLogLevel: function() { | |
'use strict'; | |
return logLevel; | |
}, | |
setLogLevel: function(newLevel) { | |
'use strict'; | |
if(newLevel > LOG_TRACE) { | |
newLevel = LOG_TRACE; | |
} | |
if(newLevel < LOG_ERROR) { | |
newLevel = LOG_ERROR; | |
} | |
logLevel = newLevel; | |
}, | |
error: function() { | |
'use strict'; | |
if(logLevel < LOG_ERROR) { | |
return; | |
} | |
var args = [].slice.apply(arguments); | |
args[0] = chalk.bold('[' + error('ERROR') + ']: ') + args[0]; | |
console.error.apply(console, args); | |
}, | |
warn: function() { | |
'use strict'; | |
if(logLevel < LOG_WARN) { | |
return; | |
} | |
var args = [].slice.apply(arguments); | |
args[0] = chalk.bold('[' + warn('WARN') + ']: ') + args[0]; | |
console.warn.apply(console, args); | |
}, | |
info: function() { | |
'use strict'; | |
if(logLevel < LOG_INFO) { | |
return; | |
} | |
var args = [].slice.apply(arguments); | |
args[0] = chalk.bold('[' + info('INFO') + ']: ') + args[0]; | |
console.log.apply(console, args); | |
}, | |
debug: function() { | |
'use strict'; | |
if(logLevel < LOG_DEBUG) { | |
return; | |
} | |
var args = [].slice.apply(arguments); | |
args[0] = chalk.bold('[' + debug('DEBUG') + ']: ') + args[0]; | |
console.log.apply(console, args); | |
}, | |
trace: function() { | |
'use strict'; | |
if(logLevel < LOG_TRACE) { | |
return; | |
} | |
var args = [].slice.apply(arguments); | |
args[0] = chalk.bold('[' + debug('TRACE') + ']: ') + args[0]; | |
console.log.apply(console, args); | |
}, | |
chalk: chalk | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var NodeGit = require('nodegit'); | |
var logger = require('./lib/utilities/logger.js'); | |
logger.setLogLevel(3); | |
// create tmp folder | |
var deployFolderName = 'test'; | |
// clone into tmp folder | |
var remoteRepo = 'ssh://[email protected]:2121/ps/pepper-demo-site.git'; | |
logger.debug('Remote stash repo: %s', remoteRepo); | |
logger.debug('Cloning into %s', path.join('_deployments',deployFolderName)); | |
var cloneOptions = {}; | |
cloneOptions.remoteCallbacks = { | |
credentials: function(url, userName) { | |
return NodeGit.Cred.sshKeyFromAgent(userName); | |
}, | |
transferProgress: function(info) { | |
logger.trace('progress %s of %s', info.receivedObjects(), info.totalObjects()); | |
} | |
}; | |
logger.info('Cloning snapshot repo'); | |
var getMostRecentCommit = function(repository) { | |
return repository.getBranchCommit('master'); | |
}; | |
var getCommitMessage = function(commit) { | |
return commit.message(); | |
}; | |
NodeGit.Clone(remoteRepo, path.join('_deployments',deployFolderName), cloneOptions ) | |
.then(getMostRecentCommit, function() { logger.error('error %o', arguments);}) | |
.then(getCommitMessage, function() { logger.error('error %o', arguments);}) | |
.then(function(message) { | |
return logger.info(message); | |
}, function() { logger.error('error %o', arguments);}) | |
.done(function() { | |
logger.info('Donezo'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment