/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch,__forIn=__rt.__forIn; var url = require("url");
















var fs = require("fs");
var util = require("util");
var GitHubApi = require("github");

var utils = require("../utils");
var $ = utils.getLocaleString;

var WebsitesClient = require("../../commands/asm/websites/websitesclient");


var child_process = require("child_process");

exports.createClient = function(cli, name, websitesClient) {
  switch (name) {
  case "github": return new GithubClient(cli, websitesClient);
  case "git":
    return new GitClient(cli, websitesClient);
    default:
    throw new Error("Invalid client");
  };};



exports.LinkedRevisionControlClient = LinkedRevisionControlClient;
exports.GithubClient = GithubClient;
exports.GitClient = GitClient;

function LinkedRevisionControlClient(cli, websitesClient) {
  this.cli = cli;
  this.websitesClient = websitesClient;
  this.log = cli.output;};









LinkedRevisionControlClient._getRepository = function(repositories, remoteFullName) {
  return repositories.filter(function(repository) {
    return (repository.full_name === remoteFullName);
  })[0];};









LinkedRevisionControlClient._getRepositoryCloneUrl = function(repositories, remoteUri) {
  return repositories.filter(function(repository) {
    return repositoryMatchUri(repository, remoteUri);
  })[0];};


function repositoryMatchUri(repository, remoteUri) {
  var cleanUri = url.parse(remoteUri);

  delete cleanUri.auth;
  cleanUri = url.format(cleanUri);

  return ((((repository.clone_url.toLowerCase() === cleanUri.toLowerCase()) || (repository.html_url.toLowerCase() === cleanUri.toLowerCase())) || (repository.ssh_url.toLowerCase() === cleanUri.toLowerCase())) || (repository.git_url.toLowerCase() === cleanUri.toLowerCase()));};








LinkedRevisionControlClient.prototype.determineIfCurrentDirectoryIsGitWorkingTree = function LinkedRevisionControlClient_prototype_determineIfCurrentDirectoryIsGitWorkingTree__1(context, _) { var isInsideWorkTree, lines, __this = this; var __frame = { name: "LinkedRevisionControlClient_prototype_determineIfCurrentDirectoryIsGitWorkingTree__1", line: 92 }; return __func(_, this, arguments, LinkedRevisionControlClient_prototype_determineIfCurrentDirectoryIsGitWorkingTree__1, 1, __frame, function __$LinkedRevisionControlClient_prototype_determineIfCurrentDirectoryIsGitWorkingTree__1() {
    __this.log.silly("determineIfCurrentDirectoryIsGitWorkingTree"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$LinkedRevisionControlClient_prototype_determineIfCurrentDirectoryIsGitWorkingTree__1() {


          return __this._exec("git rev-parse --git-dir", __cb(_, __frame, 4, 32, function ___(__0, __1) { isInsideWorkTree = __1;
            lines = (isInsideWorkTree.stdout + isInsideWorkTree.stderr);
            if (!context.flags) {
              context.flags = { }; } ;


            context.flags.isGitWorkingTree = lines.split("\n").some(function(line) {
              return (line === ".git"); }); __then(); }, true)); }); })(function ___(err, __result) { __catch(function __$LinkedRevisionControlClient_prototype_determineIfCurrentDirectoryIsGitWorkingTree__1() { if (err) {


            context.flags.isGitWorkingTree = false; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$LinkedRevisionControlClient_prototype_determineIfCurrentDirectoryIsGitWorkingTree__1() { _(); }); }); });};



LinkedRevisionControlClient.prototype.scaffoldGitIgnore = function LinkedRevisionControlClient_prototype_scaffoldGitIgnore__2(_) { var __frame = { name: "LinkedRevisionControlClient_prototype_scaffoldGitIgnore__2", line: 110 }; return __func(_, this, arguments, LinkedRevisionControlClient_prototype_scaffoldGitIgnore__2, 0, __frame, function __$LinkedRevisionControlClient_prototype_scaffoldGitIgnore__2() { return (function __$LinkedRevisionControlClient_prototype_scaffoldGitIgnore__2(__then) {
      if (!fs.existsSync(".gitignore")) {
        return fs.writeFile(".gitignore", "node_modules\nazure.err\n*.publishsettings", __cb(_, __frame, 2, 7, __then, true)); } else { __then(); } ; })(_); });};






