Skip to content

Commit

Permalink
Merge pull request #144 from MrHinsh/enableSupportForAllTfsUrls
Browse files Browse the repository at this point in the history
Enable all TFS URL's
  • Loading branch information
christianbumann authored Sep 2, 2024
2 parents 48ae73a + f640b83 commit bf2d7be
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 9 deletions.
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(
@"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://[email protected]/myorganization/myproject/",
@"https://[email protected]/",
"myorganization",
@"https://[email protected]/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

Check warning on line 38 in src/TfsUrlParser/RepositoryDescription.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Check warning on line 38 in src/TfsUrlParser/RepositoryDescription.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

{
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.");
}

Check warning on line 65 in src/TfsUrlParser/RepositoryDescription.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Check warning on line 65 in src/TfsUrlParser/RepositoryDescription.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)


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; }

Check warning on line 109 in src/TfsUrlParser/RepositoryDescription.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The property's documentation summary text should begin with: 'Gets a value indicating whether' (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1623.md)

Check warning on line 109 in src/TfsUrlParser/RepositoryDescription.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The property's documentation summary text should begin with: 'Gets a value indicating whether' (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1623.md)

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

0 comments on commit bf2d7be

Please sign in to comment.