Skip to content
This repository

Github support #394

Merged
merged 56 commits into from over 1 year ago

2 participants

André Rodrigues Chris Tavares
André Rodrigues
Collaborator

No description provided.

added some commits October 18, 2012
André Rodrigues prototyping github hooks 0855816
André Rodrigues Adding repository selection 1b83805
André Rodrigues Adding hooks 87cddfe
André Rodrigues Fix issue with hook linking a628487
André Rodrigues Improving existing hook detection logic 8276ea8
André Rodrigues Improving existing hook detection logic 909858e
André Rodrigues Removing forgotten console.log 144be8d
André Rodrigues Fixing small issue with remote repository tracking 3883ae8
André Rodrigues Adding username and password parameters 9fe4b55
André Rodrigues locking node-github version to avoid future breaking change 95fb4fc
André Rodrigues locking node-github version to avoid future breaking change cd547ad
André Rodrigues Separating github deployment command. 159c5a8
André Rodrigues Factoring out git functions. cccbef2
André Rodrigues Extracting generic code. 1bfd174
André Rodrigues Adding azure site create --github c5499d0
André Rodrigues Removing forgotten console.logs da7cd73
André Rodrigues fix reference 2ee47c2
André Rodrigues adding UT cef24f9
André Rodrigues Fixing wrong reference. 5577072
André Rodrigues Fixing issue with password input 3f827ac
André Rodrigues Switch to insecure SSL. c999da1
André Rodrigues Fixing hook type issue. 8a30845
André Rodrigues Adding oauth authentication mechanism. aa32a3c
André Rodrigues Running streamline. 1fb4387
André Rodrigues Removing console.log b4eef91
André Rodrigues Fixing location bug in sites 93147d4
André Rodrigues Fixing null reference 1cc35fb
André Rodrigues Creating cli test list 222cca8
André Rodrigues Removing gitdeployment file fab8be7
André Rodrigues Fix UT 4249605
André Rodrigues Adding UT 13a7945
André Rodrigues Adding UT 668a397
André Rodrigues Fix ut issue with missing site name 11f0ce6
André Rodrigues Rename UT Suite 5c5bcfb
André Rodrigues Aligning behavior to powershell 5ed9541
André Rodrigues Updating site.js 12bc14a
André Rodrigues Adding publishing username to site create to align to powershell a506086
André Rodrigues Adding UT b5f942f
André Rodrigues Improving parameter comments 839d92e
André Rodrigues Fix issue with credentials prompting 78ea532
André Rodrigues Fixing invalid ref a32e167
André Rodrigues Improving informational message 3cc8b1c
André Rodrigues Regenerating site.js 11f10cc
André Rodrigues improving status message 2295da7
André Rodrigues Fixing issue with spaces fetching 6a4510a
André Rodrigues Fixing issue with webspace matching e26862d
André Rodrigues fixing typo 342e9dd
André Rodrigues Applying review comments. c7d9844
André Rodrigues Improving UT. 1f9cd6f
André Rodrigues Merge pull request #13 from andrerod/github
Github
0142328
André Rodrigues Fix broken reference b62156d
lib/cli/linkedrevisioncontrol_.js
((32 lines not shown))
  32
+    default:
  33
+      throw new Error('Invalid client');
  34
+  }
  35
+};
  36
+
  37
+exports.LinkedRevisionControlClient = LinkedRevisionControlClient;
  38
+exports.GithubClient = GithubClient;
  39
+exports.GitClient = GitClient;
  40
+
  41
+function LinkedRevisionControlClient(cli) {
  42
+  this.cli = cli;
  43
+}
  44
+
  45
+LinkedRevisionControlClient.getRepository = function (repositories, remoteUri) {
  46
+  var parsedRepositoryUri = url.parse(remoteUri);
  47
+  var pathParts = parsedRepositoryUri.pathname.split('/');
1
André Rodrigues Collaborator
andrerod added a note October 23, 2012

Check initial slash. Consider comparing full name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
André Rodrigues andrerod commented on the diff October 23, 2012
lib/cli/linkedrevisioncontrol_.js
((27 lines not shown))
  27
+      return new GithubClient(cli);
  28
+      break;
  29
+    case 'git':
  30
+      return new GitClient(cli);
  31
+      break;
  32
+    default:
  33
+      throw new Error('Invalid client');
  34
+  }
  35
