Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from andrerod/github
Browse files Browse the repository at this point in the history
Github
  • Loading branch information
André Rodrigues committed Oct 23, 2012
2 parents 32e5ad7 + 1f9cd6f commit 0142328
Show file tree
Hide file tree
Showing 18 changed files with 1,854 additions and 416 deletions.
96 changes: 50 additions & 46 deletions lib/cli/cli.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -344,66 +344,71 @@ commander.Command.prototype.whiteListPowershell = function (whitelist) {
return this; return this;
}; };


// Allow cli.password to accept empty passwords commander.Command.prototype.passwordOnce = function (currentStr, mask, callback) {
commander.Command.prototype.password = function (str, mask, fn) { var self = this;
var buf = '';

// default mask // default mask
if ('function' === typeof mask) { if ('function' === typeof mask) {
fn = mask; callback = mask;
mask = ''; mask = '';
} }


var getPassword = function (currentStr, callback) { if (!process.stdin.setRawMode) {
var self = this; process.stdin.setRawMode = tty.setRawMode;
var buf = ''; }


if (!process.stdin.setRawMode) { process.stdin.resume();
process.stdin.setRawMode = tty.setRawMode; process.stdin.setRawMode(true);
fs.writeSync(istty1 ? 1 : 2, currentStr);
process.stdin.on('data', function(char) {
// Exit on Ctrl+C keypress
char = char.toString();
if (char === '\003') {
console.log('%s', buf);
process.exit();
} }


process.stdin.resume(); // Return password in the buffer on enter key press
process.stdin.setRawMode(true); if (char === '\015') {
fs.writeSync(istty1 ? 1 : 2, currentStr); process.stdin.removeAllListeners('data');
process.stdin.on('data', function(char) { process.stdout.write('\n');
// Exit on Ctrl+C keypress process.stdin.setRawMode(false);
char = char.toString(); process.stdin.pause();
if (char === '\003') {
console.log('%s', buf);
process.exit();
}


// Return password in the buffer on enter key press return callback(buf);
if (char === '\015') { }
process.stdin.removeAllListeners('data');
process.stdout.write('\n'); // Backspace handling
process.stdin.setRawMode(false); // Windows usually sends '\b' (^H) while Linux sends '\x7f'
callback(buf); if (char === '\b' || char === '\177') {
return; if (buf) {
} buf = buf.slice(0, -1);

for (var j = 0; j < mask.length; ++j) {
// Backspace handling process.stdout.write('\b \b'); // space the last char out
// Windows usually sends '\b' (^H) while Linux sends '\x7f'
if (char === '\b' || char === '\177') {
if (buf) {
buf = buf.slice(0, -1);
for (var j = 0; j < mask.length; ++j) {
process.stdout.write('\b \b'); // space the last char out
}
} }
return;
}
char = char.split('\015')[0]; // only use the first line if many (for paste)
for(var i = 0; i < char.length; ++i) {
process.stdout.write(mask); // output several chars (for paste)
} }
buf += char;


}).resume(); return;
}; }

char = char.split('\015')[0]; // only use the first line if many (for paste)
for(var i = 0; i < char.length; ++i) {
process.stdout.write(mask); // output several chars (for paste)
}

buf += char;
});
};

