Permalink
Browse files

Applying more code review comments

  • Loading branch information...
1 parent ad598c8 commit d18853b336dab408a70c62691a2e99b4f1b464c6 Andre Rodrigues committed Oct 23, 2012
Showing with 43 additions and 31 deletions.
  1. +43 −31 lib/cli/linkedrevisioncontrol_.js
@@ -205,30 +205,31 @@ GithubClient.prototype.init = function (context, _) {
};
GithubClient.prototype.deploy = function (context, _) {
- var parsedRepositoryUri = url.parse(context.repositoryUri);
- parsedRepositoryUri.auth = context.repositoryAuth;
- parsedRepositoryUri.pathname = '/deploy';
- var hookUrl = url.format(parsedRepositoryUri).replace('https://%24', 'https://$');
context.lvcClient.createOrUpdateHook(context.repository.owner.login,
- context.repository.name,
- hookUrl,
+ context.github.repository.name,
+ context.repositoryUri,
+ context.repositoryAuth,
_);
+ // Append the username to the git url
var parsedCloneUrl = url.parse(context.repository.clone_url);
parsedCloneUrl.auth = context.username;
var gitUri = url.format(parsedCloneUrl);
- if (context.remoteUri && context.remoteUri.toLowerCase() !== gitUri.toLowerCase()) {
- context.remoteUri = null;
+ // If there was a previously defined repository and the url doesn't match
+ if (context.github.repositoryFullName && context.github.repositoryFullName.toLowerCase() !== gitUri.toLowerCase()) {
+ // Reset it so that it is forced that a new one is to be created
+ context.github.repositoryFullName = null;
+ // Remove the previous one in case it existed as azure
var azureRemote = this._getRemote('azure', _);
if (azureRemote) {
this.log.verbose('Removing existing azure remote alias');
this._exec('git remote rm azure', _);
}
}
- if (!context.remoteUri) {
+ if (!context.github.repositoryFullName) {
// create the remote repo locally
this.log.info('Executing `git remote add azure ' + gitUri + '`');
this._exec('git remote add azure ' + gitUri, _);
@@ -277,35 +278,32 @@ GithubClient.prototype.getRepositories = function (username, _) {
return userRepos;
};
-GithubClient.prototype.createOrUpdateHook = function (username, repository, deployUri, _) {
- var hook = {
- name: 'web',
- user: username,
- repo: repository,
- active: true,
- events: [ 'push' ],
- config: {
- url: deployUri,
- insecure_ssl: '1',
- content_type: 'form'
- }
- };
+GithubClient.prototype.createOrUpdateHook = function (username, repository, websitesRepositoryUri, websitesRepositoryAuth, _) {
+ // Build the current deploy URI for the hook to be created / updated
+ var parsedRepositoryUri = url.parse(websitesRepositoryUri);
+ parsedRepositoryUri.auth = websitesRepositoryAuth;
+ parsedRepositoryUri.pathname = '/deploy';
+ // Url format always encoded the auth part and since it is required that the URL matches
+ // exactly what the portal also creates, it is required to revert back the encoding of the '$'
+ // character to the unencoded form.
+ var deployUri = url.format(parsedRepositoryUri).replace('https://%24', 'https://$');
+
+ // Determine if a hook for the same website already existed in the targeted github repository
var hooks = this.getHooks(username, repository, _);
- var parsedDeployUri = url.parse(deployUri);
var existingHook = hooks.filter(function (hook) {
if (hook.config) {
return hook.name === 'web' &&
- url.parse(hook.config.url).hostname.toLowerCase() === parsedDeployUri.hostname.toLowerCase();
+ url.parse(hook.config.url).hostname.toLowerCase() === parsedRepositoryUri.hostname.toLowerCase();
}
return false;
})[0];
if (existingHook) {
- // check if full url is also the same
- if (existingHook.config.url.toLowerCase() !== hook.config.url.toLowerCase()) {
- existingHook.config.url = hook.config.url;
+ // check if full uri is also the same
+ if (existingHook.config.url.toLowerCase() !== deployUri.toLowerCase()) {
+ existingHook.config.url = deployUri;
existingHook.user = username;
existingHook.repo = repository;
existingHook = this.updateHook(existingHook, _);
@@ -314,10 +312,24 @@ GithubClient.prototype.createOrUpdateHook = function (username, repository, depl
this.log.info('Link already established');
}
} else {
- hook = this.createHook(hook, _);
- hook.user = username;
- hook.repo = repository;
- this.testHook(hook, _);
+ // Initialize a new hook
+ var newHook = {
+ name: 'web',
+ user: username,
+ repo: repository,
+ active: true,
+ events: [ 'push' ],
+ config: {
+ url: deployUri,
+ insecure_ssl: '1',
+ content_type: 'form'
+ }
+ };
+
+ newHook = this.createHook(newHook, _);
+ newHook.user = username;
+ newHook.repo = repository;
+ this.testHook(newHook, _);
}
};

0 comments on commit d18853b

Please sign in to comment.