+};
  36
+
  37
+exports.LinkedRevisionControlClient = LinkedRevisionControlClient;
  38
+exports.GithubClient = GithubClient;
  39
+exports.GitClient = GitClient;
  40
+
  41
+function LinkedRevisionControlClient(cli) {
  42
+  this.cli = cli;
1
André Rodrigues Collaborator
andrerod added a note October 23, 2012

Use this.log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/cli/linkedrevisioncontrol_.js
((166 lines not shown))
  166
+  if (!context.password) {
  167
+    context.password = promptPassword(this.cli, 'Password: ', _);
  168
+  }
  169
+};
  170
+
  171
+GithubClient.prototype.init = function (context, _) {
  172
+  this.authenticate(context, _);
  173
+
  174
+  this.determineIfCurrentDirectoryIsGitWorkingTree(context, _);
  175
+  this.initGitOnCurrentDirectory(context, false, _);
  176
+
  177
+  var repositories = this.getRepositories(context.username, _);
  178
+
  179
+  if (!context.remoteUri) {
  180
+    // Look for git repository in local git remotes
  181
+    context.remoteUri = this._getRemoteUri(_);
1
André Rodrigues Collaborator
andrerod added a note October 23, 2012

Ask glenn about azure / origin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/cli/linkedrevisioncontrol_.js
((173 lines not shown))
  173
+
  174
+  this.determineIfCurrentDirectoryIsGitWorkingTree(context, _);
  175
+  this.initGitOnCurrentDirectory(context, false, _);
  176
+
  177
+  var repositories = this.getRepositories(context.username, _);
  178
+
  179
+  if (!context.remoteUri) {
  180
+    // Look for git repository in local git remotes
  181
+    context.remoteUri = this._getRemoteUri(_);
  182
+  }
  183
+
  184
+  if (context.remoteUri) {
  185
+    context.repository = LinkedRevisionControlClient.getRepository(repositories, context.remoteUri);
  186
+  }
  187
+
  188
+  if ((context.flags && context.flags.forceRepositorySelection) || !context.repository) {
1
André Rodrigues Collaborator
andrerod added a note October 23, 2012

Force selection should be moved upwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/cli/linkedrevisioncontrol_.js
((186 lines not shown))
  186
+  }
  187
+
  188
+  if ((context.flags && context.flags.forceRepositorySelection) || !context.repository) {
  189
+    // Look for git repository in github
  190
+    this.cli.output.help('Choose a repository');
  191
+    context.repository = repositories[choose(this.cli, repositories.map(function (repository) {
  192
+      return repository.full_name;
  193
+    }), _)];
  194
+  }
  195
+};
  196
+
  197
+GithubClient.prototype.deploy = function (context, _) {
  198
+  var parsedRepositoryUri = url.parse(context.repositoryUri);
  199
+  parsedRepositoryUri.auth = context.repositoryAuth;
  200
+  parsedRepositoryUri.pathname = '/deploy';
  201
+  var hookUrl = url.format(parsedRepositoryUri).replace('https://%24', 'https://$');
2
André Rodrigues Collaborator
andrerod added a note October 23, 2012

Add code comment to explain this.

André Rodrigues Collaborator
andrerod added a note October 23, 2012

Move format part inside the createOrUpdate and pass the object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/cli/linkedrevisioncontrol_.js
((217 lines not shown))
  217
+      this._exec('git remote rm azure', _);
  218
+    }
  219
+  }
  220
+
  221
+  if (!context.remoteUri) {
  222
+    // create the remote repo locally
  223
+    this.cli.output.info('Executing `git remote add azure ' + gitUri + '`');
  224
+    this._exec('git remote add azure ' + gitUri, _);
  225
+  }
  226
+};
  227
+
  228
