Permalink
Browse files

Adding Mercurial support for CodePlex

  • Loading branch information...
1 parent 5a97416 commit 07060c3c66bd7bce46b3e94c70e8440f3c8ea5ba @pranavkm pranavkm committed Jan 14, 2013
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Web;
+using System.Web;
using Kudu.Core.SourceControl;
using Kudu.Core.SourceControl.Git;
using Kudu.Services.ServiceHookHandlers;
@@ -20,7 +16,7 @@ public void CodeBaseHqHandlerIgnoresNonCodeBaseHqPayloads()
{
// Arrange
var httpRequest = new Mock<HttpRequestBase>();
- var handler = new CodebaseHqHandler(Mock.Of<IGitServer>());
+ var handler = new CodebaseHqHandler();
// Act
DeploymentInfo deploymentInfo;
@@ -29,6 +25,7 @@ public void CodeBaseHqHandlerIgnoresNonCodeBaseHqPayloads()
// Assert
Assert.Equal(DeployAction.UnknownPayload, result);
}
+
[Theory]
[InlineData("{ invalid: 'payload' }")]
[InlineData("{ ref: '' }")]
@@ -37,7 +34,7 @@ public void GitHubHandlerHandlerReturnsNoOpForMalformedPayloads(string payloadCo
{
// Arrange
var httpRequest = GetRequest();
- var handler = new CodebaseHqHandler(Mock.Of<IGitServer>());
+ var handler = new CodebaseHqHandler();
JObject payload = JObject.Parse(payloadContent);
// Act
@@ -54,7 +51,7 @@ public void CodeBaseHqHandlerProcessesPayload()
// Arrange
string payloadContent = @"{""before"":""fc10b3aa5a9e39ac326489805bba5c577f04db85"",""after"":""840daf31f4f87cb5cafd295ef75de989095f415b"",""ref"":""refs/heads/master"",""repository"":{""name"":""Git Repo #1"",""url"":""http://test.codebasehq.com/projects/test-repositories/repositories/git1"",""clone_url"":""git@codebasehq.com:test/test-repositories/git1.git"",""clone_urls"":{""ssh"":""git@codebasehq.com:test/test-repositories/git1.git"",""git"":""git://codebasehq.com:test/test-repositories/git1.git"",""http"":""https://test.codebasehq.com/test-repositories/git1.git""},""project"":{""name"":""Test Repositories"",""url"":""http://test.codebasehq.com/projects/test-repositories"",""status"":""active""}},""user"":{""name"":""Dan Wentworth"",""username"":""dan"",""email"":""dan@atechmedia.com""},""commits"":[{""id"":""840daf31f4f87cb5cafd295ef75de989095f415b"",""message"":""Extra output for the rrrraaaagh"",""author"":{""name"":""Dan Wentworth"",""email"":""dan@atechmedia.com""},""timestamp"":""Mon, 18 Jul 2011 10:50:01 +0100"",""url"":""http://test.codebasehq.com/projects/test-repositories/repositories/git1/commit/840daf31f4f87cb5cafd295ef75de989095f415b""}]}";
var httpRequest = GetRequest();
- var handler = new CodebaseHqHandler(Mock.Of<IGitServer>());
+ var handler = new CodebaseHqHandler();
JObject payload = JObject.Parse(payloadContent);
// Act
@@ -81,7 +78,7 @@ public void CodeBaseHqHandlerReturnsNoOpForDelete()
// Arrange
string payloadContent = @"{""before"":""fc10b3aa5a9e39ac326489805bba5c577f04db85"",""after"":""000000000000000000000000000000000"",""ref"":""refs/heads/master"",""repository"":{""name"":""Git Repo #1"",""url"":""http://test.codebasehq.com/projects/test-repositories/repositories/git1"",""clone_url"":""git@codebasehq.com:test/test-repositories/git1.git"",""clone_urls"":{""ssh"":""git@codebasehq.com:test/test-repositories/git1.git"",""git"":""git://codebasehq.com:test/test-repositories/git1.git"",""http"":""https://test.codebasehq.com/test-repositories/git1.git""},""project"":{""name"":""Test Repositories"",""url"":""http://test.codebasehq.com/projects/test-repositories"",""status"":""active""}},""user"":{""name"":""Dan Wentworth"",""username"":""dan"",""email"":""dan@atechmedia.com""},""commits"":[]}";
var httpRequest = GetRequest();
- var handler = new CodebaseHqHandler(Mock.Of<IGitServer>());
+ var handler = new CodebaseHqHandler();
JObject payload = JObject.Parse(payloadContent);
// Act
@@ -98,7 +95,7 @@ public void CodeBaseHqHandlerReturnsNoOpForDeploymentsToNonTargetBranch()
// Arrange
string payloadContent = @"{""before"":""fc10b3aa5a9e39ac326489805bba5c577f04db85"",""after"":""840daf31f4f87cb5cafd295ef75de989095f415b"",""ref"":""refs/heads/master"",""repository"":{""name"":""Git Repo #1"",""url"":""http://test.codebasehq.com/projects/test-repositories/repositories/git1"",""clone_url"":""git@codebasehq.com:test/test-repositories/git1.git"",""clone_urls"":{""ssh"":""git@codebasehq.com:test/test-repositories/git1.git"",""git"":""git://codebasehq.com:test/test-repositories/git1.git"",""http"":""https://test.codebasehq.com/test-repositories/git1.git""},""project"":{""name"":""Test Repositories"",""url"":""http://test.codebasehq.com/projects/test-repositories"",""status"":""active""}},""user"":{""name"":""Dan Wentworth"",""username"":""dan"",""email"":""dan@atechmedia.com""},""commits"":[{""id"":""840daf31f4f87cb5cafd295ef75de989095f415b"",""message"":""Extra output for the rrrraaaagh"",""author"":{""name"":""Dan Wentworth"",""email"":""dan@atechmedia.com""},""timestamp"":""Mon, 18 Jul 2011 10:50:01 +0100"",""url"":""http://test.codebasehq.com/projects/test-repositories/repositories/git1/commit/840daf31f4f87cb5cafd295ef75de989095f415b""}]}";
var httpRequest = GetRequest();
- var handler = new CodebaseHqHandler(Mock.Of<IGitServer>());
+ var handler = new CodebaseHqHandler();
JObject payload = JObject.Parse(payloadContent);
// Act
@@ -0,0 +1,132 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+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 CodePlexHandlerFacts
+ {
+ [Theory]
+ [InlineData("{ invalid: 'payload' }")]
+ [InlineData("{ ref: '' }")]
+ [InlineData(@"{""before"":""fc10b3aa5a9e39ac326489805bba5c577f04db85"",""after"":""840daf31f4f87cb5cafd295ef75de989095f415b"",""ref"":""refs/heads/master"",""repository"":{""name"":""Git Repo #1"",""url"":""http://test.codebasehq.com/projects/test-repositories/repositories/git1"",""clone_url"":""git@codebasehq.com:test/test-repositories/git1.git"",""clone_urls"":{""ssh"":""git@codebasehq.com:test/test-repositories/git1.git"",""git"":""git://codebasehq.com:test/test-repositories/git1.git"",""http"":""https://test.codebasehq.com/test-repositories/git1.git""},""project"":{""name"":""Test Repositories"",""url"":""http://test.codebasehq.com/projects/test-repositories"",""status"":""active""}},""user"":{""name"":""Dan Wentworth"",""username"":""dan"",""email"":""dan@atechmedia.com""},""commits"":[{""id"":""840daf31f4f87cb5cafd295ef75de989095f415b"",""message"":""Extra output for the rrrraaaagh"",""author"":{""name"":""Dan Wentworth"",""email"":""dan@atechmedia.com""},""timestamp"":""Mon, 18 Jul 2011 10:50:01 +0100"",""url"":""http://test.codebasehq.com/projects/test-repositories/repositories/git1/commit/840daf31f4f87cb5cafd295ef75de989095f415b""}]}")]
+ public void CodePlexHandlerIgnoresNonCodePlexPayloads(string payloadContent)
+ {
+ // Arrange
+ var httpRequest = new Mock<HttpRequestBase>();
+ var handler = new CodePlexHandler();
+ JObject payload = JObject.Parse(payloadContent);
+
+ // Act
+ DeploymentInfo deploymentInfo;
+ DeployAction result = handler.TryParseDeploymentInfo(httpRequest.Object, payload: payload, targetBranch: null, deploymentInfo: out deploymentInfo);
+
+ // Assert
+ Assert.Equal(DeployAction.UnknownPayload, result);
+ }
+
+ [Fact]
+ public void CodePlexHandlerParsesGitPayload()
+ {
+ // Arrange
+ string payloadContent = @"{ url: ""https://git01.codeplex.com/pranavkmgittest"", branch: ""master"", deployer: ""codeplex"", oldRef: ""3dc5fc28310a7906a9809f81fc5dc68aa681a1f8"", newRef: ""dcda9b7e70157a89423fd7862f2ee193586ca64f"", scmType: ""Git"" }";
+ var httpRequest = new Mock<HttpRequestBase>();
+ var handler = new CodePlexHandler();
+ JObject payload = JObject.Parse(payloadContent);
+
+ // Act
+ DeploymentInfo deploymentInfo;
+ DeployAction result = handler.TryParseDeploymentInfo(httpRequest.Object, payload: payload, targetBranch: "master", deploymentInfo: out deploymentInfo);
+
+ // Assert
+ Assert.Equal(DeployAction.ProcessDeployment, result);
+ Assert.NotNull(deploymentInfo);
+ Assert.Equal("CodePlex", deploymentInfo.Deployer);
+ Assert.Equal(RepositoryType.Git, deploymentInfo.RepositoryType);
+ Assert.Equal("https://git01.codeplex.com/pranavkmgittest", deploymentInfo.RepositoryUrl);
+ Assert.Equal("dcda9b7e70157a89423fd7862f2ee193586ca64f", deploymentInfo.TargetChangeset.Id);
+ }
+
+ [Fact]
+ public void CodePlexHandlerNoOpsDeleteRequest()
+ {
+ // Arrange
+ string payloadContent = @"{ url: ""https://git01.codeplex.com/pranavkmgittest"", branch: ""master"", deployer: ""codeplex"", oldRef: ""3dc5fc28310a7906a9809f81fc5dc68aa681a1f8"", newRef: ""0000000000000000000000000000000000000000"", scmType: ""Git"" }";
+ var httpRequest = new Mock<HttpRequestBase>();
+ var handler = new CodePlexHandler();
+ JObject payload = JObject.Parse(payloadContent);
+
+ // Act
+ DeploymentInfo deploymentInfo;
+ DeployAction result = handler.TryParseDeploymentInfo(httpRequest.Object, payload: payload, targetBranch: "master", deploymentInfo: out deploymentInfo);
+
+ // Assert
+ Assert.Equal(DeployAction.NoOp, result);
+ }
+
+ [Fact]
+ public void CodePlexHandlerNoOpsNonTargetBranchPayloads()
+ {
+ // Arrange
+ string payloadContent = @"{ url: ""https://git01.codeplex.com/pranavkmgittest"", branch: ""test"", deployer: ""codeplex"", oldRef: ""3dc5fc28310a7906a9809f81fc5dc68aa681a1f8"", newRef: ""dcda9b7e70157a89423fd7862f2ee193586ca64f"", scmType: ""Git"" }";
+ var httpRequest = new Mock<HttpRequestBase>();
+ var handler = new CodePlexHandler();
+ JObject payload = JObject.Parse(payloadContent);
+
+ // Act
+ DeploymentInfo deploymentInfo;
+ DeployAction result = handler.TryParseDeploymentInfo(httpRequest.Object, payload: payload, targetBranch: "prod", deploymentInfo: out deploymentInfo);
+
+ // Assert
+ Assert.Equal(DeployAction.NoOp, result);
+ }
+
+ [Fact]
+ public void CodePlexHandlerParsesMercurialPayload()
+ {
+ // Arrange
+ string payloadContent = @"{ url: ""https://hg01.codeplex.com/pranavkmmerctest"", branch: ""default"", deployer: ""codeplex"", oldRef: ""3dc5fc28310a7906a9809f81fc5dc68aa681a1f8"", newRef: ""dcda9b7e70157a89423fd7862f2ee193586ca64f"", scmType: ""Mercurial"" }";
+ var httpRequest = new Mock<HttpRequestBase>();
+ var handler = new CodePlexHandler();
+ JObject payload = JObject.Parse(payloadContent);
+
+ // Act
+ DeploymentInfo deploymentInfo;
+ DeployAction result = handler.TryParseDeploymentInfo(httpRequest.Object, payload: payload, targetBranch: "default", deploymentInfo: out deploymentInfo);
+
+ // Assert
+ Assert.Equal(DeployAction.ProcessDeployment, result);
+ Assert.NotNull(deploymentInfo);
+ Assert.Equal("CodePlex", deploymentInfo.Deployer);
+ Assert.Equal(RepositoryType.Mercurial, deploymentInfo.RepositoryType);
+ Assert.Equal("https://hg01.codeplex.com/pranavkmmerctest", deploymentInfo.RepositoryUrl);
+ Assert.Equal("dcda9b7e70157a89423fd7862f2ee193586ca64f", deploymentInfo.TargetChangeset.Id);
+ }
+
+ [Fact]
+ public void CodePlexHandlerNonOpsNonTargetBranchMercurialPayload()
+ {
+ // Arrange
+ string payloadContent = @"{ url: ""https://hg01.codeplex.com/pranavkmmerctest"", branch: ""test"", deployer: ""codeplex"", oldRef: ""3dc5fc28310a7906a9809f81fc5dc68aa681a1f8"", newRef: ""dcda9b7e70157a89423fd7862f2ee193586ca64f"", scmType: ""Mercurial"" }";
+ var httpRequest = new Mock<HttpRequestBase>();
+ var handler = new CodePlexHandler();
+ JObject payload = JObject.Parse(payloadContent);
+
+ // Act
+ DeploymentInfo deploymentInfo;
+ DeployAction result = handler.TryParseDeploymentInfo(httpRequest.Object, payload: payload, targetBranch: "production", deploymentInfo: out deploymentInfo);
+
+ // Assert
+ Assert.Equal(DeployAction.NoOp, result);
+ }
+ }
+}
@@ -19,7 +19,7 @@ public void GitHubHandlerIgnoresNonGithubPayloads()
var headers = new NameValueCollection();
var httpRequest = new Mock<HttpRequestBase>();
httpRequest.SetupGet(r => r.Headers).Returns(headers);
- var handler = new GitHubHandler(Mock.Of<IGitServer>());
+ var handler = new GitHubHandler();
// Act
DeploymentInfo deploymentInfo;
@@ -37,7 +37,7 @@ public void GitHubHandlerReturnsNoOpForMalformedPayloads(string payloadContent)
{
// Arrange
var httpRequest = GetRequest();
- var handler = new GitHubHandler(Mock.Of<IGitServer>());
+ var handler = new GitHubHandler();
JObject payload = JObject.Parse(payloadContent);
// Act
@@ -55,7 +55,7 @@ public void GitHubHandlerReturnsNoOpForPayloadsWithEmptyAfter()
// Arrange
string payloadContent = @"{""after"":""00000000000000000000000000000000"", ""repository"":{ ""url"":""https://github.com/KuduApps/PostCommitTest"" }, ref: ""refs/heads/master"", commits: [] }";
var httpRequest = GetRequest();
- var handler = new GitHubHandler(Mock.Of<IGitServer>());
+ var handler = new GitHubHandler();
JObject payload = JObject.Parse(payloadContent);
// Act
@@ -73,7 +73,7 @@ public void GitHubHandlerReturnsNoOpForPayloadsNotMatchingTargetBranch()
// Arrange
string payloadContent = @"{ ""repository"":{ ""url"":""https://github.com/KuduApps/PostCommitTest"" }, ref: ""refs/heads/not-master"", commits: [{""added"":[""Foo.txt""],""author"":{""email"":""prkrishn@hotmail.com"",""name"":""Pranav K"",""username"":""pranavkm""},""committer"":{""email"":""prkrishn@hotmail.com"",""name"":""Pranav K"",""username"":""pranavkm""},""distinct"":true,""id"":""f94996d67d6d5a060aaf2fcb72c333d0899549ab"",""message"":""Foo commit"",""modified"":[],""removed"":[],""timestamp"":""2012-12-17T14:32:20-08:00"",""url"":""https://github.com/KuduApps/PostCommitTest/commit/f94996d67d6d5a060aaf2fcb72c333d0899549ab""}] }";
var httpRequest = GetRequest();
- var handler = new GitHubHandler(Mock.Of<IGitServer>());
+ var handler = new GitHubHandler();
JObject payload = JObject.Parse(payloadContent);
// Act
@@ -92,7 +92,7 @@ public void GitHubHandlerProcessesPayloadWithMultipleCommits()
// Arrange
string payloadContent = @"{""after"":""f94996d67d6d5a060aaf2fcb72c333d0899549ab"",""before"":""0000000000000000000000000000000000000000"",""commits"":[{""added"":[],""author"":{""email"":""kirthik@microsoft.com"",""name"":""Kirthi Krishnamraju"",""username"":""kirthik""},""committer"":{""email"":""kirthik@microsoft.com"",""name"":""Kirthi Krishnamraju"",""username"":""kirthik""},""distinct"":true,""id"":""18ceab5cda610374b45f6496c88615b1213a7bd8"",""message"":""in foo"",""modified"":[""MvcApplication1/Controllers/HomeController.cs""],""removed"":[],""timestamp"":""2012-08-30T17:36:29-07:00"",""url"":""https://github.com/KuduApps/PostCommitTest/commit/18ceab5cda610374b45f6496c88615b1213a7bd8""},{""added"":[""Foo.txt""],""author"":{""email"":""prkrishn@hotmail.com"",""name"":""Pranav K"",""username"":""pranavkm""},""committer"":{""email"":""prkrishn@hotmail.com"",""name"":""Pranav K"",""username"":""pranavkm""},""distinct"":true,""id"":""f94996d67d6d5a060aaf2fcb72c333d0899549ab"",""message"":""Foo commit"",""modified"":[],""removed"":[],""timestamp"":""2012-12-17T14:32:20-08:00"",""url"":""https://github.com/KuduApps/PostCommitTest/commit/f94996d67d6d5a060aaf2fcb72c333d0899549ab""}],""compare"":""https://github.com/KuduApps/PostCommitTest/compare/18ceab5cda61^...f94996d67d6d"",""created"":true,""deleted"":false,""forced"":true,""pusher"":{""email"":""prkrishn@hotmail.com"",""name"":""pranavkm""},""ref"":""refs/heads/master"",""repository"":{""private"":false,""url"":""https://github.com/KuduApps/PostCommitTest""}}";
var httpRequest = GetRequest();
- var handler = new GitHubHandler(Mock.Of<IGitServer>());
+ var handler = new GitHubHandler();
JObject payload = JObject.Parse(payloadContent);
// Act
@@ -64,6 +64,7 @@
<ItemGroup>
<Compile Include="BitbucketHandlerFacts.cs" />
<Compile Include="CodeBaseHqFacts.cs" />
+ <Compile Include="CodePlexHandlerFacts.cs" />
<Compile Include="GithubHandlerFacts.cs" />
<Compile Include="Infrastructure\MediaTypeMapTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Oops, something went wrong.

0 comments on commit 07060c3

Please sign in to comment.