LinkedRevisionControlClient.prototype.initGitOnCurrentDirectory = function LinkedRevisionControlClient_prototype_initGitOnCurrentDirectory__3(context, scaffold, _) { var __this = this; var __frame = { name: "LinkedRevisionControlClient_prototype_initGitOnCurrentDirectory__3", line: 119 }; return __func(_, this, arguments, LinkedRevisionControlClient_prototype_initGitOnCurrentDirectory__3, 2, __frame, function __$LinkedRevisionControlClient_prototype_initGitOnCurrentDirectory__3() {
    __this.log.silly("initGitOnCurrentDirectoryIfNeeded"); return (function __$LinkedRevisionControlClient_prototype_initGitOnCurrentDirectory__3(__then) {
      if (!context.flags.isGitWorkingTree) {
        __this.log.info("Executing `git init`");
        return __this._exec("git init", __cb(_, __frame, 4, 9, function __$LinkedRevisionControlClient_prototype_initGitOnCurrentDirectory__3() {

          context.flags.isGitWorkingTree = true; __then(); }, true)); } else { __then(); } ; })(function __$LinkedRevisionControlClient_prototype_initGitOnCurrentDirectory__3() { return (function __$LinkedRevisionControlClient_prototype_initGitOnCurrentDirectory__3(__then) {


        if (scaffold) {
          return __this.scaffoldGitIgnore(__cb(_, __frame, 10, 9, __then, true)); } else { __then(); } ; })(_); }); });};



LinkedRevisionControlClient.prototype._exec = function(cmd, cb) {
  child_process.exec(cmd, function(err, stdout, stderr) {
    cb(err, {
      stdout: stdout,
      stderr: stderr }); });};




LinkedRevisionControlClient.prototype._initializeRemoteRepos = function LinkedRevisionControlClient_prototype__initializeRemoteRepos__4(context, _) { var self, __this = this; var __frame = { name: "LinkedRevisionControlClient_prototype__initializeRemoteRepos__4", line: 142 }; return __func(_, this, arguments, LinkedRevisionControlClient_prototype__initializeRemoteRepos__4, 1, __frame, function __$LinkedRevisionControlClient_prototype__initializeRemoteRepos__4() { self = __this;


    self.log.silly("InitializeRemoteRepo"); return (function __$LinkedRevisionControlClient_prototype__initializeRemoteRepos__4(__then) {
      if (!context.flags.siteExists) {
        return self.websitesClient.createRepository(context, __cb(_, __frame, 5, 24, function __$LinkedRevisionControlClient_prototype__initializeRemoteRepos__4() {
          return self.websitesClient.getRepository(context, __cb(_, __frame, 6, 39, function ___(__0, __1) { context.repo = __1; __then(); }, true)); }, true)); } else {

        return self.websitesClient.getRepository(context, __cb(_, __frame, 8, 39, function ___(__0, __2) { context.repo = __2; return (function __$LinkedRevisionControlClient_prototype__initializeRemoteRepos__4(__then) {
            if (!context.repo) {
              return self.websitesClient.createRepository(context, __cb(_, __frame, 10, 26, function __$LinkedRevisionControlClient_prototype__initializeRemoteRepos__4() {
                return self.websitesClient.getRepository(context, __cb(_, __frame, 11, 41, function ___(__0, __3) { context.repo = __3; __then(); }, true)); }, true)); } else { __then(); } ; })(__then); }, true)); } ; })(function __$LinkedRevisionControlClient_prototype__initializeRemoteRepos__4() {



      self.log.silly("context.repo", context.repo); _(); }); });};


