Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding hooks

  • Loading branch information...
commit 87cddfe856fc9046910b5a581557e4ae35c0e9ff 1 parent 1b83805
@andrerod andrerod authored
Showing with 257 additions and 55 deletions.
  1. +133 −33 lib/cli/commands/deployment.js
  2. +124 −22 lib/cli/commands/deployment_.js
View
166 lib/cli/commands/deployment.js
@@ -172,7 +172,7 @@ exports.init = function(cli) {
- scm.command("github").whiteListPowershell().usage("[options]").description("Redeploy your git deployment").execute(function __4(options, _) { var context;
+ scm.command("github [name]").whiteListPowershell().usage("[options]").description("Redeploy your git deployment").execute(function __4(nameArg, options, _) { var context;
@@ -191,56 +191,149 @@ exports.init = function(cli) {
+ function promptForCredentials(_) { var __frame = { name: "promptForCredentials", line: 194 }; return __func(_, this, arguments, promptForCredentials, 0, __frame, function __$promptForCredentials() {
+ log.help("Enter your github credentials");
+ return prompt("username: ", __cb(_, __frame, 2, 27, function ___(__0, __1) { context.username = __1;
+ return prompt("password: ", __cb(_, __frame, 3, 27, function ___(__0, __2) { context.password = __2;
+ context.github = new GitHubApi({ version: "3.0.0" });
+ context.github.authenticate({
+ type: "basic",
+ username: context.username,
+ password: context.password }); _(); }, true)); }, true)); }); };
- function promptForRepository(_) { var repositories; var __frame = { name: "promptForRepository", line: 197 }; return __func(_, this, arguments, promptForRepository, 0, __frame, function __$promptForRepository() {
+
+ function promptForRepository(_) { var repositories, githubUri, parsedRepositoryUri, pathParts, owner, name, localRepositories; var __frame = { name: "promptForRepository", line: 207 }; return __func(_, this, arguments, promptForRepository, 0, __frame, function __$promptForRepository() {
return scm.doGetRepositories(context, __cb(_, __frame, 1, 27, function ___(__0, __1) { repositories = __1;
- log.help("Choose a repository");
- return choose(repositories.map(function(repository) {
- var repoUrl = url.parse(repository.git_url);
- return repoUrl.pathname; }), __cb(_, __frame, 3, 42, function ___(__0, __2) { context.repository = repositories[__2]; _(); }, true)); }, true)); }); }; var __frame = { name: "__4", line: 179 }; return __func(_, this, arguments, __4, 1, __frame, function __$__4() { context = { subscription: cli.category("account").lookupSubscriptionId(options.subscription) }; log.help("Enter your github credentials"); return prompt("username: ", __cb(_, __frame, 6, 25, function ___(__0, __1) { context.username = __1; return prompt("password: ", __cb(_, __frame, 7, 25, function ___(__0, __2) { context.password = __2; context.github = new GitHubApi({ version: "3.0.0" }); context.github.authenticate({ type: "basic", username: context.username, password: context.password }); return promptForRepository(__cb(_, __frame, 16, 6, _, true)); }, true)); }, true)); }); });
+ return scm.doGetGitOriginUri(context, __cb(_, __frame, 3, 24, function ___(__0, __2) { githubUri = __2;
+ if (githubUri) {
+ parsedRepositoryUri = url.parse(githubUri);
+ 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]; } ;
+
+
+ if (!context.repository) {
+
+
+
+ context.repository = {
+ name: name,
+ owner: {
+ login: owner } }; } ; } ; } ; return (function __$promptForRepository(__then) {
+
+
+
+
+
+
+ if (!context.repository) {
+ log.help("Choose a repository");
+ return choose(repositories.map(function(repository) {
+ return repository.full_name; }), __cb(_, __frame, 34, 44, function ___(__0, __3) { context.repository = repositories[__3]; __then(); }, true)); } else { __then(); } ; })(_); }, true)); }, true)); }); };
+
+
+
+
+ function linkRemoteGitRepo(_) { var parsedRepositoryUri, hookUrl; var __frame = { name: "linkRemoteGitRepo", line: 247 }; return __func(_, this, arguments, linkRemoteGitRepo, 0, __frame, function __$linkRemoteGitRepo() {
+ parsedRepositoryUri = url.parse(context.repositoryUri);
+ parsedRepositoryUri.auth = context.repositoryAuth;
+ parsedRepositoryUri.pathname = "/deploy";
+ console.log(parsedRepositoryUri);
+ hookUrl = url.format(parsedRepositoryUri);
+
+ context.hook = {
+ name: "web",
+ user: context.repository.name,
+ repo: context.repository.owner.login,
+ active: true,
+ events: ["push",],
+ config: {
+ url: hookUrl,
+ content_type: "json" } };
+ return scm.doCreateHook(context, __cb(_, __frame, 19, 8, _, true)); }); };
- scm.doCreateHook = function scm_doCreateHook__5(context, _) { var progress; var __frame = { name: "scm_doCreateHook__5", line: 209 }; return __func(_, this, arguments, scm_doCreateHook__5, 1, __frame, function __$scm_doCreateHook__5() {
- progress = cli.progress("Retrieving repositories"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doCreateHook__5() {
+ function addRemoteToLocalGitRepo(_) { var __frame = { name: "addRemoteToLocalGitRepo", line: 269 }; return __func(_, this, arguments, addRemoteToLocalGitRepo, 0, __frame, _); }; var __frame = { name: "__4", line: 179 }; return __func(_, this, arguments, __4, 2, __frame, function __$__4() { context = { subscription: cli.category("account").lookupSubscriptionId(options.subscription), site: { name: nameArg } }; return ensureRepositoryUri(context, __cb(_, __frame, 9, 6, function __$__4() { return promptForCredentials(__cb(_, __frame, 10, 6, function __$__4() { return promptForRepository(__cb(_, __frame, 11, 6, function __$__4() { return linkRemoteGitRepo(__cb(_, __frame, 12, 6, function __$__4() { return addRemoteToLocalGitRepo(__cb(_, __frame, 13, 6, _, true)); }, true)); }, true)); }, true)); }, true)); }); });
+
+
+
+ scm.doCreateHook = function scm_doCreateHook__5(context, _) { var progress, msg; var __frame = { name: "scm_doCreateHook__5", line: 273 }; return __func(_, this, arguments, scm_doCreateHook__5, 1, __frame, function __$scm_doCreateHook__5() {
+ progress = cli.progress("Creating hook");
+
+ msg = {
+ user: context.repository.owner.login,
+ repo: context.repository.name };
+
+
+ console.log(context.hook);
+ console.log(msg); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doCreateHook__5() { _(null, null, true); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doCreateHook__5() {
- context.github.repos.getHooks({ repo: context.repoPath }); _(null, null, true); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doCreateHook__5() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
- scm.doGetRepositories = function scm_doGetRepositories__6(context, _) { var progress, userRepos, orgs, i, org; var __frame = { name: "scm_doGetRepositories__6", line: 219 }; return __func(_, this, arguments, scm_doGetRepositories__6, 1, __frame, function __$scm_doGetRepositories__6() {
+ scm.doGetGitOriginUri = function scm_doGetGitOriginUri__6(context, _) { var progress, originUri, remotes, origin; var __frame = { name: "scm_doGetGitOriginUri__6", line: 290 }; return __func(_, this, arguments, scm_doGetGitOriginUri__6, 1, __frame, function __$scm_doGetGitOriginUri__6() {
+ progress = cli.progress("Getting local git repositories");
+ originUri = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doGetGitOriginUri__6() {
+
+
+ return exec("git remote -v", __cb(_, __frame, 5, 20, function ___(__0, __1) { remotes = __1;
+ origin = ((remotes.stdout + remotes.stderr)).split("\n").filter(function(item) {
+ return item.split(" ").some(function(it) {
+ return (it === "origin"); }); });
+
+
+
+ if ((origin && (origin.length > 0))) {
+ originUri = origin[0].split(" ")[1].split(" ")[0]; } ; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doGetGitOriginUri__6() {
+
+
+ progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$scm_doGetGitOriginUri__6() {
+
+
+ return _(null, originUri); }); }); }); };
+
+
+ scm.doGetRepositories = function scm_doGetRepositories__7(context, _) { var progress, userRepos, orgs, i, org; var __frame = { name: "scm_doGetRepositories__7", line: 312 }; return __func(_, this, arguments, scm_doGetRepositories__7, 1, __frame, function __$scm_doGetRepositories__7() {
progress = cli.progress("Retrieving repositories");
- userRepos = []; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doGetRepositories__6() {
+ userRepos = []; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doGetRepositories__7() {
return context.github.repos.getFromUser({ user: context.username }, __cb(_, __frame, 5, 18, function ___(__0, __3) { userRepos = __3;
return context.github.user.getOrgs({ user: context.username }, __cb(_, __frame, 6, 17, function ___(__0, __4) { orgs = __4;
- var __1 = __forIn(orgs); var __2 = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$scm_doGetRepositories__6() { __more = false; var __8 = (__2 < __1.length); if (__8) { i = __1[__2++]; return (function __$scm_doGetRepositories__6(__then) {
+ var __1 = __forIn(orgs); var __2 = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$scm_doGetRepositories__7() { __more = false; var __8 = (__2 < __1.length); if (__8) { i = __1[__2++]; return (function __$scm_doGetRepositories__7(__then) {
if (orgs.hasOwnProperty(i)) {
- org = orgs[i]; return (function __$scm_doGetRepositories__6(__then) {
+ org = orgs[i]; return (function __$scm_doGetRepositories__7(__then) {
if (org.login) {
return context.github.repos.getFromOrg({ org: org.login }, __cb(_, __frame, 11, 20, function ___(__0, __5) { repos = __5;
- userRepos = userRepos.concat(repos); __then(); }, true)); } else { __then(); } ; })(__then); } else { __then(); } ; })(function __$scm_doGetRepositories__6() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$scm_doGetRepositories__6() { _(null, null, true); }); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doGetRepositories__6() {
+ userRepos = userRepos.concat(repos); __then(); }, true)); } else { __then(); } ; })(__then); } else { __then(); } ; })(function __$scm_doGetRepositories__7() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$scm_doGetRepositories__7() { _(null, null, true); }); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doGetRepositories__7() {
- progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$scm_doGetRepositories__6() {
+ progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$scm_doGetRepositories__7() {
return _(null, userRepos); }); }); }); };
- scm.doDeploymentsGet = function scm_doDeploymentsGet__7(context, _) { var maxItems, channel, progress, deployments; var __frame = { name: "scm_doDeploymentsGet__7", line: 243 }; return __func(_, this, arguments, scm_doDeploymentsGet__7, 1, __frame, function __$scm_doDeploymentsGet__7() {
+ scm.doDeploymentsGet = function scm_doDeploymentsGet__8(context, _) { var maxItems, channel, progress, deployments; var __frame = { name: "scm_doDeploymentsGet__8", line: 336 }; return __func(_, this, arguments, scm_doDeploymentsGet__8, 1, __frame, function __$scm_doDeploymentsGet__8() {
maxItems = parseInt(context.maxItems, 10);
if ((!maxItems || (maxItems <= 0))) {
maxItems = 20; } ;
@@ -251,55 +344,55 @@ exports.init = function(cli) {
channel = getScmChannel(context).path("deployments").query("$orderby", "ReceivedTime desc").query("$top", maxItems);
- progress = cli.progress("Enumerating deployments"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doDeploymentsGet__7() {
+ progress = cli.progress("Enumerating deployments"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doDeploymentsGet__8() {
return channel.GET(__cb(_, __frame, 13, 44, function ___(__0, __1) { deployments = ensureShortCommitId(__1);
- return cacheUtils.saveCommitIds(context, deployments, __cb(_, __frame, 14, 6, function __$scm_doDeploymentsGet__7() {
- return _(null, deployments.map(formatDeployment)); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doDeploymentsGet__7() {
+ return cacheUtils.saveCommitIds(context, deployments, __cb(_, __frame, 14, 6, function __$scm_doDeploymentsGet__8() {
+ return _(null, deployments.map(formatDeployment)); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doDeploymentsGet__8() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
- scm.doDeploymentGet = function scm_doDeploymentGet__8(context, _) { var channel, progress; var __frame = { name: "scm_doDeploymentGet__8", line: 264 }; return __func(_, this, arguments, scm_doDeploymentGet__8, 1, __frame, function __$scm_doDeploymentGet__8() {
+ scm.doDeploymentGet = function scm_doDeploymentGet__9(context, _) { var channel, progress; var __frame = { name: "scm_doDeploymentGet__9", line: 357 }; return __func(_, this, arguments, scm_doDeploymentGet__9, 1, __frame, function __$scm_doDeploymentGet__9() {
channel = getScmChannel(context).path("deployments").path(context.id);
- progress = cli.progress("Retrieving deployment info"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doDeploymentGet__8() {
+ progress = cli.progress("Retrieving deployment info"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doDeploymentGet__9() {
- return channel.GET(__cb(_, __frame, 6, 30, function ___(__0, __2) { var __1 = formatDeployment(__2); return _(null, __1); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doDeploymentGet__8() {
+ return channel.GET(__cb(_, __frame, 6, 30, function ___(__0, __2) { var __1 = formatDeployment(__2); return _(null, __1); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doDeploymentGet__9() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
- scm.doDeploymentPut = function scm_doDeploymentPut__9(context, _) { var channel, progress; var __frame = { name: "scm_doDeploymentPut__9", line: 276 }; return __func(_, this, arguments, scm_doDeploymentPut__9, 1, __frame, function __$scm_doDeploymentPut__9() {
+ scm.doDeploymentPut = function scm_doDeploymentPut__10(context, _) { var channel, progress; var __frame = { name: "scm_doDeploymentPut__10", line: 369 }; return __func(_, this, arguments, scm_doDeploymentPut__10, 1, __frame, function __$scm_doDeploymentPut__10() {
channel = getScmChannel(context).path("deployments").path(context.id);
- progress = cli.progress("Redeploying deployment"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doDeploymentPut__9() {
+ progress = cli.progress("Redeploying deployment"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doDeploymentPut__10() {
- return channel.PUT(null, __cb(_, __frame, 6, 13, _, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doDeploymentPut__9() {
+ return channel.PUT(null, __cb(_, __frame, 6, 13, _, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doDeploymentPut__10() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
- scm.doLogGet = function scm_doLogGet__10(context, _) { var channel, progress, logs; var __frame = { name: "scm_doLogGet__10", line: 288 }; return __func(_, this, arguments, scm_doLogGet__10, 1, __frame, function __$scm_doLogGet__10() {
+ scm.doLogGet = function scm_doLogGet__11(context, _) { var channel, progress, logs; var __frame = { name: "scm_doLogGet__11", line: 381 }; return __func(_, this, arguments, scm_doLogGet__11, 1, __frame, function __$scm_doLogGet__11() {
channel = getScmChannel(context).path("deployments").path(context.id).path("log");
- progress = cli.progress("Retrieving deployment log info"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doLogGet__10() {
+ progress = cli.progress("Retrieving deployment log info"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$scm_doLogGet__11() {
return channel.GET(__cb(_, __frame, 7, 17, function ___(__0, __1) { logs = __1;
- return _(null, logs.map(formatLog)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doLogGet__10() {
+ return _(null, logs.map(formatLog)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$scm_doLogGet__11() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, _); }); }); };
- function listDeployments(context, _) { var deployments, authorLength, messageLength; var __frame = { name: "listDeployments", line: 302 }; return __func(_, this, arguments, listDeployments, 1, __frame, function __$listDeployments() {
+ function listDeployments(context, _) { var deployments, authorLength, messageLength; var __frame = { name: "listDeployments", line: 395 }; return __func(_, this, arguments, listDeployments, 1, __frame, function __$listDeployments() {
return scm.doDeploymentsGet(context, __cb(_, __frame, 1, 22, function ___(__0, __1) { deployments = __1;
authorLength = 0; messageLength = 0;
if ((deployments && deployments.length)) {
@@ -317,13 +410,13 @@ exports.init = function(cli) {
- function getLogDetails(context, _) { var results, logs, progress, i; var __frame = { name: "getLogDetails", line: 320 }; return __func(_, this, arguments, getLogDetails, 1, __frame, function __$getLogDetails() {
+ function getLogDetails(context, _) { var results, logs, progress, i; var __frame = { name: "getLogDetails", line: 413 }; return __func(_, this, arguments, getLogDetails, 1, __frame, function __$getLogDetails() {
return scm.doLogGet(context, __cb(_, __frame, 2, 15, function ___(__0, __2) { logs = __2; return (function __$getLogDetails(__then) {
if ((logs && logs.length)) {
progress = cli.progress("Retrieving log details"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getLogDetails() {
- return async.map(logs, function __1(log, _) { var details; var __frame = { name: "__1", line: 326 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() { return (function __$__1(__then) {
+ return async.map(logs, function __1(log, _) { var details; var __frame = { name: "__1", line: 419 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() { return (function __$__1(__then) {
if (log.hasDetails) {
@@ -416,7 +509,7 @@ exports.init = function(cli) {
- function ensureRepositoryUri(context, _) { var siteData, repositoryUri; var __frame = { name: "ensureRepositoryUri", line: 419 }; return __func(_, this, arguments, ensureRepositoryUri, 1, __frame, function __$ensureRepositoryUri() {
+ function ensureRepositoryUri(context, _) { var siteData, repositoryUri; var __frame = { name: "ensureRepositoryUri", line: 512 }; return __func(_, this, arguments, ensureRepositoryUri, 1, __frame, function __$ensureRepositoryUri() {
return site.lookupSiteNameAndWebSpace(context, __cb(_, __frame, 1, 19, function ___(__0, __1) { siteData = __1;
repositoryUri = (siteData && site.getRepositoryUri(siteData)); return (function __$ensureRepositoryUri(__then) {
if (!repositoryUri) {
@@ -454,4 +547,11 @@ exports.init = function(cli) {
log.type = logTypeText(log.type);
log.shortId = log.id.substr(0, 10);
delete log.details_url;
- return log; };};
+ return log; };
+
+
+ function exec(cmd, cb) {
+ child_process.exec(cmd, function(err, stdout, stderr) {
+ cb(err, {
+ stdout: stdout,
+ stderr: stderr }); }); };};
View
146 lib/cli/commands/deployment_.js
@@ -172,48 +172,141 @@ exports.init = function (cli) {
}
});
- scm.command('github')
+ scm.command('github [name]')
.whiteListPowershell()
.usage('[options]')
.description('Redeploy your git deployment')
- .execute(function (options, _) {
+ .execute(function (nameArg, options, _) {
var context = {
- subscription: cli.category('account').lookupSubscriptionId(options.subscription)
+ subscription: cli.category('account').lookupSubscriptionId(options.subscription),
+ site: {
+ name: nameArg
+ }
};
- log.help('Enter your github credentials');
- context.username = prompt('username: ', _);
- context.password = prompt('password: ', _);
-
- context.github = new GitHubApi({ version: "3.0.0" });
- context.github.authenticate({
- type: "basic",
- username: context.username,
- password: context.password
- });
-
+ // Fetch site and repository data
+ ensureRepositoryUri(context, _);
+ promptForCredentials(_);
promptForRepository(_);
+ linkRemoteGitRepo(_);
+ addRemoteToLocalGitRepo(_);
+
+ function promptForCredentials(_) {
+ log.help('Enter your github credentials');
+ context.username = prompt('username: ', _);
+ context.password = prompt('password: ', _);
+
+ context.github = new GitHubApi({ version: "3.0.0" });
+ context.github.authenticate({
+ type: "basic",
+ username: context.username,
+ password: context.password
+ });
+ }
function promptForRepository(_) {
var repositories = scm.doGetRepositories(context, _);
- log.help('Choose a repository');
- context.repository = repositories[choose(repositories.map(function (repository) {
- var repoUrl = url.parse(repository.git_url);
- return repoUrl.pathname;
- }), _)];
+
+ var githubUri = scm.doGetGitOriginUri(context, _);
+ if (githubUri) {
+ var parsedRepositoryUri = url.parse(githubUri);
+ 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) {
+ // Attempt manual repository
+ // TODO: consider just failing ?
+ // throw new Error('Invalid repository');
+ context.repository = {
+ name: name,
+ owner: {
+ login: owner
+ }
+ }
+ }
+ }
+ }
+
+ 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';
+ console.log(parsedRepositoryUri);
+ var hookUrl = url.format(parsedRepositoryUri);
+
+ context.hook = {
+ name: 'web',
+ user: context.repository.name,
+ repo: context.repository.owner.login,
+ active: true,
+ events: [ 'push' ],
+ config: {
+ url: hookUrl,
+ content_type: 'json'
+ }
+ };
+
+ scm.doCreateHook(context, _);
+ }
+ function addRemoteToLocalGitRepo(_) {
+ }
+ });
scm.doCreateHook = function (context, _) {
- var progress = cli.progress('Retrieving repositories');
+ var progress = cli.progress('Creating hook');
+
+ var msg = {
+ user: context.repository.owner.login,
+ repo: context.repository.name
+ };
+
+ console.log(context.hook);
+ console.log(msg);
+ try {
+ context.github.repos.createHook(msg, context.hook, _);
+ } finally {
+ progress.end();
+ }
+ };
+
+ scm.doGetGitOriginUri = function (context, _) {
+ var progress = cli.progress('Getting local git repositories');
+ var originUri = null;
try {
- context.github.repos.getHooks({ repo: context.repoPath })
+ 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 === 'origin';
+ });
+ });
+
+ if (origin && origin.length > 0) {
+ originUri = origin[0].split('\t')[1].split(' ')[0];
+ }
} finally {
progress.end();
}
+
+ return originUri;
};
scm.doGetRepositories = function (context, _) {
@@ -456,4 +549,13 @@ exports.init = function (cli) {
delete log.details_url;
return log;
}
+
+ function exec(cmd, cb) {
+ child_process.exec(cmd, function (err, stdout, stderr) {
+ cb(err, {
+ stdout: stdout,
+ stderr: stderr
+ });
+ });
+ }
};
Please sign in to comment.
Something went wrong with that request. Please try again.