+GithubClient.prototype.getRepositories = function (username, _) {
  229
+  var progress = this.cli.progress('Retrieving repositories');
  230
+  var userRepos = [];
  231
+
  232
+  function sortFunction (repositoryA, repositoryB) {
1
André Rodrigues Collaborator
andrerod added a note October 23, 2012

SortByFullName

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
André Rodrigues andrerod commented on the diff October 23, 2012
test/cli/commands/cli.deployment-tests.js
((115 lines not shown))
  115
+            // verify that the hook is in github
  116
+            githubClient.repos.getFromUser({ user: githubUsername }, function (err, repositories) {
  117
+              var repository = LinkedRevisionControlClient.getRepository(repositories, githubRepositoryUri);
  118
+
  119
+              githubClient.repos.getHooks({
  120
+                user: githubUsername,
  121
+                repo: repository.name
  122
+              }, function (err, hooks) {
  123
+                var hookExists = hooks.some(function (hook) {
  124
+                  var parsedUrl = url.parse(hook.config.url);
  125
+                  return parsedUrl.hostname === (siteName + '.scm.azurewebsites.net');
  126
+                });
  127
+
  128
+                hookExists.should.be.ok;
  129
+
  130
+                // Delete created site
1
André Rodrigues Collaborator
andrerod added a note October 23, 2012

Consider moving to tear down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
test/cli/commands/cli.site-tests.js
((46 lines not shown))
  55
+      githubClient.repos.getFromUser({ user: githubUsername }, function (err, repositories) {
  56
+        repositoryName = LinkedRevisionControlClient.getRepository(repositories, githubRepositoryUri).name;
  57
+
  58
+        githubClient.repos.getHooks({
  59
+          user: githubUsername,
  60
+          repo: repositoryName
  61
+        }, function (err, hooks) {
  62
+          deleteAllHooks(hooks, done);
  63
+        });
  64
+      });
  65
+    });
  66
+
  67
+    test('site create', function(done) {
  68
+      var siteName = 'cliuttestsite1';
  69
+
  70
+      // Setup
1
André Rodrigues Collaborator
andrerod added a note October 23, 2012

Dead code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
test/cli/commands/cli.site-tests.js
((223 lines not shown))
  226
+      capture(function() {
  227
+        cli.parse(cmd);
  228
+      }, function (result) {
  229
+        result.text.should.equal('');
  230
+        result.exitStatus.should.equal(0);
  231
+
  232
+        // Rerun to make sure update hook works properly
  233
+        capture(function() {
  234
+          cli.parse(cmd);
  235
+        }, function (result) {
  236
+          result.text.should.equal('');
  237
+          result.exitStatus.should.equal(0);
  238
+
  239
+          // List sites
  240
+          cmd = 'node cli.js site list --json'.split(' ');
  241
+          cmd.push('--github');
1
André Rodrigues Collaborator
andrerod added a note October 23, 2012

Needs to be moved up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
André Rodrigues andrerod commented on the diff October 23, 2012
test/cli/linkrevisioncontrol-tests.js
((51 lines not shown))
  51
+
  52
+      // Test
  53
+      githubClient._getRemoteUri(function (err, url) {
  54
+        // Assert
  55
+        url.should.equal('git://github.com/andrerod/mynewsite999.git');
  56
+
  57
+        done();
  58
+      });
  59
+    });
  60
+
  61
+    test('should get remote origin uri', function(done) {
  62
+      // Setup
  63
+      var originUrl = { 
  64
+        stdout: 'origin\tgit://github.com/andrerod/mynewsite999.git (fetch)\n' +
  65
+                'origin\tgit://github.com/andrerod/mynewsite999.git (push)\n',
  66
+        stderr: '' 
1
André Rodrigues Collaborator
andrerod added a note October 23, 2012

Add one more UT for both origin and azure and see that it picks the azure one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Chris Tavares christav commented on the diff October 23, 2012
lib/cli/commands/site_.js
((27 lines not shown))
140  
-          createSiteAndInitializeRemoteRepo(_);
141  
-          addRemoteToLocalGitRepo(_);
  153
+          createSite(_);
  154
+
  155
+          // Init git / github linking
  156
+          if (options.git || options.github) {
  157
+            if (options.github) {
  158
+              context.lvcClient = linkedRevisionControl.createClient(cli, 'github');
  159
+            } else if (options.git) {
  160
+              context.lvcClient = linkedRevisionControl.createClient(cli, 'git');
  161
+            }
  162
+
  163
+            context.lvcClient.init(context, _);
  164
+
  165
+            // Scaffold
  166
+            copyIisNodeWhenServerJsPresent(_);
2
Chris Tavares Collaborator
christav added a note October 23, 2012

Wasn't this going to be moved upwards out of this if block?

André Rodrigues Collaborator
andrerod added a note October 23, 2012

If we do decide to move, it'll be the iisnode scaffolding. But we still havent settled. So for now its going to proceed with the same behavior as powershell. Follow up / stabilization / finalization issues will follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Chris Tavares
Collaborator

One question, otherwise LGTM

André Rodrigues andrerod merged commit 80254cc into from October 23, 2012
André Rodrigues andrerod closed this October 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 56 unique commits by 1 author.

Oct 18, 2012
André Rodrigues prototyping github hooks 0855816
André Rodrigues Adding repository selection 1b83805
André Rodrigues Adding hooks 87cddfe
André Rodrigues Fix issue with hook linking a628487
André Rodrigues Improving existing hook detection logic 8276ea8
André Rodrigues Improving existing hook detection logic 909858e
André Rodrigues Removing forgotten console.log 144be8d
André Rodrigues Fixing small issue with remote repository tracking 3883ae8
André Rodrigues Adding username and password parameters 9fe4b55
André Rodrigues locking node-github version to avoid future breaking change 95fb4fc
Oct 19, 2012
André Rodrigues locking node-github version to avoid future breaking change cd547ad
André Rodrigues Separating github deployment command. 159c5a8
André Rodrigues Factoring out git functions. cccbef2
André Rodrigues Extracting generic code. 1bfd174
André Rodrigues Adding azure site create --github c5499d0
André Rodrigues Removing forgotten console.logs da7cd73
André Rodrigues fix reference 2ee47c2
André Rodrigues adding UT cef24f9
André Rodrigues Fixing wrong reference. 5577072
André Rodrigues Fixing issue with password input 3f827ac
Oct 20, 2012
André Rodrigues Switch to insecure SSL. c999da1
André Rodrigues Fixing hook type issue. 8a30845
André Rodrigues Adding oauth authentication mechanism. aa32a3c
André Rodrigues Running streamline. 1fb4387
Oct 21, 2012
André Rodrigues Removing console.log b4eef91
André Rodrigues Fixing location bug in sites 93147d4
Oct 22, 2012
André Rodrigues Fixing null reference 1cc35fb
André Rodrigues Creating cli test list 222cca8
André Rodrigues Removing gitdeployment file fab8be7
André Rodrigues Fix UT 4249605
André Rodrigues Adding UT 13a7945
André Rodrigues Adding UT 668a397
André Rodrigues Fix ut issue with missing site name 11f0ce6
André Rodrigues Rename UT Suite 5c5bcfb
André Rodrigues Aligning behavior to powershell 5ed9541
André Rodrigues Updating site.js 12bc14a
André Rodrigues Adding publishing username to site create to align to powershell a506086
André Rodrigues Adding UT b5f942f
André Rodrigues Improving parameter comments 839d92e
André Rodrigues Fix issue with credentials prompting 78ea532
André Rodrigues Fixing invalid ref a32e167
André Rodrigues Improving informational message 3cc8b1c
André Rodrigues Regenerating site.js 11f10cc
André Rodrigues improving status message 2295da7
André Rodrigues Fixing issue with spaces fetching 6a4510a
André Rodrigues Fixing issue with webspace matching e26862d
André Rodrigues fixing typo 342e9dd
André Rodrigues Merge pull request #13 from andrerod/github
Github
0142328
Oct 23, 2012
André Rodrigues Applying review comments. c7d9844
André Rodrigues Improving UT. 1f9cd6f
André Rodrigues Fix broken reference b62156d
André Rodrigues Applying more code review comments ad598c8
André Rodrigues Applying more code review comments d18853b
André Rodrigues Applying more code review comments 2981980
André Rodrigues Fixing references 60d29d3
André Rodrigues remove dead code 3cc26ec
Something went wrong with that request. Please try again.