Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix UT

  • Loading branch information...
commit 4249605a9f7a120c66887158c08391cb0e692925 1 parent fab8be7
@andrerod andrerod authored
View
43 lib/cli/commands/deployment_.js
@@ -167,6 +167,49 @@ 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 username')
+ .option('-up, --pass <pass>', 'The password')
+ .execute(function (name, options, _) {
+ var context = {
+ subscription: cli.category('account').lookupSubscriptionId(options.subscription),
+ site: {
+ name: name
+ }
+ };
+
+ // Fetch site and repository data
+ scm.ensureRepositoryUri(context, _);
+ promptForGithubCredentials(_);
+
+ context.flags = { forceRepositorySelection: true };
+ context.lvcClient.init(context, _);
+ context.lvcClient.deploy(context, _);
+
+ 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, _);
+ }
+ });
+
scm.doDeploymentsGet = function (context, _) {
var maxItems = parseInt(context.maxItems, 10);
if (!maxItems || maxItems <= 0) {
View
1  lib/cli/commands/site_.js
@@ -125,6 +125,7 @@ exports.init = function (cli) {
.option('--github', 'configure github on web site and local folder')
.option('-u, --username <user>', 'The username')
.option('-up, --pass <pass>', 'The password')
+ .option('-r, --repository repository', 'The github repository')
.execute(function (nameArg, options, _) {
var context = {
subscription: cli.category('account').lookupSubscriptionId(options.subscription),
View
48 lib/cli/linkedrevisioncontrol.js
@@ -128,9 +128,13 @@ GithubClient.prototype.init = function GithubClient_prototype_init__7(context, _
return __this.determineIfCurrentDirectoryIsGitWorkingTree(context, __cb(_, __frame, 1, 2, function __$GithubClient_prototype_init__7() {
return __this.initGitOnCurrentDirectory(context, false, __cb(_, __frame, 2, 2, function __$GithubClient_prototype_init__7() {
- return __this.getRepositories(context.username, __cb(_, __frame, 4, 21, function ___(__0, __1) { repositories = __1;
+ return __this.getRepositories(context.username, __cb(_, __frame, 4, 21, function ___(__0, __1) { repositories = __1; return (function __$GithubClient_prototype_init__7(__then) {
+
+ if (!context.remoteUri) {
+
+ return __this._getRemoteUri(__cb(_, __frame, 8, 24, function ___(__0, __2) { context.remoteUri = __2; __then(); }, true)); } else { __then(); } ; })(function __$GithubClient_prototype_init__7() {
+
- return __this._getRemoteUri(__cb(_, __frame, 6, 22, function ___(__0, __2) { context.remoteUri = __2;
if ((!context.flags.forceRepositorySelection && context.remoteUri)) {
parsedRepositoryUri = url.parse(context.remoteUri);
pathParts = parsedRepositoryUri.pathname.split("/");
@@ -148,14 +152,15 @@ GithubClient.prototype.init = function GithubClient_prototype_init__7(context, _
if (!context.repository) {
+
__this.cli.output.help("Choose a repository");
return choose(__this.cli, repositories.map(function(repository) {
- return repository.full_name; }), __cb(_, __frame, 25, 38, function ___(__0, __3) { context.repository = repositories[__3]; __then(); }, true)); } else { __then(); } ; })(_); }, true)); }, true)); }, true)); }, true)); });};
+ return repository.full_name; }), __cb(_, __frame, 30, 38, function ___(__0, __3) { context.repository = repositories[__3]; __then(); }, true)); } else { __then(); } ; })(_); }); }, true)); }, true)); }, true)); });};
-GithubClient.prototype.deploy = function GithubClient_prototype_deploy__8(context, _) { var parsedRepositoryUri, hookUrl, parsedCloneUrl, gitUri, __this = this; var __frame = { name: "GithubClient_prototype_deploy__8", line: 158 }; return __func(_, this, arguments, GithubClient_prototype_deploy__8, 1, __frame, function __$GithubClient_prototype_deploy__8() {
+GithubClient.prototype.deploy = function GithubClient_prototype_deploy__8(context, _) { var parsedRepositoryUri, hookUrl, parsedCloneUrl, gitUri, azureRemote, __this = this; var __frame = { name: "GithubClient_prototype_deploy__8", line: 163 }; return __func(_, this, arguments, GithubClient_prototype_deploy__8, 1, __frame, function __$GithubClient_prototype_deploy__8() {
parsedRepositoryUri = url.parse(context.repositoryUri);
parsedRepositoryUri.auth = context.repositoryAuth;
parsedRepositoryUri.pathname = "/deploy";
@@ -169,16 +174,20 @@ GithubClient.prototype.deploy = function GithubClient_prototype_deploy__8(contex
parsedCloneUrl.auth = context.username;
gitUri = url.format(parsedCloneUrl); return (function __$GithubClient_prototype_deploy__8(__then) {
- if (((context.remoteUri && (context.remoteUri.toLowerCase() !== gitUri.toLowerCase())) && context.remoteUri.origin)) {
- __this.cli.output.verbose("Removing existing azure remote alias");
- return __this._exec("git remote rm azure", __cb(_, __frame, 16, 4, function __$GithubClient_prototype_deploy__8() {
- context.remoteUri = null; __then(); }, true)); } else { __then(); } ; })(function __$GithubClient_prototype_deploy__8() { return (function __$GithubClient_prototype_deploy__8(__then) {
+ if ((context.remoteUri && (context.remoteUri.toLowerCase() !== gitUri.toLowerCase()))) {
+ context.remoteUri = null;
+
+ return __this._getRemote("azure", __cb(_, __frame, 17, 22, function ___(__0, __1) { azureRemote = __1; return (function __$GithubClient_prototype_deploy__8(__then) {
+ if (azureRemote) {
+ __this.cli.output.verbose("Removing existing azure remote alias");
+ return __this._exec("git remote rm azure", __cb(_, __frame, 20, 6, __then, true)); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$GithubClient_prototype_deploy__8() { return (function __$GithubClient_prototype_deploy__8(__then) {
+
if (!context.remoteUri) {
__this.cli.output.info((("Executing `git remote add azure " + gitUri) + "`"));
- return __this._exec(("git remote add azure " + gitUri), __cb(_, __frame, 23, 4, __then, true)); } else { __then(); } ; })(_); }); }, true)); });};
+ return __this._exec(("git remote add azure " + gitUri), __cb(_, __frame, 27, 4, __then, true)); } else { __then(); } ; })(_); }); }, true)); });};
@@ -192,7 +201,7 @@ GithubClient.prototype.getRepositories = function GithubClient_prototype_getRepo
function filterPrivate(repository) {
- return (repository["private"] !== true); }; var __frame = { name: "GithubClient_prototype_getRepositories__9", line: 185 }; return __func(_, this, arguments, GithubClient_prototype_getRepositories__9, 1, __frame, function __$GithubClient_prototype_getRepositories__9() { progress = __this.cli.progress("Retrieving repositories"); userRepos = []; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_getRepositories__9() {
+ return (repository["private"] !== true); }; var __frame = { name: "GithubClient_prototype_getRepositories__9", line: 194 }; return __func(_, this, arguments, GithubClient_prototype_getRepositories__9, 1, __frame, function __$GithubClient_prototype_getRepositories__9() { progress = __this.cli.progress("Retrieving repositories"); userRepos = []; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_getRepositories__9() {
@@ -224,7 +233,7 @@ GithubClient.prototype.getRepositories = function GithubClient_prototype_getRepo
return _(null, userRepos); }); }); });};
-GithubClient.prototype.createOrUpdateHook = function GithubClient_prototype_createOrUpdateHook__10(username, repository, deployUri, _) { var hook, hooks, parsedDeployUri, existingHook, __this = this; var __frame = { name: "GithubClient_prototype_createOrUpdateHook__10", line: 227 }; return __func(_, this, arguments, GithubClient_prototype_createOrUpdateHook__10, 3, __frame, function __$GithubClient_prototype_createOrUpdateHook__10() {
+GithubClient.prototype.createOrUpdateHook = function GithubClient_prototype_createOrUpdateHook__10(username, repository, deployUri, _) { var hook, hooks, parsedDeployUri, existingHook, __this = this; var __frame = { name: "GithubClient_prototype_createOrUpdateHook__10", line: 236 }; return __func(_, this, arguments, GithubClient_prototype_createOrUpdateHook__10, 3, __frame, function __$GithubClient_prototype_createOrUpdateHook__10() {
hook = {
name: "web",
user: username,
@@ -268,7 +277,7 @@ GithubClient.prototype.createOrUpdateHook = function GithubClient_prototype_crea
-GithubClient.prototype.createHook = function GithubClient_prototype_createHook__11(hook, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_createHook__11", line: 271 }; return __func(_, this, arguments, GithubClient_prototype_createHook__11, 1, __frame, function __$GithubClient_prototype_createHook__11() {
+GithubClient.prototype.createHook = function GithubClient_prototype_createHook__11(hook, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_createHook__11", line: 280 }; return __func(_, this, arguments, GithubClient_prototype_createHook__11, 1, __frame, function __$GithubClient_prototype_createHook__11() {
progress = __this.cli.progress("Creating new hook"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_createHook__11() {
@@ -278,7 +287,7 @@ GithubClient.prototype.createHook = function GithubClient_prototype_createHook__
-GithubClient.prototype.updateHook = function GithubClient_prototype_updateHook__12(hook, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_updateHook__12", line: 281 }; return __func(_, this, arguments, GithubClient_prototype_updateHook__12, 1, __frame, function __$GithubClient_prototype_updateHook__12() {
+GithubClient.prototype.updateHook = function GithubClient_prototype_updateHook__12(hook, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_updateHook__12", line: 290 }; return __func(_, this, arguments, GithubClient_prototype_updateHook__12, 1, __frame, function __$GithubClient_prototype_updateHook__12() {
progress = __this.cli.progress("Updating hook"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_updateHook__12() {
@@ -288,7 +297,7 @@ GithubClient.prototype.updateHook = function GithubClient_prototype_updateHook__
-GithubClient.prototype.testHook = function GithubClient_prototype_testHook__13(hook, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_testHook__13", line: 291 }; return __func(_, this, arguments, GithubClient_prototype_testHook__13, 1, __frame, function __$GithubClient_prototype_testHook__13() {
+GithubClient.prototype.testHook = function GithubClient_prototype_testHook__13(hook, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_testHook__13", line: 300 }; return __func(_, this, arguments, GithubClient_prototype_testHook__13, 1, __frame, function __$GithubClient_prototype_testHook__13() {
progress = __this.cli.progress("Testing new hook"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_testHook__13() {
@@ -298,7 +307,7 @@ GithubClient.prototype.testHook = function GithubClient_prototype_testHook__13(h
-GithubClient.prototype.getHooks = function GithubClient_prototype_getHooks__14(username, repository, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_getHooks__14", line: 301 }; return __func(_, this, arguments, GithubClient_prototype_getHooks__14, 2, __frame, function __$GithubClient_prototype_getHooks__14() {
+GithubClient.prototype.getHooks = function GithubClient_prototype_getHooks__14(username, repository, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_getHooks__14", line: 310 }; return __func(_, this, arguments, GithubClient_prototype_getHooks__14, 2, __frame, function __$GithubClient_prototype_getHooks__14() {
progress = __this.cli.progress("Retrieving website hooks"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_getHooks__14() {
@@ -311,17 +320,14 @@ GithubClient.prototype.getHooks = function GithubClient_prototype_getHooks__14(u
-GithubClient.prototype._getRemoteUri = function GithubClient_prototype__getRemoteUri__15(_) { var progress, originUri, __this = this; var __frame = { name: "GithubClient_prototype__getRemoteUri__15", line: 314 }; return __func(_, this, arguments, GithubClient_prototype__getRemoteUri__15, 0, __frame, function __$GithubClient_prototype__getRemoteUri__15() {
+GithubClient.prototype._getRemoteUri = function GithubClient_prototype__getRemoteUri__15(_) { var progress, originUri, __this = this; var __frame = { name: "GithubClient_prototype__getRemoteUri__15", line: 323 }; return __func(_, this, arguments, GithubClient_prototype__getRemoteUri__15, 0, __frame, function __$GithubClient_prototype__getRemoteUri__15() {
progress = __this.cli.progress("Retrieving local git repositories");
originUri = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype__getRemoteUri__15() {
return __this._getRemote("azure", __cb(_, __frame, 5, 16, function ___(__0, __1) { originUri = __1; return (function __$GithubClient_prototype__getRemoteUri__15(__then) {
if (!originUri) {
- return __this._getRemote("origin", __cb(_, __frame, 7, 18, function ___(__0, __2) { originUri = __2;
- if (originUri) {
- originUri.origin = true; } ; __then(); }, true)); } else { __then(); } ; })(function __$GithubClient_prototype__getRemoteUri__15() { _(null, null, true); }); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$GithubClient_prototype__getRemoteUri__15() {
-
+ return __this._getRemote("origin", __cb(_, __frame, 7, 18, function ___(__0, __2) { originUri = __2; __then(); }, true)); } else { __then(); } ; })(function __$GithubClient_prototype__getRemoteUri__15() { _(null, null, true); }); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$GithubClient_prototype__getRemoteUri__15() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$GithubClient_prototype__getRemoteUri__15() {
@@ -330,7 +336,7 @@ GithubClient.prototype._getRemoteUri = function GithubClient_prototype__getRemot
return _(null, originUri); }); }); });};
-GithubClient.prototype._getRemote = function GithubClient_prototype__getRemote__16(name, _) { var remotes, origin, __this = this; var __frame = { name: "GithubClient_prototype__getRemote__16", line: 333 }; return __func(_, this, arguments, GithubClient_prototype__getRemote__16, 1, __frame, function __$GithubClient_prototype__getRemote__16() {
+GithubClient.prototype._getRemote = function GithubClient_prototype__getRemote__16(name, _) { var remotes, origin, __this = this; var __frame = { name: "GithubClient_prototype__getRemote__16", line: 339 }; return __func(_, this, arguments, GithubClient_prototype__getRemote__16, 1, __frame, function __$GithubClient_prototype__getRemote__16() {
return __this._exec("git remote -v", __cb(_, __frame, 1, 16, function ___(__0, __1) { remotes = __1;
origin = ((remotes.stdout + remotes.stderr)).split("\n").filter(function(item) {
return item.split(" ").some(function(it) {
View
20 lib/cli/linkedrevisioncontrol_.js
@@ -130,7 +130,11 @@ GithubClient.prototype.init = function (context, _) {
var repositories = this.getRepositories(context.username, _);
- context.remoteUri = this._getRemoteUri(_);
+ if (!context.remoteUri) {
+ // Look for git repository in local git remotes
+ context.remoteUri = this._getRemoteUri(_);
+ }
+
if (!context.flags.forceRepositorySelection && context.remoteUri) {
var parsedRepositoryUri = url.parse(context.remoteUri);
var pathParts = parsedRepositoryUri.pathname.split('/');
@@ -148,6 +152,7 @@ GithubClient.prototype.init = function (context, _) {
}
if (!context.repository) {
+ // Look for git repository in github
this.cli.output.help('Choose a repository');
context.repository = repositories[choose(this.cli, repositories.map(function (repository) {
return repository.full_name;
@@ -169,10 +174,14 @@ GithubClient.prototype.deploy = function (context, _) {
parsedCloneUrl.auth = context.username;
var gitUri = url.format(parsedCloneUrl);
- if (context.remoteUri && context.remoteUri.toLowerCase() !== gitUri.toLowerCase() && context.remoteUri.origin) {
- this.cli.output.verbose('Removing existing azure remote alias');
- this._exec('git remote rm azure', _);
+ if (context.remoteUri && context.remoteUri.toLowerCase() !== gitUri.toLowerCase()) {
context.remoteUri = null;
+
+ var azureRemote = this._getRemote('azure', _);
+ if (azureRemote) {
+ this.cli.output.verbose('Removing existing azure remote alias');
+ this._exec('git remote rm azure', _);
+ }
}
if (!context.remoteUri) {
@@ -319,9 +328,6 @@ GithubClient.prototype._getRemoteUri = function (_) {
originUri = this._getRemote('azure', _);
if (!originUri) {
originUri = this._getRemote('origin', _);
- if (originUri) {
- originUri.origin = true;
- }
}
} finally {
progress.end();
View
83 test/cli/commands/cli.site-tests.js
@@ -51,16 +51,91 @@ suite('cli', function(){
siteExists.should.be.ok;
- console.log('vou pro delete');
+ // Delete created site
+ cmd = ('node cli.js site delete ' + siteName + ' --json --quiet').split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ result.exitStatus.should.equal(0);
+
+ // List sites
+ cmd = 'node cli.js site list --json'.split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ siteList = JSON.parse(result.text);
+
+ siteExists = siteList.some(function (site) {
+ return site.Name.toLowerCase() === siteName.toLowerCase()
+ });
+
+ siteExists.should.not.be.ok;
+
+ done();
+ });
+ });
+ });
+ });
+ });
+
+ test('site create github', function(done) {
+ var siteName = 'cliuttestsite';
+
+ // Setup
+ var originUrl = {
+ stdout: 'myremote\tgit://github.com/andrerod/mynewsite999.git (fetch)\n' +
+ 'myremote\tgit://github.com/andrerod/mynewsite999.git (push)\n',
+ stderr: ''
+ };
+
+ // Create site
+ var cmd = ('node cli.js site create ' + siteName + ' --github --json --location').split(' ');
+ cmd.push('East US');
+ cmd.push('--username');
+ cmd.push(process.env['AZURE_GITHUB_USERNAME']);
+ cmd.push('--pass');
+ cmd.push(process.env['AZURE_GITHUB_PASSWORD']);
+
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ result.exitStatus.should.equal(0);
+
+ // List sites
+ cmd = 'node cli.js site list --json'.split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ var siteList = JSON.parse(result.text);
+
+ var siteExists = siteList.some(function (site) {
+ return site.Name.toLowerCase() === siteName.toLowerCase()
+ });
+
+ siteExists.should.be.ok;
// Delete created site
- cmd = ('node cli.js site delete ' + siteName + ' --json').split(' ');
+ cmd = ('node cli.js site delete ' + siteName + ' --json --quiet').split(' ');
capture(function() {
cli.parse(cmd);
}, function (result) {
- console.log(result);
+ result.exitStatus.should.equal(0);
+
+ // List sites
+ cmd = 'node cli.js site list --json'.split(' ');
+ capture(function() {
+ cli.parse(cmd);
+ }, function (result) {
+ siteList = JSON.parse(result.text);
+
+ siteExists = siteList.some(function (site) {
+ return site.Name.toLowerCase() === siteName.toLowerCase()
+ });
+
+ siteExists.should.not.be.ok;
- done();
+ done();
+ });
});
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.