Skip to content
This repository was archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
Adding support for TFS collections on VisualStudio.com
Browse files Browse the repository at this point in the history
  • Loading branch information
Shai Nahum committed Aug 24, 2017
1 parent 6c6c91f commit 8d57593
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Andrew Arnott <[email protected]>
Geert van Horrik <[email protected]>
Wesley Eledui <[email protected]>
Marek Fišera <[email protected]>
Shai Nahum <[email protected]>
Original file line number Diff line number Diff line change
Expand Up @@ -35,60 +35,47 @@ public void ReturnsInValidInitialization()
[TestFixture]
public class TheVisualStudioTeamServicesProviderProperties
{
[TestCase]
public void ReturnsValidCompany()
[TestCase("https://CatenaLogic.visualstudio.com/_git/main-repo", "main-repo")]
[TestCase("https://CatenaLogic.visualstudio.com/BigProject/_git/main-repo", "BigProject")]
[TestCase("https://CatenaLogic.visualstudio.com/DefaultCollection/BigProject/_git/main-repo", "BigProject")]
public void ReturnsValidProject(string url, string expectedProjectName)
{
var provider = new VisualStudioTeamServicesProvider();
provider.Initialize("https://CatenaLogic.visualstudio.com/_git/main-repo");
provider.Initialize(url);

Assert.AreEqual("CatenaLogic", provider.CompanyName);
Assert.AreEqual(expectedProjectName, provider.ProjectName);
}

[TestCase]
public void ReturnsValidCompanyUrl()
[TestCase("https://CatenaLogic.visualstudio.com/_git/main-repo", "CatenaLogic")]
public void ReturnsValidCompany(string url, string expectedCompanyName)
{
var provider = new VisualStudioTeamServicesProvider();
provider.Initialize("https://CatenaLogic.visualstudio.com/_git/main-repo");
provider.Initialize(url);

Assert.AreEqual("https://CatenaLogic.visualstudio.com/", provider.CompanyUrl);
Assert.AreEqual(expectedCompanyName, provider.CompanyName);
}

[TestCase]
public void ReturnsValidProject()
[TestCase("https://CatenaLogic.visualstudio.com/Project/_git/main-repo", "main-repo")]
[TestCase("https://CatenaLogic.visualstudio.com/Project/_git/main.repo", "main.repo")]
[TestCase("https://CatenaLogic.visualstudio.com/DefaultCollection/Project/_git/main.repo", "main.repo")]
public void ReturnsValidRepositoryName(string url, string expectedProjectUrl)
{
var provider = new VisualStudioTeamServicesProvider();
provider.Initialize("https://CatenaLogic.visualstudio.com/_git/main-repo");
provider.Initialize(url);

Assert.AreEqual("main-repo", provider.ProjectName);
Assert.AreEqual(expectedProjectUrl, provider.ProjectUrl);
}

[TestCase]
public void ReturnsValidProject2()
[TestCase("https://CatenaLogic.visualstudio.com/_git/main-repo", "https://CatenaLogic.visualstudio.com/")]
[TestCase("https://CatenaLogic.visualstudio.com/DefaultCollection/BigProject/_git/main-repo", "https://CatenaLogic.visualstudio.com/DefaultCollection/")]
[TestCase("https://CatenaLogic.visualstudio.com/Other.Collection/BigProject/_git/main-repo", "https://CatenaLogic.visualstudio.com/Other.Collection/")]
public void ReturnsValidCompanyUrl(string url, string expectedCompanyUrl)
{
var provider = new VisualStudioTeamServicesProvider();
provider.Initialize("https://CatenaLogic.visualstudio.com/BigProject/_git/main-repo");
provider.Initialize(url);

Assert.AreEqual("BigProject", provider.ProjectName);
Assert.AreEqual(expectedCompanyUrl, provider.CompanyUrl);
}

[TestCase]
public void ReturnsValidRepositoryName()
{
var provider = new VisualStudioTeamServicesProvider();
provider.Initialize("https://CatenaLogic.visualstudio.com/Project/_git/main-repo");

Assert.AreEqual("main-repo", provider.ProjectUrl);
}

[TestCase]
public void ReturnsValidRepositoryNameWhenContainsPeriod()
{
var provider = new VisualStudioTeamServicesProvider();
provider.Initialize("https://CatenaLogic.visualstudio.com/Big.Project/_git/main.repo");

Assert.AreEqual("main.repo", provider.ProjectUrl);
}

}
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/GitLink/Providers/VisualStudioTeamServicesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,24 @@ namespace GitLink.Providers

public class VisualStudioTeamServicesProvider : ProviderBase
{
private static readonly Regex HostingUrlPattern = new Regex(@"(?<url>(?<companyurl>(?:https://)?(?<accountname>([a-zA-Z0-9\-\.]*)?)\.visualstudio\.com/)(?<project>[a-zA-Z0-9\-\.]*)/?_git//?(?<repo>[^/]+))");
// Matches the git origin URL, providing named capture groups
// Example match: https://user.visualstudio.com/DefaultCollection/MyFirstProject/_git/MyFirstRepo
private static readonly Regex HostingUrlPattern =
new Regex(
@"(?<companyurl>
(?:https://)?
(?<accountname>([a-zA-Z0-9\-\.]*)?) # account name (e.g. user)
\.visualstudio\.com/
(
[a-zA-Z0-9\-\.]+/ # collection (optional). e.g. DefaultCollection/
(?!/?_git/) # Negative lookahead to avoid capturing 'project' group
)?
)
(?<project>[a-zA-Z0-9\-\.]*) # project name. e.g. MyFirstProject
(?<git>/?_git//?)
(?<repo>[^/]+) # the repository's name. e.g. MyFirstRepo
",
RegexOptions.IgnorePatternWhitespace);

public VisualStudioTeamServicesProvider()
: base(new GitPreparer())
Expand Down

0 comments on commit 8d57593

Please sign in to comment.