Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable all TFS URL's #144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 112 additions & 3 deletions src/TfsUrlParser.Tests/RepositoryDescriptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
public class RepositoryDescriptionTests
{
[Theory]
[InlineData(
christianbumann marked this conversation as resolved.
Show resolved Hide resolved
@"http://myserver:8080/tfs/defaultcollection/myproject/",
"No valid Git repository URL.")]
[InlineData(
@"http://myserver:8080/tfs/defaultcollection/myproject/_git",
"No valid Git repository URL.")]
Expand All @@ -25,6 +22,7 @@ public void Should_Throw_If_No_Valid_Url(string repoUrl, string expectedMessage)
var result = Record.Exception(() => new RepositoryDescription(new Uri(repoUrl)));

// Then

result.IsUriFormatExceptionException(expectedMessage);
}

Expand Down Expand Up @@ -192,6 +190,117 @@ public void Should_Parse_Repo_Url(
repositoryDescription.ProjectName.ShouldBe(projectName);
repositoryDescription.RepositoryName.ShouldBe(repositoryName);
repositoryDescription.RepositoryUrl.ShouldBe(new Uri(repositoryUrl));
repositoryDescription.IsRepository.ShouldBe(true);
}

[Theory]
[InlineData(
@"http://myserver:8080/tfs/defaultcollection/myproject/",
@"http://myserver:8080/",
"defaultcollection",
@"http://myserver:8080/tfs/defaultcollection",
"myproject")]
[InlineData(
@"http://tfs.myserver/defaultcollection/myproject/",
@"http://tfs.myserver/",
"defaultcollection",
@"http://tfs.myserver/defaultcollection",
"myproject")]
[InlineData(
@"http://mytenant.visualstudio.com/defaultcollection/myproject/",
@"http://mytenant.visualstudio.com/",
"defaultcollection",
@"http://mytenant.visualstudio.com/defaultcollection",
"myproject")]
[InlineData(
@"http://tfs.foo.com/foo/foo",
@"http://tfs.foo.com/",
"foo",
@"http://tfs.foo.com/foo",
"foo")]
[InlineData(
@"https://myserver:8080/tfs/defaultcollection/myproject/",
@"https://myserver:8080/",
"defaultcollection",
@"https://myserver:8080/tfs/defaultcollection",
"myproject")]
[InlineData(
@"https://tfs.myserver/defaultcollection/myproject/",
@"https://tfs.myserver/",
"defaultcollection",
@"https://tfs.myserver/defaultcollection",
"myproject")]
[InlineData(
@"https://mytenant.visualstudio.com/defaultcollection/myproject/",
@"https://mytenant.visualstudio.com/",
"defaultcollection",
@"https://mytenant.visualstudio.com/defaultcollection",
"myproject")]
[InlineData(
@"https://tfs.foo.com/foo/foo/",
@"https://tfs.foo.com/",
"foo",
@"https://tfs.foo.com/foo",
"foo")]
[InlineData(
@"ssh://myserver:8080/tfs/defaultcollection/myproject/",
@"ssh://myserver:8080/",
"defaultcollection",
@"https://myserver:8080/tfs/defaultcollection",
"myproject")]
[InlineData(
@"ssh://tfs.myserver/defaultcollection/myproject/",
@"ssh://tfs.myserver/",
"defaultcollection",
@"https://tfs.myserver/defaultcollection",
"myproject")]
[InlineData(
@"ssh://mytenant.visualstudio.com/defaultcollection/myproject/",
@"ssh://mytenant.visualstudio.com/",
"defaultcollection",
@"https://mytenant.visualstudio.com/defaultcollection",
"myproject")]
[InlineData(
@"ssh://tfs.foo.com/foo/foo/",
@"ssh://tfs.foo.com/",
"foo",
@"https://tfs.foo.com/foo",
"foo")]
[InlineData(
@"ssh://foo:bar@myserver:8080/tfs/defaultcollection/myproject/",
@"ssh://myserver:8080/",
"defaultcollection",
@"https://myserver:8080/tfs/defaultcollection",
"myproject")]
[InlineData(
@"https://myorganization@dev.azure.com/myorganization/myproject/",
@"https://myorganization@dev.azure.com/",
"myorganization",
@"https://myorganization@dev.azure.com/myorganization",
"myproject")]
[InlineData(
@"https://myorganization.visualstudio.com/myproject/",
@"https://myorganization.visualstudio.com/",
"DefaultCollection",
@"https://myorganization.visualstudio.com",
"myproject")]
public void Should_Parse_NonRepo_Url(
string repoUrl,
string serverUrl,
string collectionName,
string collectionurl,
string projectName)
{
// Given / When
var repositoryDescription = new RepositoryDescription(new Uri(repoUrl));

// Then
repositoryDescription.ServerUrl.ShouldBe(new Uri(serverUrl));
repositoryDescription.CollectionName.ShouldBe(collectionName);
repositoryDescription.CollectionUrl.ShouldBe(new Uri(collectionurl));
repositoryDescription.ProjectName.ShouldBe(projectName);
repositoryDescription.IsRepository.ShouldBe(false);
}

}
}
26 changes: 20 additions & 6 deletions src/TfsUrlParser/RepositoryDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ public RepositoryDescription(Uri repoUrl)

var gitSeparator = new[] { "/_git/" };
var splitPath = repoUrl.AbsolutePath.Split(gitSeparator, StringSplitOptions.None);
if (splitPath.Length < 2)
if (repoUrl.ToString().Contains("/_git/"))
{
throw new UriFormatException("No valid Git repository URL.");
this.IsRepository = true;
if (splitPath.Length < 2)
{
throw new UriFormatException("No valid Git repository URL.");
}
} else
MrHinsh marked this conversation as resolved.
Show resolved Hide resolved
{
this.IsRepository = false;
}

this.ServerUrl = new Uri(repoUrl.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped));
Expand All @@ -56,11 +63,13 @@ public RepositoryDescription(Uri repoUrl)
{
throw new UriFormatException("No valid Git repository URL containing default collection and project name.");
}

var splitLastPart = splitPath[1].Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

this.ProjectName = splitFirstPart.Last();
this.RepositoryName = splitLastPart.First();

if (this.IsRepository)
{
var splitLastPart = splitPath[1].Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
this.RepositoryName = splitLastPart.First();
}
}

/// <summary>
Expand Down Expand Up @@ -94,6 +103,11 @@ public RepositoryDescription(Uri repoUrl)
/// </summary>
public Uri RepositoryUrl { get; private set; }

/// <summary>
/// Get a value that indicates if this is a Git Repo or another TFS URL.
/// </summary>
public bool IsRepository { get; private set; }

/// <summary>
/// Converts the repository URL to a supported scheme if possible.
/// </summary>
Expand Down