Skip to content

Commit

Permalink
Fixes issue #24 - Doesn't deploy from a folder withing the repo
Browse files Browse the repository at this point in the history
Added repo display name so that shows a sanitized source URL that can be deeper than the root of the repository.  However if the user is deploying a website, we'll still continue to pull from the root.
  • Loading branch information
ehamai committed Mar 4, 2015
1 parent e5d084f commit 5f54e9c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Slingshot.Api/Abstract/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public abstract class Repository
{
protected Uri _inputUri;
protected string _repoUrl;
protected string _repoDisplayUrl;
protected string _branch;
protected string _repositoryName;
protected string _userName;
Expand All @@ -25,6 +26,8 @@ public Repository(Uri uri)
_inputUri = uri;
}

public abstract string RepositoryDisplayUrl { get; }

public abstract string RepositoryUrl { get; }

public abstract string RepositoryName { get; }
Expand Down
44 changes: 40 additions & 4 deletions Slingshot.Api/Concrete/GitHubRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using System.Web;
using System.IO;
using System.Text;

namespace Slingshot.Concrete
{
Expand All @@ -33,15 +34,28 @@ public override async Task<string> GetTemplateUrlAsync()
{
JObject template = null;
string templateUrl = null;
StringBuilder builder = null;

if (_inputUri.Segments.Length > 2)
{
string branch = await GetBranch();
templateUrl = string.Format(Constants.Repository.GitCustomTemplateFormat,
builder = new StringBuilder(string.Format(Constants.Repository.GitCustomTemplateFolderUrlFormat,
UserName,
RepositoryName,
branch);
branch));

for (var i = 5; i < _inputUri.Segments.Length; i++)
{
string segment = _inputUri.Segments[i];
if(segment.EndsWith(".md", StringComparison.OrdinalIgnoreCase))
{
break;
}

builder.Append(segment);
}

templateUrl = builder.ToString().TrimEnd(Constants.Path.SlashChars) + "/azuredeploy.json";
template = await DownloadTemplate(templateUrl);
}

Expand Down Expand Up @@ -69,16 +83,38 @@ public override string RepositoryUrl
_repoUrl = string.Format("https://{0}/{1}/{2}", _inputUri.Host, UserName, RepositoryName);
}
}

return _repoUrl;
}
}

public override string RepositoryDisplayUrl
{
get
{
if (string.IsNullOrEmpty(_repoDisplayUrl))
{
string lastSegment = _inputUri.Segments[_inputUri.Segments.Length - 1];
string url = _inputUri.ToString();
if (lastSegment.EndsWith(".md", StringComparison.OrdinalIgnoreCase))
{
int lastSlashIndex = url.LastIndexOf('/');
_repoDisplayUrl = _inputUri.ToString().Substring(0, lastSlashIndex);
}
else
{
_repoDisplayUrl = url;
}
}

return _repoDisplayUrl;
}
}

public override async Task<string> GetBranch()
{
if (string.IsNullOrEmpty(_branch))
{
if (_inputUri.Segments.Length >= 4)
if (_inputUri.Segments.Length > 4)
{
_branch = _inputUri.Segments[4].Trim(Constants.Path.SlashChars);
}
Expand Down
6 changes: 6 additions & 0 deletions Slingshot.Api/Content/Styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ pre { margin-bottom:20px; }
min-height: 200px;
}

.header-label{
white-space:nowrap;
width:670px;
overflow: hidden;
}

/* ANIMATION STYLINGS
============================================================================= */
#signup-form { position:relative; min-height:300px; overflow:hidden; padding:30px; }
Expand Down
4 changes: 2 additions & 2 deletions Slingshot.Api/Controllers/ARMController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ public async Task<HttpResponseMessage> GetTemplate(string repositoryUrl)
JObject returnObj = new JObject();

Repository repo = Repository.CreateRepositoryObj(repositoryUrl);
repositoryUrl = repo.RepositoryUrl;

string templateUrl = await repo.GetTemplateUrlAsync();
JObject template = await repo.DownloadTemplateAsync();
Expand Down Expand Up @@ -344,7 +343,8 @@ public async Task<HttpResponseMessage> GetTemplate(string repositoryUrl)
returnObj["resourceGroup"] = resourceGroupName;
returnObj["template"] = template;
returnObj["templateUrl"] = templateUrl;
returnObj["repositoryUrl"] = repositoryUrl;
returnObj["repositoryUrl"] = repo.RepositoryUrl;
returnObj["repositoryDisplayUrl"] = repo.RepositoryDisplayUrl;
returnObj["branch"] = branch;

// Check if the template takes in a Website parameter
Expand Down
2 changes: 1 addition & 1 deletion Slingshot.Api/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Path
public class Repository
{
public const string EmptySiteTemplateUrl = "http://deploytoazure.azurewebsites.net/sitewithrepository.json";
public const string GitCustomTemplateFormat = "https://raw.githubusercontent.com/{0}/{1}/{2}/azuredeploy.json";
public const string GitCustomTemplateFolderUrlFormat = "https://raw.githubusercontent.com/{0}/{1}/{2}/";
public const string GitHubApiRepoInfoFormat = "https://api.github.com/repos/{0}/{1}";
}

Expand Down
1 change: 1 addition & 0 deletions Slingshot.Api/ng/Scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ angular.module('formApp', ['ngAnimate', 'ui.router'])
$scope.formData.branch = result.data.branch;
$scope.formData.tenants = result.data.tenants;
$scope.formData.repositoryUrl = result.data.repositoryUrl;
$scope.formData.repositoryDisplayUrl = result.data.repositoryDisplayUrl;
$scope.formData.siteName = result.data.siteName;
$scope.formData.siteNameQuery = result.data.siteName;

Expand Down
8 changes: 4 additions & 4 deletions Slingshot.Api/ng/Views/form-setup.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div ng-hide="formData.error">
<div id="repositoryContainer">
<div class="text-primary">
Git Repository Url - <span class="text-info">{{formData.repositoryUrl}}</span>
<div class="text-primary header-label">
Git Repository Url - <span class="text-info" ng-attr-title="{{formData.repositoryDisplayUrl}}">{{formData.repositoryDisplayUrl}}</span>
</div>

<div class="text-primary">
Branch - <span class="text-info">{{formData.branch}}</span>
<div class="text-primary header-label">
Branch - <span class="text-info" ng-attr-title="{{formData.branch}}">{{formData.branch}}</span>
</div>
</div>

Expand Down

0 comments on commit 5f54e9c

Please sign in to comment.