Skip to content

Commit

Permalink
FIx parsing of Azure Repos URLs whose project name is the same as rep…
Browse files Browse the repository at this point in the history
…o name (#479)
  • Loading branch information
tmat committed Nov 3, 2019
1 parent b32f565 commit 80135fa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
Binary file modified docs/Implementation/AzureDevOpsServicesUrls.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 5 additions & 7 deletions src/Common/AzureDevOpsUrlParser.cs
Expand Up @@ -63,18 +63,16 @@ public static bool TryParseHostedHttp(string host, string relativeUrl, out strin
return false;
}

if (isVisualStudioHost)
{
projectPath = projectName ?? repositoryName;
}
else
projectPath = projectName ?? repositoryName;

if (!isVisualStudioHost)
{
if (projectName == null || teamName != null)
if (teamName != null)
{
return false;
}

projectPath = account + "/" + projectName;
projectPath = account + "/" + projectPath;
}

return true;
Expand Down
Expand Up @@ -49,6 +49,7 @@ public void TryParseHostedHttp_Error(string host, string relativeUrl)
[InlineData("account.vsts.me", "/DefaultCollection/project/team/_git/_full/repo", "project", "repo")]
[InlineData("account.vsts.me", "/DefaultCollection/project/team/_git/_optimized/repo", "project", "repo")]
[InlineData("account.vsts.me", "/DefaultCollection/_git/repo", "repo", "repo")]
[InlineData("contoso.com", "/account/_git/repo", "account/repo", "repo")]
[InlineData("contoso.com", "/account/project/_git/repo", "account/project", "repo")]
[InlineData("contoso.com", "/account/project/_git/_full/repo", "account/project", "repo")]
[InlineData("contoso.com", "/account/project/_git/_optimized/repo", "account/project", "repo")]
Expand Down
25 changes: 2 additions & 23 deletions src/SourceLink.AzureRepos.Git.UnitTests/GetSourceLinkUrlTests.cs
Expand Up @@ -80,7 +80,8 @@ public void BadUrl(string domainAndAccount, string host)
[Theory]
[InlineData("account.visualstudio.com", "visualstudio.com")]
[InlineData("account.vsts.me", "vsts.me")]
public void RepoOnly_VisualStudioHost(string domainAndAccount, string host)
[InlineData("contoso.com/account", "contoso.com")]
public void RepoOnly(string domainAndAccount, string host)
{
var engine = new MockEngine();

Expand All @@ -97,28 +98,6 @@ public void RepoOnly_VisualStudioHost(string domainAndAccount, string host)
Assert.True(result);
}

[Theory]
[InlineData("contoso.com/account", "contoso.com")]
public void RepoOnly_NonVisualStudioHost(string domainAndAccount, string host)
{
var engine = new MockEngine();

var task = new GetSourceLinkUrl()
{
BuildEngine = engine,
SourceRoot = new MockItem("/src/", KVP("RepositoryUrl", $"http://{domainAndAccount}/_git/repo"), KVP("SourceControl", "git"), KVP("RevisionId", "0123456789abcdefABCDEF000000000000000000")),
Hosts = new[] { new MockItem(host) }
};

bool result = task.Execute();

// ERROR : The value of SourceRoot.RepositoryUrl with identity '/src/' is invalid: 'http://account.visualstudio.com/_git/repo'""
AssertEx.AssertEqualToleratingWhitespaceDifferences(
"ERROR : " + string.Format(CommonResources.ValueOfWithIdentityIsInvalid, "SourceRoot.RepositoryUrl", "/src/", $"http://{domainAndAccount}/_git/repo"), engine.Log);

Assert.False(result);
}

[Theory]
[InlineData("account.visualstudio.com", "visualstudio.com")]
[InlineData("account.vsts.me", "vsts.me")]
Expand Down

0 comments on commit 80135fa

Please sign in to comment.