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

Provide converted repository URL for SSH URLs #12

Merged
merged 1 commit into from
Sep 7, 2017
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
60 changes: 42 additions & 18 deletions src/TfsUrlParser.Tests/RepositoryDescriptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
10 changes: 9 additions & 1 deletion src/TfsUrlParser/RepositoryDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -74,6 +76,12 @@ public RepositoryDescription(Uri repoUrl)
/// </summary>
public string RepositoryName { get; private set; }

/// <summary>
/// Gets the URL of the Git repository.
/// URLs using SSH scheme are converted to HTTPS.
/// </summary>
public Uri RepositoryUrl { get; private set; }

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