LinkedRevisionControlClient.prototype._addRemotesToLocalGitRepo = function LinkedRevisionControlClient_prototype__addRemotesToLocalGitRepo__5(context, _) { var self, remotes, azureExists, gitUri, __this = this; var __frame = { name: "LinkedRevisionControlClient_prototype__addRemotesToLocalGitRepo__5", line: 160 }; return __func(_, this, arguments, LinkedRevisionControlClient_prototype__addRemotesToLocalGitRepo__5, 1, __frame, function __$LinkedRevisionControlClient_prototype__addRemotesToLocalGitRepo__5() { self = __this;


    if (context.site.slot) {
      context.site.localGitRemote = util.format("azure-%s", context.site.slot); }
     else {
      context.site.localGitRemote = "azure"; } ;


    self.log.silly("addRemoteToLocalGitRepo");
    if (!context.flags.isGitWorkingTree) {
      self.log.info((("To create a local git repository to publish to the remote site, please rerun this command with the --git flag: \"azure site create " + ((((context.site && context.site.name)) || "{site name}"))) + " --git\".")); return _(null); } ; return (function __$LinkedRevisionControlClient_prototype__addRemotesToLocalGitRepo__5(__then) {



      if (!context.publishingUser) {
        return self.websitesClient.getPublishingUsers(context, __cb(_, __frame, 16, 50, function ___(__0, __1) { context.publishingUsers = __1;
          return self.websitesClient.getPublishingUser(context, __cb(_, __frame, 17, 49, function ___(__0, __2) { context.publishingUser = __2; __then(); }, true)); }, true)); } else { __then(); } ; })(function __$LinkedRevisionControlClient_prototype__addRemotesToLocalGitRepo__5() {


      self.log.verbose($("Detecting git and local git folder"));
      return __this._exec("git remote", __cb(_, __frame, 21, 21, function ___(__0, __3) { remotes = __3;
        azureExists = ((remotes.stdout + remotes.stderr)).split("\n").some(function(item) {
          return (item === context.site.localGitRemote); }); return (function __$LinkedRevisionControlClient_prototype__addRemotesToLocalGitRepo__5(__then) {


          if (azureExists) {
            self.log.verbose(util.format($("Removing existing %s remote alias"), context.site.localGitRemote));
            return __this._exec(util.format("git remote rm %s", context.site.localGitRemote), __cb(_, __frame, 28, 9, __then, true)); } else { __then(); } ; })(function __$LinkedRevisionControlClient_prototype__addRemotesToLocalGitRepo__5() {


          gitUri = self.websitesClient.getGitUri(context.repo, context.site.name, context.publishingUser);
          self.log.info(util.format($("Executing `git remote add %s %s`"), context.site.localGitRemote, gitUri));
          return __this._exec(util.format("git remote add %s %s", context.site.localGitRemote, gitUri), __cb(_, __frame, 33, 7, function __$LinkedRevisionControlClient_prototype__addRemotesToLocalGitRepo__5() {
            self.log.info(util.format($("A new remote, '%s', has been added to your local git repository"), context.site.localGitRemote));
            self.log.info(util.format($("Use git locally to make changes to your site, commit, and then use 'git push %s master' to deploy to Azure"), context.site.localGitRemote)); _(); }, true)); }); }, true)); }); });};


function GitClient(cli, websitesClient) {
  GitClient.super_.call(this, cli, websitesClient);};


util.inherits(GitClient, LinkedRevisionControlClient);

GitClient.prototype.init = function GitClient_prototype_init__6(context, _) { var __this = this; var __frame = { name: "GitClient_prototype_init__6", line: 204 }; return __func(_, this, arguments, GitClient_prototype_init__6, 1, __frame, function __$GitClient_prototype_init__6() {
    return __this.determineIfCurrentDirectoryIsGitWorkingTree(context, __cb(_, __frame, 1, 7, function __$GitClient_prototype_init__6() {
      return __this.initGitOnCurrentDirectory(context, true, __cb(_, __frame, 2, 7, function __$GitClient_prototype_init__6() { _(); }, true)); }, true)); });};



