-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
Enable all TFS URL's
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.")] | ||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 GitHub Actions / build (ubuntu-latest)
Check warning on line 38 in src/TfsUrlParser/RepositoryDescription.cs GitHub Actions / build (ubuntu-latest)
|
||
{ | ||
this.IsRepository = false; | ||
} | ||
|
||
this.ServerUrl = new Uri(repoUrl.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped)); | ||
|
@@ -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 GitHub Actions / build (ubuntu-latest)
Check warning on line 65 in src/TfsUrlParser/RepositoryDescription.cs 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> | ||
|
@@ -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 GitHub Actions / build (ubuntu-latest)
Check warning on line 109 in src/TfsUrlParser/RepositoryDescription.cs GitHub Actions / build (ubuntu-latest)
|
||
|
||
/// <summary> | ||
/// Converts the repository URL to a supported scheme if possible. | ||
/// </summary> | ||
|