Skip to content

Commit

Permalink
Merge pull request #12 from bbtsoftware/feature/repo-clone-url
Browse files Browse the repository at this point in the history
Provide converted repository URL for SSH URLs
  • Loading branch information
pascalberger authored Sep 7, 2017
2 parents feaba18 + 99de697 commit 322d774
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 19 deletions.
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

0 comments on commit 322d774

Please sign in to comment.