Permalink
Browse files

Merge pull request #394 from andrerod/dev

Github support
  • Loading branch information...
2 parents df1b226 + 3cc26ec commit 80254ccd0a2a99c74ecd716686eb5cd151f28fa1 André Rodrigues committed Oct 24, 2012
View
@@ -344,66 +344,71 @@ commander.Command.prototype.whiteListPowershell = function (whitelist) {
return this;
};
-// Allow cli.password to accept empty passwords
-commander.Command.prototype.password = function (str, mask, fn) {
+commander.Command.prototype.passwordOnce = function (currentStr, mask, callback) {
+ var self = this;
+ var buf = '';
+
// default mask
if ('function' === typeof mask) {
- fn = mask;
+ callback = mask;
mask = '';
}
- var getPassword = function (currentStr, callback) {
- var self = this;
- var buf = '';
+ if (!process.stdin.setRawMode) {
+ process.stdin.setRawMode = tty.setRawMode;
+ }
- if (!process.stdin.setRawMode) {
- process.stdin.setRawMode = tty.setRawMode;
+ process.stdin.resume();
+ 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();
- 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();
- }
+ // Return password in the buffer on enter key press
+ if (char === '\015') {
+ process.stdin.removeAllListeners('data');
+ process.stdout.write('\n');
+ process.stdin.setRawMode(false);
+ process.stdin.pause();
- // Return password in the buffer on enter key press
- if (char === '\015') {
- process.stdin.removeAllListeners('data');
- process.stdout.write('\n');
- process.stdin.setRawMode(false);
- callback(buf);
- return;
- }
-
- // Backspace handling
- // 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 callback(buf);
+ }
+
+ // Backspace handling
+ // 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
- getPassword(str, function (pass) {
+ self.passwordOnce(str, mask, function (pass) {
// Prompt for confirmation
- getPassword('Confirm password: ', function (pass2) {
+ self.passwordOnce('Confirm password: ', mask, function (pass2) {
if (pass === pass2) {
fn (pass);
} else {
@@ -413,7 +418,6 @@ commander.Command.prototype.password = function (str, mask, fn) {
});
};
-
commander.Command.prototype.execute = function (fn) {
var self = this;
return self.action(function () {

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -13,9 +13,6 @@
* limitations under the License.
*/
-
-//if (!require('streamline/module')(module)) return;
-
var common = require('../common');
var fs = require('fs');
var path = require('path');
@@ -24,11 +21,12 @@ var crypto = require('crypto');
var pfx2pem = require('../../util/certificates/pkcs').pfx2pem;
var Channel = require('../channel');
var async = require('async');
-var child_process = require('child_process');
var utils = require('../utils');
var constants = require('../constants');
var cacheUtils = require('../cacheUtils');
+var linkedRevisionControl = require('../linkedrevisioncontrol');
+
exports.init = function (cli) {
var log = cli.output;
@@ -80,7 +78,7 @@ exports.init = function (cli) {
}
};
- var repositoryUri = ensureRepositoryUri(context, _);
+ var repositoryUri = site.ensureRepositoryUri(context, _);
if (repositoryUri) {
listDeployments(context, _);
} else {
@@ -107,7 +105,7 @@ exports.init = function (cli) {
return log.error('deployment with ' + commitId + ' does not exist');
}
- var repositoryUri = ensureRepositoryUri(context, _);
+ var repositoryUri = site.ensureRepositoryUri(context, _);
if (repositoryUri) {
var deployment = scm.doDeploymentGet(context, _);
@@ -159,7 +157,7 @@ exports.init = function (cli) {
return log.error('deployment with ' + commitId + ' does not exist');
}
- var repositoryUri = ensureRepositoryUri(context, _);
+ var repositoryUri = site.ensureRepositoryUri(context, _);
if (repositoryUri) {
if (!options.quiet && !site.confirm('Reploy deployment with ' + context.shortId + ' id? (y/n) ', _)) {
return;
@@ -171,6 +169,52 @@ 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 full name (i.e. user/repository)')
+ .execute(function (name, options, _) {
+ var context = {
+ subscription: cli.category('account').lookupSubscriptionId(options.subscription),
+ site: {
+ name: name
+ },
+ github: {
+ username: options.username,
+ password: options.pass,
+ repositoryFullName: options.repository
+ },
+ flags: { }
+ };
+
+ if (!context.github.repositoryFullName) {
+ // 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, _) {
var maxItems = parseInt(context.maxItems, 10);
if (!maxItems || maxItems <= 0) {
@@ -335,20 +379,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) {
var timeProperties = ['end_time', 'last_success_end_time', 'received_time', 'start_time'];
for (var i = 0; i < timeProperties.length; ++i) {
Oops, something went wrong.

0 comments on commit 80254cc

Please sign in to comment.