GitClient.prototype.deploy = function GitClient_prototype_deploy__7(context, _) { var self, __this = this; var __frame = { name: "GitClient_prototype_deploy__7", line: 210 }; return __func(_, this, arguments, GitClient_prototype_deploy__7, 1, __frame, function __$GitClient_prototype_deploy__7() { self = __this;


    return self._initializeRemoteRepos(context, __cb(_, __frame, 3, 7, function __$GitClient_prototype_deploy__7() {
      return self._addRemotesToLocalGitRepo(context, __cb(_, __frame, 4, 7, function __$GitClient_prototype_deploy__7() { _(); }, true)); }, true)); });};


function GithubClient(cli, websitesClient) {
  GithubClient.super_.call(this, cli, websitesClient);

  this.client = new GitHubApi({ version: "3.0.0" });};


util.inherits(GithubClient, LinkedRevisionControlClient);

GithubClient.prototype.authenticate = function GithubClient_prototype_authenticate__8(context, _) { var __this = this; var __frame = { name: "GithubClient_prototype_authenticate__8", line: 225 }; return __func(_, this, arguments, GithubClient_prototype_authenticate__8, 1, __frame, function __$GithubClient_prototype_authenticate__8() {
    return __this.ensureCredentials(context, __cb(_, __frame, 1, 7, function __$GithubClient_prototype_authenticate__8() {

      __this.client.authenticate({
        type: "basic",
        username: context.github.username,
        password: context.github.password }); _(); }, true)); });};



GithubClient.prototype.authenticateAuth = function GithubClient_prototype_authenticateAuth__9(context, _) { var oauthToken, __this = this; var __frame = { name: "GithubClient_prototype_authenticateAuth__9", line: 235 }; return __func(_, this, arguments, GithubClient_prototype_authenticateAuth__9, 1, __frame, function __$GithubClient_prototype_authenticateAuth__9() {
    return __this.ensureCredentials(context, __cb(_, __frame, 1, 7, function __$GithubClient_prototype_authenticateAuth__9() {

      __this.client.authenticate({
        type: "basic",
        username: context.github.username,
        password: context.github.password });



      return __this.client.oauth.createAuthorization({ user: context.github.username }, __cb(_, __frame, 10, 37, function ___(__0, __1) { oauthToken = __1;
        __this.client.authenticate({
          type: "oauth",
          token: oauthToken.token }); _(); }, true)); }, true)); });};



GithubClient.prototype.ensureCredentials = function GithubClient_prototype_ensureCredentials__10(context, _) { var __this = this; var __frame = { name: "GithubClient_prototype_ensureCredentials__10", line: 252 }; return __func(_, this, arguments, GithubClient_prototype_ensureCredentials__10, 1, __frame, function __$GithubClient_prototype_ensureCredentials__10() {
    if (!context.github) {
      context.github = { }; } ;


    if ((!context.github.username || !context.github.password)) {
      __this.log.help("Enter your github credentials"); } ; return (function __$GithubClient_prototype_ensureCredentials__10(__then) {


      if (!context.github.username) {
        return __this.cli.interaction.prompt("Username: ", __cb(_, __frame, 10, 51, function ___(__0, __1) { context.github.username = __1; __then(); }, true)); } else { __then(); } ; })(function __$GithubClient_prototype_ensureCredentials__10() { return (function __$GithubClient_prototype_ensureCredentials__10(__then) {


        if (!context.github.password) {
          return __this.cli.interaction.promptPasswordOnce("Password: ", __cb(_, __frame, 14, 51, function ___(__0, __2) { context.github.password = __2; __then(); }, true)); } else { __then(); } ; })(_); }); });};



