From 99de6971bf71ac60eba74ee23d6024086a299506 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Thu, 7 Sep 2017 14:37:17 +0200 Subject: [PATCH] Provide converted repository URL for SSH URLs --- .../RepositoryDescriptionTests.cs | 60 +++++++++++++------ src/TfsUrlParser/RepositoryDescription.cs | 10 +++- 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/TfsUrlParser.Tests/RepositoryDescriptionTests.cs b/src/TfsUrlParser.Tests/RepositoryDescriptionTests.cs index 9bbe942..0105be7 100644 --- a/src/TfsUrlParser.Tests/RepositoryDescriptionTests.cs +++ b/src/TfsUrlParser.Tests/RepositoryDescriptionTests.cs @@ -35,123 +35,147 @@ public void Should_Throw_If_No_Valid_Url(string repoUrl, string expectedMessage) "defaultcollection", @"http://myserver:8080/tfs/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository")] [InlineData( @"http://tfs.myserver/defaultcollection/myproject/_git/myrepository", @"http://tfs.myserver/", "defaultcollection", @"http://tfs.myserver/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"http://tfs.myserver/defaultcollection/myproject/_git/myrepository")] [InlineData( @"http://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository", @"http://mytenant.visualstudio.com/", "defaultcollection", @"http://mytenant.visualstudio.com/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"http://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository")] [InlineData( @"http://tfs.foo.com/foo/foo/_git/foo", @"http://tfs.foo.com/", "foo", @"http://tfs.foo.com/foo", "foo", - "foo")] + "foo", + @"http://tfs.foo.com/foo/foo/_git/foo")] [InlineData( @"http://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository/somethingelse", @"http://mytenant.visualstudio.com/", "defaultcollection", @"http://mytenant.visualstudio.com/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"http://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository/somethingelse")] [InlineData( @"https://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", @"https://myserver:8080/", "defaultcollection", @"https://myserver:8080/tfs/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"https://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository")] [InlineData( @"https://tfs.myserver/defaultcollection/myproject/_git/myrepository", @"https://tfs.myserver/", "defaultcollection", @"https://tfs.myserver/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"https://tfs.myserver/defaultcollection/myproject/_git/myrepository")] [InlineData( @"https://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository", @"https://mytenant.visualstudio.com/", "defaultcollection", @"https://mytenant.visualstudio.com/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"https://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository")] [InlineData( @"https://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository/somethingelse", @"https://mytenant.visualstudio.com/", "defaultcollection", @"https://mytenant.visualstudio.com/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"https://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository/somethingelse")] [InlineData( @"https://tfs.foo.com/foo/foo/_git/foo", @"https://tfs.foo.com/", "foo", @"https://tfs.foo.com/foo", "foo", - "foo")] + "foo", + @"https://tfs.foo.com/foo/foo/_git/foo")] [InlineData( @"ssh://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", @"ssh://myserver:8080/", "defaultcollection", @"https://myserver:8080/tfs/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"https://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository")] [InlineData( @"ssh://tfs.myserver/defaultcollection/myproject/_git/myrepository", @"ssh://tfs.myserver/", "defaultcollection", @"https://tfs.myserver/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"https://tfs.myserver/defaultcollection/myproject/_git/myrepository")] [InlineData( @"ssh://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository", @"ssh://mytenant.visualstudio.com/", "defaultcollection", @"https://mytenant.visualstudio.com/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"https://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository")] [InlineData( @"ssh://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository/somethingelse", @"ssh://mytenant.visualstudio.com/", "defaultcollection", @"https://mytenant.visualstudio.com/defaultcollection", "myproject", - "myrepository")] + "myrepository", + @"https://mytenant.visualstudio.com/defaultcollection/myproject/_git/myrepository/somethingelse")] [InlineData( @"ssh://tfs.foo.com/foo/foo/_git/foo", @"ssh://tfs.foo.com/", "foo", @"https://tfs.foo.com/foo", "foo", - "foo")] + "foo", + @"https://tfs.foo.com/foo/foo/_git/foo")] [InlineData( @"ssh://foo:bar@myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", @"ssh://myserver:8080/", "defaultcollection", @"https://myserver:8080/tfs/defaultcollection", "myproject", - "myrepository")] - public void Should_Parse_Repo_Url(string repoUrl, string serverUrl, string collectionName, string collectionurl, string projectName, string repositoryName) + "myrepository", + @"https://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository")] + public void Should_Parse_Repo_Url( + string repoUrl, + string serverUrl, + string collectionName, + string collectionurl, + string projectName, + string repositoryName, + string repositoryUrl) { // Given / When var repositoryDescription = new RepositoryDescription(new Uri(repoUrl)); // Then - repositoryDescription.ServerUrl.ToString().ShouldBe(serverUrl); + repositoryDescription.ServerUrl.ShouldBe(new Uri(serverUrl)); repositoryDescription.CollectionName.ShouldBe(collectionName); repositoryDescription.CollectionUrl.ShouldBe(new Uri(collectionurl)); repositoryDescription.ProjectName.ShouldBe(projectName); repositoryDescription.RepositoryName.ShouldBe(repositoryName); + repositoryDescription.RepositoryUrl.ShouldBe(new Uri(repositoryUrl)); } } } diff --git a/src/TfsUrlParser/RepositoryDescription.cs b/src/TfsUrlParser/RepositoryDescription.cs index 963fb74..7191a9a 100644 --- a/src/TfsUrlParser/RepositoryDescription.cs +++ b/src/TfsUrlParser/RepositoryDescription.cs @@ -22,7 +22,9 @@ public RepositoryDescription(Uri repoUrl) throw new ArgumentNullException(nameof(repoUrl)); } - var repoUrlString = ConvertToSupportedUriScheme(repoUrl).ToString(); + this.RepositoryUrl = ConvertToSupportedUriScheme(repoUrl); + var repoUrlString = this.RepositoryUrl.ToString(); + var gitSeparator = new[] { "/_git/" }; var splitPath = repoUrl.AbsolutePath.Split(gitSeparator, StringSplitOptions.None); if (splitPath.Length < 2) @@ -74,6 +76,12 @@ public RepositoryDescription(Uri repoUrl) /// public string RepositoryName { get; private set; } + /// + /// Gets the URL of the Git repository. + /// URLs using SSH scheme are converted to HTTPS. + /// + public Uri RepositoryUrl { get; private set; } + /// /// Converts the repository URL to a supported scheme if possible. ///