Permalink
Browse files

Factoring out git functions.

  • Loading branch information...
1 parent 159c5a8 commit cccbef22c62393daf92accc49d1806434d997682 Andre Rodrigues committed Oct 19, 2012
@@ -21,7 +21,6 @@ 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');
@@ -1,4 +1,4 @@
-/*** Generated by streamline 0.4.5 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb,__tryCatch=__rt.__tryCatch; var LinkedRevisionControl = require("../linkedrevisioncontrol.js");
+/*** Generated by streamline 0.4.5 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb; var url = require("url");
@@ -15,13 +15,15 @@
+var LinkedRevisionControl = require("../linkedrevisioncontrol.js");
+
exports.init = function(cli) {
var log = cli.output;
var site = cli.category("site");
var scm = site.category("deployment");
- scm.command("github [name]").whiteListPowershell().usage("[options] [name]").description("Redeploy your git deployment").option("-s, --subscription <id>", "use the subscription id").option("-u, --username <user>", "The username").option("-up, --pass <pass>", "The password").execute(function __1(name, options, _) { var context;
+ 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 username").option("-up, --pass <pass>", "The password").execute(function __1(name, options, _) { var context;
@@ -43,106 +45,24 @@ exports.init = function(cli) {
- function promptForCredentials(_) { var __frame = { name: "promptForCredentials", line: 46 }; return __func(_, this, arguments, promptForCredentials, 0, __frame, function __$promptForCredentials() {
- log.help("Enter your github credentials"); return (function __$promptForCredentials(__then) {
+ function promptForGithubCredentials(_) { var __frame = { name: "promptForGithubCredentials", line: 48 }; return __func(_, this, arguments, promptForGithubCredentials, 0, __frame, function __$promptForGithubCredentials() {
+ log.help("Enter your github credentials"); return (function __$promptForGithubCredentials(__then) {
if (options.username) {
context.username = options.username; __then(); } else {
- return prompt("Username: ", __cb(_, __frame, 6, 29, function ___(__0, __1) { context.username = __1; __then(); }, true)); } ; })(function __$promptForCredentials() { return (function __$promptForCredentials(__then) {
+ return prompt("Username: ", __cb(_, __frame, 6, 29, function ___(__0, __1) { context.username = __1; __then(); }, true)); } ; })(function __$promptForGithubCredentials() { return (function __$promptForGithubCredentials(__then) {
if (options.pass) {
context.password = options.pass; __then(); } else {
- return promptPassword("Password: ", __cb(_, __frame, 12, 29, function ___(__0, __2) { context.password = __2; __then(); }, true)); } ; })(function __$promptForCredentials() {
-
-
- context.lvcClient = LinkedRevisionControl.createClient(cli, "github"); _(); }); }); }); };
-
-
- function promptForRepository(_) { var repositories, parsedRepositoryUri, pathParts, owner, name, localRepositories; var __frame = { name: "promptForRepository", line: 64 }; return __func(_, this, arguments, promptForRepository, 0, __frame, function __$promptForRepository() {
- return context.lvcClient.getRepositories(context.username, __cb(_, __frame, 1, 27, function ___(__0, __1) { repositories = __1;
-
- return scm.doGetRemoteUri(context, __cb(_, __frame, 3, 28, function ___(__0, __2) { context.remoteUri = __2;
- if (context.remoteUri) {
- parsedRepositoryUri = url.parse(context.remoteUri);
- pathParts = parsedRepositoryUri.pathname.split("/");
- if ((pathParts.length === 3)) {
- owner = pathParts[1];
- name = pathParts[2].split(".")[0];
- localRepositories = repositories.filter(function(repository) {
- return ((repository.name === name) && (repository.owner.login === owner)); });
-
-
- if ((localRepositories && (localRepositories.length > 0))) {
- context.repository = localRepositories[0]; } ; } ; } ; return (function __$promptForRepository(__then) {
-
-
-
-
- if (!context.repository) {
- log.help("Choose a repository");
- return choose(repositories.map(function(repository) {
- return repository.full_name; }), __cb(_, __frame, 22, 44, function ___(__0, __3) { context.repository = repositories[__3]; __then(); }, true)); } else { __then(); } ; })(_); }, true)); }, true)); }); };
-
-
-
-
- function linkRemoteGitRepo(_) { var parsedRepositoryUri, hookUrl; var __frame = { name: "linkRemoteGitRepo", line: 92 }; return __func(_, this, arguments, linkRemoteGitRepo, 0, __frame, function __$linkRemoteGitRepo() {
- parsedRepositoryUri = url.parse(context.repositoryUri);
- parsedRepositoryUri.auth = context.repositoryAuth;
- parsedRepositoryUri.pathname = "/deploy";
- hookUrl = url.format(parsedRepositoryUri);
-
- return context.lvcClient.createOrUpdateHook(context.repository.owner.login, context.repository.name, hookUrl, __cb(_, __frame, 6, 8, _, true)); }); };
-
-
-
-
-
- function addRemoteToLocalGitRepo(_) { var gitUri; var __frame = { name: "addRemoteToLocalGitRepo", line: 104 }; return __func(_, this, arguments, addRemoteToLocalGitRepo, 0, __frame, function __$addRemoteToLocalGitRepo() {
- if (context.remoteUri) { return _(null); } ;
+ return promptPassword("Password: ", __cb(_, __frame, 12, 29, function ___(__0, __2) { context.password = __2; __then(); }, true)); } ; })(function __$promptForGithubCredentials() {
+ context.lvcClient = LinkedRevisionControl.createClient(cli, "github");
+ context.lvcClient.authenticate(context.username, context.password); _(); }); }); }); }; var __frame = { name: "__1", line: 33 }; return __func(_, this, arguments, __1, 2, __frame, function __$__1() { context = { subscription: cli.category("account").lookupSubscriptionId(options.subscription), site: { name: name } }; return scm.ensureRepositoryUri(context, __cb(_, __frame, 9, 6, function __$__1() { return promptForGithubCredentials(__cb(_, __frame, 10, 6, function __$__1() { return context.lvcClient.init(context, __cb(_, __frame, 11, 6, function __$__1() { console.log(context); return context.lvcClient.deploy(context, __cb(_, __frame, 13, 6, _, true)); }, true)); }, true)); }, true)); }); });
- gitUri = context.repository.git_url;
-
-
- log.info((("Executing `git remote add azure " + gitUri) + "`"));
- return exec(("git remote add azure " + gitUri), __cb(_, __frame, 9, 8, _, true)); }); }; var __frame = { name: "__1", line: 31 }; return __func(_, this, arguments, __1, 2, __frame, function __$__1() { context = { subscription: cli.category("account").lookupSubscriptionId(options.subscription), site: { name: name } }; return scm.ensureRepositoryUri(context, __cb(_, __frame, 9, 6, function __$__1() { return promptForCredentials(__cb(_, __frame, 10, 6, function __$__1() { return promptForRepository(__cb(_, __frame, 11, 6, function __$__1() { return linkRemoteGitRepo(__cb(_, __frame, 12, 6, function __$__1() { return addRemoteToLocalGitRepo(__cb(_, __frame, 13, 6, _, true)); }, true)); }, true)); }, true)); }, true)); }); });
-
-
-
- scm.doGetRemoteUri = function scm_doGetRemoteUri__2(context, _) { var progress, originUri;
-
-
-
-
- function getRemote(name, _) { var remotes, origin; var __frame = { name: "getRemote", line: 122 }; return __func(_, this, arguments, getRemote, 1, __frame, function __$getRemote() {
- return exec("git remote -v", __cb(_, __frame, 1, 22, function ___(__0, __1) { remotes = __1;
- origin = ((remotes.stdout + remotes.stderr)).split("\n").filter(function(item) {
- return item.split(" ").some(function(it) {
- return (it === name); }); });
-
-
-
- if ((origin && (origin.length > 0))) {
- return _(null, origin[0].split(" ")[1].split(" ")[0]); } ;
-
-
- return _(null, null); }, true)); }); }; var __frame = { name: "scm_doGetRemoteUri__2", line: 117 }; return __func(_, this, arguments, scm_doGetRemoteUri__2, 1, __frame, function __$scm_doGetRemoteUri__2() { progress = cli.progress("Retrieving local git repositories"); originUri = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doGetRemoteUri__2() {
-
-
- return getRemote("azure", __cb(_, __frame, 20, 18, function ___(__0, __1) { originUri = __1; return (function __$scm_doGetRemoteUri__2(__then) {
- if (!originUri) {
- return getRemote("origin", __cb(_, __frame, 22, 20, function ___(__0, __2) { originUri = __2; __then(); }, true)); } else { __then(); } ; })(function __$scm_doGetRemoteUri__2() { _(null, null, true); }); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doGetRemoteUri__2() {
-
-
- progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$scm_doGetRemoteUri__2() {
-
-
- return _(null, originUri); }); }); }); };
function prompt(label, callback) {
@@ -154,11 +74,4 @@ exports.init = function(cli) {
function choose(data, callback) {
- cli.choose(data, function(x) { callback(undefined, x); }); };
-
-
- function exec(cmd, cb) {
- child_process.exec(cmd, function(err, stdout, stderr) {
- cb(err, {
- stdout: stdout,
- stderr: stderr }); }); };};
+ cli.choose(data, function(x) { callback(undefined, x); }); };};
@@ -13,6 +13,8 @@
* limitations under the License.
*/
+var url = require('url');
+
var LinkedRevisionControl = require('../linkedrevisioncontrol.js');
exports.init = function (cli) {
@@ -24,7 +26,7 @@ exports.init = function (cli) {
scm.command('github [name]')
.whiteListPowershell()
.usage('[options] [name]')
- .description('Redeploy your git deployment')
+ .description('Links a website to a github account for deployment')
.option('-s, --subscription <id>', 'use the subscription id')
.option('-u, --username <user>', 'The username')
.option('-up, --pass <pass>', 'The password')
@@ -38,12 +40,12 @@ exports.init = function (cli) {
// Fetch site and repository data
scm.ensureRepositoryUri(context, _);
- promptForCredentials(_);
- promptForRepository(_);
- linkRemoteGitRepo(_);
- addRemoteToLocalGitRepo(_);
+ promptForGithubCredentials(_);
+ context.lvcClient.init(context, _);
+ console.log(context);
+ context.lvcClient.deploy(context, _);
- function promptForCredentials(_) {
+ function promptForGithubCredentials(_) {
log.help('Enter your github credentials');
if (options.username) {
@@ -59,92 +61,10 @@ exports.init = function (cli) {
}
context.lvcClient = LinkedRevisionControl.createClient(cli, 'github');
- }
-
- function promptForRepository(_) {
- var repositories = context.lvcClient.getRepositories(context.username, _);
-
- context.remoteUri = scm.doGetRemoteUri(context, _);
- if (context.remoteUri) {
- var parsedRepositoryUri = url.parse(context.remoteUri);
- var pathParts = parsedRepositoryUri.pathname.split('/');
- if (pathParts.length === 3) {
- var owner = pathParts[1];
- var name = pathParts[2].split('.')[0];
- var localRepositories = repositories.filter(function (repository) {
- return repository.name === name && repository.owner.login === owner;
- });
-
- if (localRepositories && localRepositories.length > 0) {
- context.repository = localRepositories[0];
- }
- }
- }
-
- if (!context.repository) {
- log.help('Choose a repository');
- context.repository = repositories[choose(repositories.map(function (repository) {
- return repository.full_name;
- }), _)];
- }
- }
-
- function linkRemoteGitRepo(_) {
- var parsedRepositoryUri = url.parse(context.repositoryUri);
- parsedRepositoryUri.auth = context.repositoryAuth;
- parsedRepositoryUri.pathname = '/deploy';
- var hookUrl = url.format(parsedRepositoryUri);
-
- context.lvcClient.createOrUpdateHook(context.repository.owner.login,
- context.repository.name,
- hookUrl,
- _);
- }
-
- function addRemoteToLocalGitRepo(_) {
- if (context.remoteUri) {
- return;
- }
-
- var gitUri = context.repository.git_url;
-
- // create the remote repo locally
- log.info('Executing `git remote add azure ' + gitUri + '`');
- exec('git remote add azure ' + gitUri, _);
+ context.lvcClient.authenticate(context.username, context.password);
}
});
- scm.doGetRemoteUri = function (context, _) {
- var progress = cli.progress('Retrieving local git repositories');
- var originUri = null;
-
- try {
- function getRemote(name, _) {
- var remotes = exec('git remote -v', _);
- var origin = (remotes.stdout + remotes.stderr).split('\n').filter(function (item) {
- return item.split('\t').some(function (it) {
- return it === name;
- });
- });
-
- if (origin && origin.length > 0) {
- return origin[0].split('\t')[1].split(' ')[0];
- }
-
- return null;
- }
-
- originUri = getRemote('azure', _);
- if (!originUri) {
- originUri = getRemote('origin', _);
- }
- } finally {
- progress.end();
- }
-
- return originUri;
- };
-
function prompt(label, callback) {
cli.prompt(label, function (x) { callback(undefined, x); });
}
@@ -156,13 +76,4 @@ exports.init = function (cli) {
function choose(data, callback) {
cli.choose(data, function (x) { callback(undefined, x); });
}
-
- function exec(cmd, cb) {
- child_process.exec(cmd, function (err, stdout, stderr) {
- cb(err, {
- stdout: stdout,
- stderr: stderr
- });
- });
- }
};
View
@@ -117,6 +117,7 @@ exports.init = function (cli) {
.option('--location <location>', 'the geographic region to create the website')
.option('--hostname <hostname>', 'custom host name to use')
.option('--git', 'configure git on web site and local folder')
+ .option('--github', 'configure github on web site and local folder')
.execute(function (nameArg, options, _) {
var context = {
subscription: cli.category('account').lookupSubscriptionId(options.subscription),
@@ -130,15 +131,31 @@ exports.init = function (cli) {
}
};
+ if (options.git && options.github) {
+ throw new Error('Please run the command with either --git or --github options. Not both.')
+ }
+
promptForSiteName(_);
determineIfSiteExists(_);
promptForLocation(_);
- determineIfCurrentDirectoryIsGitWorkingTree(_);
- initGitOnCurrentDirectory(_);
+
+ if (options.git) {
+ determineIfCurrentDirectoryIsGitWorkingTree(_);
+ initGitOnCurrentDirectory(_);
+ } else if (options.github) {
+ promptForGithubCredentials(_);
+ }
+
copyIisNodeWhenServerJsPresent(_);
updateLocalConfigWithSiteName(_);
- createSiteAndInitializeRemoteRepo(_);
- addRemoteToLocalGitRepo(_);
+ createSite(_);
+
+ if (options.git) {
+ initializeRemoteRepo(_);
+ addRemoteToLocalGitRepo(_);
+ } else if (options.github) {
+
+ }
function promptForSiteName(_) {
log.silly('promptForSiteName');
@@ -203,6 +220,25 @@ exports.init = function (cli) {
}
}
+ function promptForGithubCredentials(_) {
+ log.help('Enter your github credentials');
+
+ if (options.username) {
+ context.username = options.username;
+ } else {
+ context.username = prompt('Username: ', _);
+ }
+
+ if (options.pass) {
+ context.password = options.pass;
+ } else {
+ context.password = promptPassword('Password: ', _);
+ }
+
+ context.lvcClient = LinkedRevisionControl.createClient(cli, 'github');
+ context.lvcClient.authenticate(context.username, context.password);
+ }
+
function determineIfCurrentDirectoryIsGitWorkingTree(_) {
log.silly('determineIfCurrentDirectoryIsGitWorkingTree');
@@ -260,10 +296,16 @@ exports.init = function (cli) {
}
}
- function createSiteAndInitializeRemoteRepo(_) {
- log.silly('createSiteAndInitializeRemoteRepo');
+ function createSite(_) {
+ log.silly('createSite');
if (!context.flags.siteExists) {
site.doSitesPost(context, _);
+ }
+ }
+
+ function initializeRemoteRepo(_) {
+ log.silly('InitializeRemoteRepo');
+ if (!context.flags.siteExists) {
site.doRepositoryPost(context, _);
context.repo = site.doRepositoryGet(context, _);
} else {
Oops, something went wrong.

0 comments on commit cccbef2

Please sign in to comment.