GithubClient.prototype.init = function GithubClient_prototype_init__11(context, _) { var repositories, remoteUris, resultingRepositories, __this = this; var __frame = { name: "GithubClient_prototype_init__11", line: 270 }; return __func(_, this, arguments, GithubClient_prototype_init__11, 1, __frame, function __$GithubClient_prototype_init__11() {
    return __this.authenticate(context, __cb(_, __frame, 1, 7, function __$GithubClient_prototype_init__11() {


      return __this.determineIfCurrentDirectoryIsGitWorkingTree(context, __cb(_, __frame, 4, 7, function __$GithubClient_prototype_init__11() {


        return __this.getRepositories(context.github.username, __cb(_, __frame, 7, 26, function ___(__0, __1) { repositories = __1; return (function __$GithubClient_prototype_init__11(__then) {
            if (context.github.repositoryFullName) {


              context.github.repository = LinkedRevisionControlClient._getRepository(repositories, context.github.repositoryFullName);
              if (!context.github.repository) {
                __this.log.info(("Invalid repository " + context.github.repositoryFullName)); } ; __then(); } else { return (function __$GithubClient_prototype_init__11(__then) {

                if ((context.flags.isGitWorkingTree && !((context.flags && context.flags.forceRepositorySelection)))) {



                  return __this._getRemoteUris(__cb(_, __frame, 19, 26, function ___(__0, __2) { remoteUris = __2;

                    if ((remoteUris.length === 1)) {
                      context.github.repository = LinkedRevisionControlClient._getRepositoryCloneUrl(repositories, remoteUris[0]); } else {
                      if ((remoteUris.length > 0)) {

                        resultingRepositories = repositories.filter(function(repository) {
                          return remoteUris.some(function(remoteUri) {
                            return repositoryMatchUri(repository, remoteUri); }); });



                        if ((resultingRepositories.length > 0)) {
                          repositories = resultingRepositories; } ;


                        if ((repositories.length !== remoteUris.length)) {
                          __this.log.info("Some remote URIs were ignored. Currently only public repositories are supported."); } ;


                        if ((repositories.length === 1)) {
                          context.github.repository = repositories[0]; } ; } ; } ; __then(); }, true)); } else { __then(); } ; })(__then); } ; })(function __$GithubClient_prototype_init__11() { return (function __$GithubClient_prototype_init__11(__then) {




              if (!context.github.repository) {

                __this.log.help("Choose a repository (or hit ctrl-c to exit)");
                return __this.cli.interaction.choose(repositories.map(function(repository) {
                  return repository.full_name; }), __cb(_, __frame, 48, 66, function ___(__0, __3) { context.github.repository = repositories[__3]; __then(); }, true)); } else { __then(); } ; })(_); }); }, true)); }, true)); }, true)); });};




GithubClient.prototype.deploy = function GithubClient_prototype_deploy__12(context, _) { var self, __this = this; var __frame = { name: "GithubClient_prototype_deploy__12", line: 324 }; return __func(_, this, arguments, GithubClient_prototype_deploy__12, 1, __frame, function __$GithubClient_prototype_deploy__12() { self = __this;


    return self._initializeRemoteRepos(context, __cb(_, __frame, 3, 7, function __$GithubClient_prototype_deploy__12() {
      return self.websitesClient.ensureRepositoryUri(context, __cb(_, __frame, 4, 22, function __$GithubClient_prototype_deploy__12() {


        return context.lvcClient.createOrUpdateHook(context.github.repository.owner.login, context.github.repository.name, context.repositoryUri, context.repositoryAuth, __cb(_, __frame, 7, 20, function __$GithubClient_prototype_deploy__12() { _(); }, true)); }, true)); }, true)); });};