// Allow cli.password to accept empty passwords
commander.Command.prototype.password = function (str, mask, fn) {
var self = this;


// Prompt first time // Prompt first time
getPassword(str, function (pass) { self.passwordOnce(str, mask, function (pass) {
// Prompt for confirmation // Prompt for confirmation
getPassword('Confirm password: ', function (pass2) { self.passwordOnce('Confirm password: ', mask, function (pass2) {
if (pass === pass2) { if (pass === pass2) {
fn (pass); fn (pass);
} else { } else {
Expand All @@ -413,7 +418,6 @@ commander.Command.prototype.password = function (str, mask, fn) {
}); });
}; };



commander.Command.prototype.execute = function (fn) { commander.Command.prototype.execute = function (fn) {
var self = this; var self = this;
return self.action(function () { return self.action(function () {
Expand Down
110 changes: 69 additions & 41 deletions lib/cli/commands/deployment.js

Large diffs are not rendered by default.

70 changes: 49 additions & 21 deletions lib/cli/commands/deployment_.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */



//if (!require('streamline/module')(module)) return;

var common = require('../common'); var common = require('../common');
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
Expand All @@ -24,11 +21,12 @@ var crypto = require('crypto');
var pfx2pem = require('../../util/certificates/pkcs').pfx2pem; var pfx2pem = require('../../util/certificates/pkcs').pfx2pem;
var Channel = require('../channel'); var Channel = require('../channel');
var async = require('async'); var async = require('async');
var child_process = require('child_process');
var utils = require('../utils'); var utils = require('../utils');
var constants = require('../constants'); var constants = require('../constants');
var cacheUtils = require('../cacheUtils'); var cacheUtils = require('../cacheUtils');


var linkedRevisionControl = require('../linkedrevisioncontrol');

exports.init = function (cli) { exports.init = function (cli) {


var log = cli.output; var log = cli.output;
Expand Down Expand Up @@ -80,7 +78,7 @@ exports.init = function (cli) {
} }
}; };


var repositoryUri = ensureRepositoryUri(context, _); var repositoryUri = site.ensureRepositoryUri(context, _);
if (repositoryUri) { if (repositoryUri) {
listDeployments(context, _); listDeployments(context, _);
} else { } else {
Expand All @@ -107,7 +105,7 @@ exports.init = function (cli) {
return log.error('deployment with ' + commitId + ' does not exist'); return log.error('deployment with ' + commitId + ' does not exist');
} }


var repositoryUri = ensureRepositoryUri(context, _); var repositoryUri = site.ensureRepositoryUri(context, _);
if (repositoryUri) { if (repositoryUri) {
var deployment = scm.doDeploymentGet(context, _); var deployment = scm.doDeploymentGet(context, _);


Expand Down Expand Up @@ -159,7 +157,7 @@ exports.init = function (cli) {
return log.error('deployment with ' + commitId + ' does not exist'); return log.error('deployment with ' + commitId + ' does not exist');
} }


var repositoryUri = ensureRepositoryUri(context, _); var repositoryUri = site.ensureRepositoryUri(context, _);
if (repositoryUri) { if (repositoryUri) {
if (!options.quiet && !site.confirm('Reploy deployment with ' + context.shortId + ' id? (y/n) ', _)) { if (!options.quiet && !site.confirm('Reploy deployment with ' + context.shortId + ' id? (y/n) ', _)) {
return; return;
Expand All @@ -171,6 +169,50 @@ exports.init = function (cli) {
} }
}); });


scm.command('github [name]')
.whiteListPowershell()
.usage('[options] [name]')
.description('Links a website to a github account for deployment')
.option('-s, --subscription <id>', 'use the subscription id')
.option('-u, --username <user>', 'The github username')
.option('-up, --pass <pass>', 'The github password')
.option('-r, --repository <repository>', 'The github repository')
.execute(function (name, options, _) {
var context = {
subscription: cli.category('account').lookupSubscriptionId(options.subscription),
site: {
name: name
},
username: options.username,
password: options.pass,
remoteUri: options.repository,
flags: { }
};

if (!context.remoteUri) {
// If no explicit github repository URI is passed
// this command always prompts the user for a repository
context.flags = { forceRepositorySelection: true };
}

// Fetch site and website repository data
site.ensureRepositoryUri(context, _);
if (!context.repositoryUri) {
// If there is no website remote repo, initialize it
initializeRemoteRepo(_);
}

context.lvcClient = linkedRevisionControl.createClient(cli, 'github');
context.lvcClient.init(context, _);
context.lvcClient.deploy(context, _);

function initializeRemoteRepo(_) {
log.silly('InitializeRemoteRepo');
site.doRepositoryPost(context, _);
site.ensureRepositoryUri(context, _);
}
});

scm.doDeploymentsGet = function (context, _) { scm.doDeploymentsGet = function (context, _) {
var maxItems = parseInt(context.maxItems, 10); var maxItems = parseInt(context.maxItems, 10);
if (!maxItems || maxItems <= 0) { if (!maxItems || maxItems <= 0) {
Expand Down Expand Up @@ -335,20 +377,6 @@ exports.init = function (cli) {
}); });
} }


function ensureRepositoryUri(context, _) {
var siteData = site.lookupSiteNameAndWebSpace(context, _);
var repositoryUri = siteData && site.getRepositoryUri(siteData);
if (!repositoryUri) {
siteData = site.doSiteGet(context, _);
repositoryUri = site.getRepositoryUri(siteData);
}
if (repositoryUri) {
context.repositoryAuth = site.getRepositoryAuth(siteData);
return context.repositoryUri = repositoryUri;
}
}
scm.ensureRepositoryUri = ensureRepositoryUri;

function formatDeployment(deployment) { function formatDeployment(deployment) {
var timeProperties = ['end_time', 'last_success_end_time', 'received_time', 'start_time']; var timeProperties = ['end_time', 'last_success_end_time', 'received_time', 'start_time'];
for (var i = 0; i < timeProperties.length; ++i) { for (var i = 0; i < timeProperties.length; ++i) {
Expand Down
Loading

0 comments on commit 0142328

Please sign in to comment.