Skip to content

Commit 80135fa

Browse files
authored
FIx parsing of Azure Repos URLs whose project name is the same as repo name (#479)
1 parent b32f565 commit 80135fa

File tree

4 files changed

+8
-30
lines changed

4 files changed

+8
-30
lines changed
-4.26 KB
Loading

src/Common/AzureDevOpsUrlParser.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,16 @@ public static bool TryParseHostedHttp(string host, string relativeUrl, out strin
6363
return false;
6464
}
6565

66-
if (isVisualStudioHost)
67-
{
68-
projectPath = projectName ?? repositoryName;
69-
}
70-
else
66+
projectPath = projectName ?? repositoryName;
67+
68+
if (!isVisualStudioHost)
7169
{
72-
if (projectName == null || teamName != null)
70+
if (teamName != null)
7371
{
7472
return false;
7573
}
7674

77-
projectPath = account + "/" + projectName;
75+
projectPath = account + "/" + projectPath;
7876
}
7977

8078
return true;

src/SourceLink.AzureRepos.Git.UnitTests/AzureDevOpsUrlParserHostedTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void TryParseHostedHttp_Error(string host, string relativeUrl)
4949
[InlineData("account.vsts.me", "/DefaultCollection/project/team/_git/_full/repo", "project", "repo")]
5050
[InlineData("account.vsts.me", "/DefaultCollection/project/team/_git/_optimized/repo", "project", "repo")]
5151
[InlineData("account.vsts.me", "/DefaultCollection/_git/repo", "repo", "repo")]
52+
[InlineData("contoso.com", "/account/_git/repo", "account/repo", "repo")]
5253
[InlineData("contoso.com", "/account/project/_git/repo", "account/project", "repo")]
5354
[InlineData("contoso.com", "/account/project/_git/_full/repo", "account/project", "repo")]
5455
[InlineData("contoso.com", "/account/project/_git/_optimized/repo", "account/project", "repo")]

src/SourceLink.AzureRepos.Git.UnitTests/GetSourceLinkUrlTests.cs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public void BadUrl(string domainAndAccount, string host)
8080
[Theory]
8181
[InlineData("account.visualstudio.com", "visualstudio.com")]
8282
[InlineData("account.vsts.me", "vsts.me")]
83-
public void RepoOnly_VisualStudioHost(string domainAndAccount, string host)
83+
[InlineData("contoso.com/account", "contoso.com")]
84+
public void RepoOnly(string domainAndAccount, string host)
8485
{
8586
var engine = new MockEngine();
8687

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

100-
[Theory]
101-
[InlineData("contoso.com/account", "contoso.com")]
102-
public void RepoOnly_NonVisualStudioHost(string domainAndAccount, string host)
103-
{
104-
var engine = new MockEngine();
105-
106-
var task = new GetSourceLinkUrl()
107-
{
108-
BuildEngine = engine,
109-
SourceRoot = new MockItem("/src/", KVP("RepositoryUrl", $"http://{domainAndAccount}/_git/repo"), KVP("SourceControl", "git"), KVP("RevisionId", "0123456789abcdefABCDEF000000000000000000")),
110-
Hosts = new[] { new MockItem(host) }
111-
};
112-
113-
bool result = task.Execute();
114-
115-
// ERROR : The value of SourceRoot.RepositoryUrl with identity '/src/' is invalid: 'http://account.visualstudio.com/_git/repo'""
116-
AssertEx.AssertEqualToleratingWhitespaceDifferences(
117-
"ERROR : " + string.Format(CommonResources.ValueOfWithIdentityIsInvalid, "SourceRoot.RepositoryUrl", "/src/", $"http://{domainAndAccount}/_git/repo"), engine.Log);
118-
119-
Assert.False(result);
120-
}
121-
122101
[Theory]
123102
[InlineData("account.visualstudio.com", "visualstudio.com")]
124103
[InlineData("account.vsts.me", "vsts.me")]

0 commit comments

Comments
 (0)