GithubClient.prototype.getRepositories = function GithubClient_prototype_getRepositories__13(username, _) { var progress, userRepos, orgRepos, orgs, i, org, repos, __this = this;



  function sortByFullName(repositoryA, repositoryB) {
    return repositoryA.full_name.toLowerCase().localeCompare(repositoryB.full_name.toLowerCase()); };



  function filterPrivate(repository) {
    return (repository["private"] !== true); }; var __frame = { name: "GithubClient_prototype_getRepositories__13", line: 338 }; return __func(_, this, arguments, GithubClient_prototype_getRepositories__13, 1, __frame, function __$GithubClient_prototype_getRepositories__13() { progress = __this.cli.interaction.progress("Retrieving repositories"); userRepos = []; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_getRepositories__13() {



          return __this.client.repos.getFromUser({ user: username }, __cb(_, __frame, 14, 34, function ___(__0, __3) { userRepos = __3.filter(filterPrivate).sort(sortByFullName);




            return __this.client.orgs.getFromUser({ user: username }, __cb(_, __frame, 19, 32, function ___(__0, __4) { orgs = __4; return (function __$GithubClient_prototype_getRepositories__13(__then) {
                if (orgs) {
                  orgRepos = [];
                  var __1 = __forIn(orgs); var __2 = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$GithubClient_prototype_getRepositories__13() { __more = false; var __8 = (__2 < __1.length); if (__8) { i = __1[__2++]; return (function __$GithubClient_prototype_getRepositories__13(__then) {
                          if (orgs.hasOwnProperty(i)) {
                            org = orgs[i]; return (function __$GithubClient_prototype_getRepositories__13(__then) {
                              if (org.login) {
                                return __this.client.repos.getFromOrg({ org: org.login, sort: "updated", desc: "desc" }, __cb(_, __frame, 26, 42, function ___(__0, __5) { repos = __5;

                                  orgRepos = orgRepos.concat(repos); __then(); }, true)); } else { __then(); } ; })(__then); } else { __then(); } ; })(function __$GithubClient_prototype_getRepositories__13() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); } else { __then(); } ; })(function __$GithubClient_prototype_getRepositories__13() {




                orgRepos = orgRepos.filter(filterPrivate).sort(sortByFullName);

                userRepos = userRepos.concat(orgRepos); _(null, null, true); }); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$GithubClient_prototype_getRepositories__13() {

            progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$GithubClient_prototype_getRepositories__13() {


        return _(null, userRepos); }); }); });};


GithubClient.prototype.createOrUpdateHook = function GithubClient_prototype_createOrUpdateHook__14(username, repository, websitesRepositoryUri, websitesRepositoryAuth, _) { var parsedRepositoryUri, deployUri, hooks, existingHook, newHook, __this = this; var __frame = { name: "GithubClient_prototype_createOrUpdateHook__14", line: 381 }; return __func(_, this, arguments, GithubClient_prototype_createOrUpdateHook__14, 4, __frame, function __$GithubClient_prototype_createOrUpdateHook__14() {

    parsedRepositoryUri = url.parse(websitesRepositoryUri);
    parsedRepositoryUri.auth = websitesRepositoryAuth;
    parsedRepositoryUri.pathname = "/deploy";




    deployUri = url.format(parsedRepositoryUri).replace("https://%24", "https://$");


    return __this.getHooks(username, repository, __cb(_, __frame, 12, 19, function ___(__0, __1) { hooks = __1;







      existingHook = hooks.filter(function(hook) { if (hook.config) { return ((hook.name === "web") && (url.parse(hook.config.url).hostname.toLowerCase() === parsedRepositoryUri.hostname.toLowerCase())); } ; return false; })[0]; return (function __$GithubClient_prototype_createOrUpdateHook__14(__then) {

        if (existingHook) { return (function __$GithubClient_prototype_createOrUpdateHook__14(__then) {

            if ((existingHook.config.url.toLowerCase() !== deployUri.toLowerCase())) {
              existingHook.config.url = deployUri;
              existingHook.user = username;
              existingHook.repo = repository;
              return __this.updateHook(existingHook, __cb(_, __frame, 28, 26, function ___(__0, __2) { existingHook = __2;
                existingHook.user = username;
                existingHook.repo = repository;
                return __this.testHook(existingHook, __cb(_, __frame, 31, 11, __then, true)); }, true)); } else {

              __this.log.info("Link already established"); __then(); } ; })(__then); } else {



          newHook = {
            name: "web",
            user: username,
            repo: repository,
            active: true,
            events: ["push",],
            config: {
              url: deployUri,
              insecure_ssl: "1",
              content_type: "form" } };



          return __this.createHook(newHook, __cb(_, __frame, 50, 19, function ___(__0, __3) { newHook = __3;
            newHook.user = username;
            newHook.repo = repository;
            return __this.testHook(newHook, __cb(_, __frame, 53, 9, __then, true)); }, true)); } ; })(_); }, true)); });};



GithubClient.prototype.createHook = function GithubClient_prototype_createHook__15(hook, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_createHook__15", line: 438 }; return __func(_, this, arguments, GithubClient_prototype_createHook__15, 1, __frame, function __$GithubClient_prototype_createHook__15() {
    progress = __this.cli.interaction.progress("Creating new hook"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_createHook__15() {


          return __this.client.repos.createHook(hook, __cb(_, __frame, 4, 29, _, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$GithubClient_prototype_createHook__15() {

            progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$GithubClient_prototype_createHook__15() { _(); }); }); });};



GithubClient.prototype.updateHook = function GithubClient_prototype_updateHook__16(hook, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_updateHook__16", line: 448 }; return __func(_, this, arguments, GithubClient_prototype_updateHook__16, 1, __frame, function __$GithubClient_prototype_updateHook__16() {
    progress = __this.cli.interaction.progress("Updating hook"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_updateHook__16() {


          return __this.client.repos.updateHook(hook, __cb(_, __frame, 4, 29, _, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$GithubClient_prototype_updateHook__16() {

            progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$GithubClient_prototype_updateHook__16() { _(); }); }); });};



GithubClient.prototype.testHook = function GithubClient_prototype_testHook__17(hook, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_testHook__17", line: 458 }; return __func(_, this, arguments, GithubClient_prototype_testHook__17, 1, __frame, function __$GithubClient_prototype_testHook__17() {
    progress = __this.cli.interaction.progress("Testing hook"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_testHook__17() {


          return __this.client.repos.testHook(hook, __cb(_, __frame, 4, 22, function __$GithubClient_prototype_testHook__17() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$GithubClient_prototype_testHook__17() {

            progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$GithubClient_prototype_testHook__17() { _(); }); }); });};



GithubClient.prototype.getHooks = function GithubClient_prototype_getHooks__18(username, repository, _) { var progress, __this = this; var __frame = { name: "GithubClient_prototype_getHooks__18", line: 468 }; return __func(_, this, arguments, GithubClient_prototype_getHooks__18, 2, __frame, function __$GithubClient_prototype_getHooks__18() {
    progress = __this.cli.interaction.progress("Retrieving website hooks"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype_getHooks__18() {


          return __this.client.repos.getHooks({
            user: username,
            repo: repository }, __cb(_, __frame, 4, 29, _, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$GithubClient_prototype_getHooks__18() {


            progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$GithubClient_prototype_getHooks__18() { _(); }); }); });};



GithubClient.prototype._getRemoteUris = function GithubClient_prototype__getRemoteUris__19(_) { var progress, remoteUris, remotes, __this = this; var __frame = { name: "GithubClient_prototype__getRemoteUris__19", line: 481 }; return __func(_, this, arguments, GithubClient_prototype__getRemoteUris__19, 0, __frame, function __$GithubClient_prototype__getRemoteUris__19() {
    progress = __this.cli.interaction.progress("Retrieving local git repositories");
    remoteUris = []; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$GithubClient_prototype__getRemoteUris__19() {


          return __this._exec("git remote -v", __cb(_, __frame, 5, 23, function ___(__0, __1) { remotes = __1;
            remoteUris = ((remotes.stdout + remotes.stderr)).split("\n").filter(function(line) {

              return (line.length > 0);

            }).map(function(item) {
              return item.split("	")[1].split(" ")[0]; });


            remoteUris = removeDuplicates(remoteUris); _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$GithubClient_prototype__getRemoteUris__19() {

            progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$GithubClient_prototype__getRemoteUris__19() {


        return _(null, remoteUris); }); }); });};


function removeDuplicates(array) {
  return array.filter(function(elem, pos) {
    return (array.indexOf(elem) === pos); });};
