Permalink
Browse files

support simple payload with just repo url

  • Loading branch information...
1 parent 7bffbb3 commit e33e6927c2c165b108ad0d74d2503181f83abdcb @suwatch suwatch committed Jan 21, 2013
View
52 Kudu.FunctionalTests/DeploymentManagerTests.cs
@@ -13,6 +13,7 @@
using Kudu.Core.Deployment;
using Kudu.FunctionalTests.Infrastructure;
using Kudu.TestHarness;
+using Newtonsoft.Json.Linq;
using Xunit;
namespace Kudu.FunctionalTests
@@ -487,6 +488,57 @@ public void PullApiTestConsecutivePushesGetQueued()
});
}
+ [Fact]
+ public void PullApiTestSimpleFormat()
+ {
+ var payload = new JObject();
+ payload["url"] = "https://github.com/KuduApps/HelloKudu";
+ payload["format"] = "basic";
+ string appName = "HelloKudu";
+
+ ApplicationManager.Run(appName, appManager =>
+ {
+ var client = CreateClient(appManager);
+
+ client.PostAsJsonAsync("deploy", payload).Result.EnsureSuccessful();
+
+ var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
+ Assert.Equal(1, results.Count);
+ Assert.Equal(DeployStatus.Success, results[0].Status);
+ Assert.Equal("GitHub", results[0].Deployer);
+
+ KuduAssert.VerifyUrl(appManager.SiteUrl, "Hello Kudu");
+ });
+ }
+
+ [Fact]
+ public void PullApiTestSimpleFormatWithMercurial()
+ {
+ string payload = @"{""url"":""https://bitbucket.org/kudutest/hellomercurial/"",""format"":""basic"",""scm"":""hg""}";
+ string appName = "PullApiTestSimpleFormatWithMercurial";
+
+ ApplicationManager.Run(appName, appManager =>
+ {
+ var client = CreateClient(appManager);
+
+ appManager.SettingsManager.SetValue("branch", "default").Wait();
+
+ var post = new Dictionary<string, string>
+ {
+ { "payload", payload }
+ };
+
+ client.PostAsync("deploy", new FormUrlEncodedContent(post)).Result.EnsureSuccessful();
+
+ var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
+ Assert.Equal(1, results.Count);
+ Assert.Equal(DeployStatus.Success, results[0].Status);
+ Assert.Equal("Bitbucket", results[0].Deployer);
+
+ KuduAssert.VerifyUrl(appManager.SiteUrl + "Hello.txt", "Hello mercurial");
+ });
+ }
+
private static HttpClient CreateClient(ApplicationManager appManager)
{
HttpClientHandler handler = HttpClientHelper.CreateClientHandler(appManager.ServiceUrl, appManager.DeploymentManager.Credentials);
View
8 Kudu.FunctionalTests/DropboxTests.cs
@@ -45,6 +45,7 @@ public void TestDropboxBasic()
KuduAssert.VerifyUrl(appManager.SiteUrl + "/default.html", "Hello Default!");
KuduAssert.VerifyUrl(appManager.SiteUrl + "/temp/temp.html", "Hello Temp!");
+ KuduAssert.VerifyUrl(appManager.SiteUrl + "/New Folder/New File.html", "Hello New File!");
});
}
@@ -110,13 +111,15 @@ private DropboxDeployInfo GetDeployInfo(OAuthInfo oauth, AccountInfo account, st
foreach (EntryInfo info in delta.entries)
{
- DropboxDeltaInfo item = new DropboxDeltaInfo { Path = info.path };
+ DropboxDeltaInfo item = new DropboxDeltaInfo();
if (info.metadata == null || info.metadata.is_deleted || string.IsNullOrEmpty(info.metadata.path))
{
+ item.Path = info.path;
item.IsDeleted = true;
}
else
{
+ item.Path = info.metadata.path;
item.IsDirectory = info.metadata.is_dir;
if (!item.IsDirectory)
{
@@ -233,9 +236,10 @@ private string GetSignature(OAuthInfo oauth, string path, string timeStamp, stri
strb.AppendFormat("&{0}={1}", "oauth_token", oauth.Token);
strb.AppendFormat("&{0}={1}", "oauth_version", "1.0");
+ Uri uri = new Uri("https://api-content.dropbox.com/1/files/sandbox" + path.ToLower());
string data = String.Format("{0}&{1}&{2}",
"GET",
- UrlEncode("https://api-content.dropbox.com/1/files/sandbox" + path),
+ UrlEncode("https://api-content.dropbox.com" + uri.AbsolutePath),
UrlEncode(strb.ToString()));
var key = String.Format("{0}&{1}",
View
1 Kudu.Services.Test/CodeBaseHqFacts.cs
@@ -62,7 +62,6 @@ public void CodeBaseHqHandlerProcessesPayload()
Assert.Equal(DeployAction.ProcessDeployment, result);
Assert.NotNull(deploymentInfo);
Assert.Equal("CodebaseHQ", deploymentInfo.Deployer);
- Assert.False(deploymentInfo.IsPrivate);
Assert.Equal(RepositoryType.Git, deploymentInfo.RepositoryType);
Assert.Equal("https://test.codebasehq.com/test-repositories/git1.git", deploymentInfo.RepositoryUrl);
Assert.Equal("840daf31f4f87cb5cafd295ef75de989095f415b", deploymentInfo.TargetChangeset.Id);
View
157 Kudu.Services.Test/GenericHandlerFacts.cs
@@ -0,0 +1,157 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Web;
+using Kudu.Core.SourceControl;
+using Kudu.Services.ServiceHookHandlers;
+using Moq;
+using Newtonsoft.Json.Linq;
+using Xunit;
+using Xunit.Extensions;
+
+namespace Kudu.Services.Test
+{
+ public class GenericHandlerFacts
+ {
+ [Theory, PropertyData("SimpleTestData")]
+ public void GenericHandlerSimpleTest(DeployAction expected, IDictionary<string, object> values)
+ {
+ // Arrange
+ var handler = new GenericHandler();
+ var payload = new JObject();
+ foreach (var pair in values)
+ {
+ payload[pair.Key] = JToken.FromObject(pair.Value);
+ }
+
+ // Act
+ DeploymentInfo deploymentInfo;
+ DeployAction result = handler.TryParseDeploymentInfo(request: null, payload: payload, targetBranch: null, deploymentInfo: out deploymentInfo);
+
+ // Assert
+ Assert.Equal(expected, result);
+ }
+
+ [Theory]
+ [InlineData("https://scm.com/repo", null, RepositoryType.Git)]
+ [InlineData("https://scm.com/repo", false, RepositoryType.Git)]
+ [InlineData("https://scm.com/repo", true, RepositoryType.Mercurial)]
+ [InlineData("git@scm.com:user/repo", null, RepositoryType.Git)]
+ [InlineData("git@scm.com:user/repo", false, RepositoryType.Git)]
+ [InlineData("git@scm.com:user/repo", true, RepositoryType.Mercurial)]
+ [InlineData("hg@scm.com:user/repo", null, RepositoryType.Mercurial)]
+ [InlineData("hg@scm.com:user/repo", false, RepositoryType.Git)]
+ [InlineData("hg@scm.com:user/repo", true, RepositoryType.Mercurial)]
+ public void GenericHandlerRepositoryTypeTest(string url, bool? is_hg, RepositoryType expected)
+ {
+ // Arrange
+ var handler = new GenericHandler();
+ var payload = new JObject();
+ payload["url"] = url;
+ payload["format"] = "basic";
+ if (is_hg != null)
+ {
+ payload["scm"] = is_hg.Value ? "hg" : "git";
+ }
+
+ // Act
+ DeploymentInfo deploymentInfo;
+ DeployAction result = handler.TryParseDeploymentInfo(request: null, payload: payload, targetBranch: null, deploymentInfo: out deploymentInfo);
+
+ // Assert
+ Assert.Equal(DeployAction.ProcessDeployment, result);
+ Assert.NotNull(deploymentInfo);
+ Assert.Equal(expected, deploymentInfo.RepositoryType);
+ }
+
+ [Theory]
+ [InlineData("http://scm1.com/repo", "scm1.com")]
+ [InlineData("git@scm2.com:user/repo", "scm2.com")]
+ [InlineData("https://www.github.com/repo", "GitHub")]
+ [InlineData("hg@scm.Bitbucket.org:user/repo", "Bitbucket")]
+ [InlineData("https://www.codeplex.com/repo", "CodePlex")]
+ [InlineData("http://gitlab.proscat.nl/inspectbin", "GitlabHQ")]
+ [InlineData("https://www.kilnhg.com/repo", "Kiln")]
+ public void GenericHandlerDeployerTest(string url, string expected)
+ {
+ // Arrange
+ var handler = new GenericHandler();
+ var payload = new JObject();
+ payload["url"] = url;
+ payload["format"] = "basic";
+
+ // Act
+ DeploymentInfo deploymentInfo;
+ DeployAction result = handler.TryParseDeploymentInfo(request: null, payload: payload, targetBranch: null, deploymentInfo: out deploymentInfo);
+
+ // Assert
+ Assert.Equal(DeployAction.ProcessDeployment, result);
+ Assert.NotNull(deploymentInfo);
+ Assert.Equal(expected, deploymentInfo.Deployer);
+ }
+
+ [Theory]
+ [InlineData("invalid_url")]
+ [InlineData("git@scm.com")]
+ [InlineData("scm.com:user/repo")]
+ [InlineData("git:scm.com@user/repo")]
+ public void GenericHandlerInvalidUrl(string url)
+ {
+ // Arrange
+ var handler = new GenericHandler();
+ var payload = new JObject();
+ payload["url"] = url;
+ payload["format"] = "basic";
+
+ // Act
+ DeploymentInfo deploymentInfo;
+
+ // Assert
+ Assert.Throws<InvalidOperationException>(() =>
+ {
+ handler.TryParseDeploymentInfo(request: null, payload: payload, targetBranch: null, deploymentInfo: out deploymentInfo);
+ });
+ }
+
+ public static IEnumerable<object[]> SimpleTestData
+ {
+ get
+ {
+ // Valid payload
+ yield return new object[] { DeployAction.ProcessDeployment, new Dictionary<string, object> {
+ { "url", "http://scm.com/repo" },
+ { "format", "basic" }
+ }};
+ yield return new object[] { DeployAction.ProcessDeployment, new Dictionary<string, object> {
+ { "url", "http://scm.com/repo" },
+ { "format", "basic" },
+ { "is_hg", true }
+ }};
+ yield return new object[] { DeployAction.ProcessDeployment, new Dictionary<string, object> {
+ { "url", "http://scm.com/repo" },
+ { "format", "basic" },
+ { "is_hg", "false" }
+ }};
+ yield return new object[] { DeployAction.ProcessDeployment, new Dictionary<string, object> {
+ { "url", "git@scm.com:suwatch/repo" },
+ { "format", "basic" }
+ }};
+ yield return new object[] { DeployAction.ProcessDeployment, new Dictionary<string, object> {
+ { "url", "hg@scm.com:suwatch/repo" },
+ { "format", "basic" },
+ { "garbage", 1 }
+ }};
+
+ // Invalid payload
+ yield return new object[] { DeployAction.UnknownPayload, new Dictionary<string, object> {
+ }};
+ yield return new object[] { DeployAction.UnknownPayload, new Dictionary<string, object> {
+ { "url", "http://scm.com/repo" },
+ }};
+ yield return new object[] { DeployAction.UnknownPayload, new Dictionary<string, object> {
+ { "format", "basic" }
+ }};
+ }
+ }
+ }
+}
View
1 Kudu.Services.Test/GithubHandlerFacts.cs
@@ -103,7 +103,6 @@ public void GitHubHandlerProcessesPayloadWithMultipleCommits()
Assert.Equal(DeployAction.ProcessDeployment, result);
Assert.NotNull(deploymentInfo);
Assert.Equal("GitHub", deploymentInfo.Deployer);
- Assert.False(deploymentInfo.IsPrivate);
Assert.Equal(RepositoryType.Git, deploymentInfo.RepositoryType);
Assert.Equal("https://github.com/KuduApps/PostCommitTest", deploymentInfo.RepositoryUrl);
Assert.Equal("f94996d67d6d5a060aaf2fcb72c333d0899549ab", deploymentInfo.TargetChangeset.Id);
View
1 Kudu.Services.Test/Kudu.Services.Test.csproj
@@ -68,6 +68,7 @@
<Compile Include="BitbucketHandlerFacts.cs" />
<Compile Include="CodeBaseHqFacts.cs" />
<Compile Include="CodePlexHandlerFacts.cs" />
+ <Compile Include="GenericHandlerFacts.cs" />
<Compile Include="GithubHandlerFacts.cs" />
<Compile Include="Infrastructure\MediaTypeMapTest.cs" />
<Compile Include="KilnHgHandlerFacts.cs" />
View
1 Kudu.Services.Web/App_Start/NinjectServices.cs
@@ -169,6 +169,7 @@ private static void RegisterServices(IKernel kernel)
.InRequestScope();
// Git Servicehook parsers
+ kernel.Bind<IServiceHookHandler>().To<GenericHandler>().InRequestScope();
kernel.Bind<IServiceHookHandler>().To<GitHubHandler>().InRequestScope();
kernel.Bind<IServiceHookHandler>().To<BitbucketHandler>().InRequestScope();
kernel.Bind<IServiceHookHandler>().To<DropboxHandler>().InRequestScope();
View
9 Kudu.Services/FetchHelpers/DropboxHelper.cs
@@ -139,7 +139,9 @@ private void ApplyChanges(DropboxDeployInfo info)
SafeWriteFile(parent, path, stream, modified);
}
}
- });
+
+ return t;
+ }).FastUnwrap();
}
catch (Exception ex)
{
@@ -250,11 +252,11 @@ private Task<Stream> GetFileAsync(DropboxDeployInfo info, DropboxDeltaInfo delta
// Using ContinueWith instead of Then to avoid SyncContext deadlock in 4.5
TaskCompletionSource<Task<Stream>> tcs = new TaskCompletionSource<Task<Stream>>();
- client.GetAsync(SandboxFilePath + delta.Path).ContinueWith(t =>
+ client.GetAsync(SandboxFilePath + delta.Path.ToLower()).ContinueWith(t =>
{
if (t.IsFaulted)
{
- _tracer.TraceError(t.Exception);
+ _tracer.TraceError("Get '" + SandboxFilePath + delta.Path + "' failed with " + t.Exception);
tcs.TrySetException(t.Exception.InnerExceptions);
}
else if (t.IsCanceled)
@@ -269,6 +271,7 @@ private Task<Stream> GetFileAsync(DropboxDeployInfo info, DropboxDeltaInfo delta
}
catch (Exception ex)
{
+ _tracer.TraceError("Get '" + SandboxFilePath + delta.Path + "' failed with " + ex);
tcs.TrySetException(ex);
}
}
View
1 Kudu.Services/Kudu.Services.csproj
@@ -140,6 +140,7 @@
<Compile Include="ServiceHookHandlers\CodebaseHqHandler.cs" />
<Compile Include="ServiceHookHandlers\CodePlexHandler.cs" />
<Compile Include="ServiceHookHandlers\DropboxHandler.cs" />
+ <Compile Include="ServiceHookHandlers\GenericHandler.cs" />
<Compile Include="ServiceHookHandlers\GitDeploymentInfo.cs" />
<Compile Include="ServiceHookHandlers\GitHubCompatHandler.cs" />
<Compile Include="ServiceHookHandlers\GitlabHqHandler.cs" />
View
9 Kudu.Services/Resources.Designer.cs
@@ -187,6 +187,15 @@ internal class Resources {
}
/// <summary>
+ /// Looks up a localized string similar to Repository url &apos;{0}&apos; is invalid..
+ /// </summary>
+ internal static string Error_InvalidRepoUrl {
+ get {
+ return ResourceManager.GetString("Error_InvalidRepoUrl", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Mismatch dropbox origin cursor..
/// </summary>
internal static string Error_MismatchDropboxCursor {
View
3 Kudu.Services/Resources.resx
@@ -231,4 +231,7 @@
<data name="Error_SyncDropboxTimeout" xml:space="preserve">
<value>Synching with Dropbox timeout after {0} seconds.</value>
</data>
+ <data name="Error_InvalidRepoUrl" xml:space="preserve">
+ <value>Repository url '{0}' is invalid.</value>
+ </data>
</root>
View
6 Kudu.Services/ServiceHookHandlers/BitbucketHandler.cs
@@ -47,10 +47,10 @@ where targetBranch.Equals(commit.Value<string>("branch"), StringComparison.Ordin
string server = payload.Value<string>("canon_url"); // e.g. https://bitbucket.org
string path = repository.Value<string>("absolute_url"); // e.g. /davidebbo/testrepo/
string scm = repository.Value<string>("scm"); // e.g. hg
+ bool isPrivate = repository.Value<bool>("is_private");
// Combine them to get the full URL
info.RepositoryUrl = server + path;
- info.IsPrivate = repository.Value<bool>("is_private");
info.RepositoryType = scm.Equals("hg", StringComparison.OrdinalIgnoreCase) ? RepositoryType.Mercurial : RepositoryType.Git;
info.TargetChangeset = new ChangeSet(
@@ -64,19 +64,17 @@ where targetBranch.Equals(commit.Value<string>("branch"), StringComparison.Ordin
info.Deployer = request.UserAgent;
// private repo, use SSH
- if (info.IsPrivate)
+ if (isPrivate)
{
var uri = new UriBuilder(info.RepositoryUrl);
if (uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
uri.Scheme = "ssh";
uri.Port = -1;
uri.Host = (info.RepositoryType == RepositoryType.Mercurial ? "hg@" : "git@") + uri.Host;
- info.Host = uri.Host;
// Private repo paths are of the format ssh://git@bitbucket.org/accountname/reponame.git
info.RepositoryUrl = uri.ToString();
- info.UseSSH = true;
}
}
View
4 Kudu.Services/ServiceHookHandlers/CodebaseHqHandler.cs
@@ -32,10 +32,10 @@ protected override GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request,
// CodebaseHq format, see http://support.codebasehq.com/kb/howtos/repository-push-commit-notifications
var repository = payload.Value<JObject>("repository");
var urls = repository.Value<JObject>("clone_urls");
- info.IsPrivate = repository.Value<bool>("private");
+ var isPrivate = repository.Value<bool>("private");
info.NewRef = payload.Value<string>("after");
- if (info.IsPrivate)
+ if (isPrivate)
{
info.RepositoryUrl = urls.Value<string>("ssh");
}
View
3 Kudu.Services/ServiceHookHandlers/DeploymentInfo.cs
@@ -7,9 +7,6 @@ public class DeploymentInfo
{
public RepositoryType RepositoryType { get; set; }
public string RepositoryUrl { get; set; }
- public bool IsPrivate { get; set; }
- public bool UseSSH { get; set; }
- public string Host { get; set; }
public string Deployer { get; set; }
public ChangeSet TargetChangeset { get; set; }
public IServiceHookHandler Handler { get; set; }
View
52 Kudu.Services/ServiceHookHandlers/GenericHandler.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Web;
+using Kudu.Core.SourceControl;
+using Newtonsoft.Json.Linq;
+
+namespace Kudu.Services.ServiceHookHandlers
+{
+ /// <summary>
+ /// Generic Servicehook Handler, uses simplest format.
+ /// </summary>
+ public class GenericHandler : ServiceHookHandlerBase
+ {
+ // {
+ // 'format':'basic'
+ // 'url':'http://host/repository',
+ // 'is_hg':true // optional
+ // }
+ public override DeployAction TryParseDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch, out DeploymentInfo deploymentInfo)
+ {
+ deploymentInfo = null;
+ if (!String.Equals(payload.Value<string>("format"), "basic", StringComparison.OrdinalIgnoreCase))
+ {
+ return DeployAction.UnknownPayload;
+ }
+
+ string url = payload.Value<string>("url");
+ if (String.IsNullOrEmpty(url))
+ {
+ return DeployAction.UnknownPayload;
+ }
+
+ string scm = payload.Value<string>("scm");
+ bool is_hg;
+ if (String.IsNullOrEmpty(scm))
+ {
+ // SSH hg@... vs git@...
+ is_hg = url.StartsWith("hg@", StringComparison.OrdinalIgnoreCase);
+ }
+ else
+ {
+ is_hg = String.Equals(scm, "hg", StringComparison.OrdinalIgnoreCase);
+ }
+
+ deploymentInfo = new DeploymentInfo();
+ deploymentInfo.RepositoryUrl = url;
+ deploymentInfo.RepositoryType = is_hg ? RepositoryType.Mercurial : RepositoryType.Git;
+ deploymentInfo.Deployer = GetDeployerFromUrl(url);
+
+ return DeployAction.ProcessDeployment;
+ }
+ }
+}
View
9 Kudu.Services/ServiceHookHandlers/GitHubCompatHandler.cs
@@ -54,22 +54,21 @@ protected virtual GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, J
// github format
// { repository: { url: "https//...", private: False }, ref: "", before: "", after: "" }
info.RepositoryUrl = repository.Value<string>("url");
- info.IsPrivate = repository.Value<bool>("private");
info.Deployer = GetDeployer(request);
info.NewRef = payload.Value<string>("after");
var commits = payload.Value<JArray>("commits");
info.TargetChangeset = ParseChangeSet(info.NewRef, commits);
// private repo, use SSH
- if (info.IsPrivate)
+ bool isPrivate = repository.Value<bool>("private");
+ if (isPrivate)
{
Uri uri = new Uri(info.RepositoryUrl);
if (uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
- info.Host = "git@" + uri.Host;
- info.RepositoryUrl = info.Host + ":" + uri.AbsolutePath.TrimStart('/');
- info.UseSSH = true;
+ var host = "git@" + uri.Host;
+ info.RepositoryUrl = host + ":" + uri.AbsolutePath.TrimStart('/');
}
}
View
14 Kudu.Services/ServiceHookHandlers/GitlabHqHandler.cs
@@ -42,13 +42,10 @@ protected override GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request,
// work around missing 'private' property, if missing assume is private.
JToken priv;
+ bool isPrivate = true;
if (repository.TryGetValue("private", out priv))
{
- info.IsPrivate = priv.ToObject<bool>();
- }
- else
- {
- info.IsPrivate = true;
+ isPrivate = priv.ToObject<bool>();
}
// The format of ref is refs/something/something else
@@ -62,14 +59,13 @@ protected override GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request,
info.Deployer = "GitlabHQ";
// private repo, use SSH
- if (info.IsPrivate)
+ if (isPrivate)
{
Uri uri = new Uri(info.RepositoryUrl);
if (uri.Scheme.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
- info.Host = "git@" + uri.Host;
- info.RepositoryUrl = info.Host + ":" + uri.AbsolutePath.TrimStart('/');
- info.UseSSH = true;
+ var host = "git@" + uri.Host;
+ info.RepositoryUrl = host + ":" + uri.AbsolutePath.TrimStart('/');
}
}
View
4 Kudu.Services/ServiceHookHandlers/KilnHgHandler.cs
@@ -102,7 +102,6 @@ where targetBranch.Equals(commit.Value<string>("branch"), StringComparison.Ordin
var info = new DeploymentInfo
{
Deployer = "Kiln",
- IsPrivate = !String.IsNullOrWhiteSpace(accessToken), // assume a private repo if an access token is provided
RepositoryUrl = repository.Value<string>("url"),
RepositoryType = RepositoryType.Mercurial,
TargetChangeset = new ChangeSet(
@@ -114,7 +113,8 @@ where targetBranch.Equals(commit.Value<string>("branch"), StringComparison.Ordin
)
};
- if (info.IsPrivate)
+ bool isPrivate = !String.IsNullOrWhiteSpace(accessToken); // assume a private repo if an access token is provided
+ if (isPrivate)
{
var uri = new UriBuilder(info.RepositoryUrl)
{
View
57 Kudu.Services/ServiceHookHandlers/ServiceHookHandlerBase.cs
@@ -1,4 +1,6 @@
-using Kudu.Core.SourceControl;
+using System;
+using System.Globalization;
+using Kudu.Core.SourceControl;
namespace Kudu.Services.ServiceHookHandlers
{
@@ -10,5 +12,58 @@ public void Fetch(IRepository repository, DeploymentInfo deploymentInfo, string
{
repository.FetchWithoutConflict(deploymentInfo.RepositoryUrl, "external", targetBranch);
}
+
+ protected string GetDeployerFromUrl(string url)
+ {
+ string host;
+ Uri uri;
+ if (Uri.TryCreate(url, UriKind.Absolute, out uri))
+ {
+ host = uri.Host;
+ if (String.IsNullOrEmpty(host))
+ {
+ throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_InvalidRepoUrl, url));
+ }
+ }
+ else
+ {
+ // extract host from git@host:user/repo
+ int at = url.IndexOf("@");
+ int colon = url.IndexOf(":");
+ if (at <= 0 || colon <= 0 || at >= colon)
+ {
+ throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_InvalidRepoUrl, url));
+ }
+
+ host = url.Substring(at + 1, colon - at - 1);
+ }
+
+ if (host.EndsWith("github.com", StringComparison.OrdinalIgnoreCase))
+ {
+ return "GitHub";
+ }
+
+ if (host.EndsWith("bitbucket.org", StringComparison.OrdinalIgnoreCase))
+ {
+ return "Bitbucket";
+ }
+
+ if (host.EndsWith("codeplex.com", StringComparison.OrdinalIgnoreCase))
+ {
+ return "CodePlex";
+ }
+
+ if (host.EndsWith("kilnhg.com", StringComparison.OrdinalIgnoreCase))
+ {
+ return "Kiln";
+ }
+
+ if (host.StartsWith("gitlab", StringComparison.OrdinalIgnoreCase))
+ {
+ return "GitlabHQ";
+ }
+
+ return host;
+ }
}
}

0 comments on commit e33e692

Please sign in to comment.