Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/Common/GitProvider/GetSourceLinkUrlGitTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the License.txt file in the project root for more information.

Expand Down Expand Up @@ -222,7 +222,7 @@ static bool IsValidContentUri(Uri uri)
}
}

private static bool TryGetMatchingContentUri(UrlMapping[] mappings, Uri repoUri, [NotNullWhen(true)]out Uri? contentUri, out ITaskItem? hostItem)
private static bool TryGetMatchingContentUri(UrlMapping[] mappings, Uri repoUri, [NotNullWhen(true)] out Uri? contentUri, out ITaskItem? hostItem)
{
UrlMapping? FindMatch(bool exactHost)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public void TryParseHostedHttp_Error(string host, string relativeUrl)
[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")]
[InlineData("dev.azure.com", "/org/project/_git/repo.git", "org/project", "repo.git")]
[InlineData("dev.azure.com", "/org/project/_git/repo.git/", "org/project", "repo.git")]
[InlineData("account.visualstudio.com", "/DefaultCollection/project/_git/repo.git", "project", "repo.git")]

public void TryParseHostedHttp_Success(string host, string relativeUrl, string repositoryPath, string repositoryName)
{
Assert.True(AzureDevOpsUrlParser.TryParseHostedHttp(host, relativeUrl, out var actualRepositoryPath, out var actualRepositoryName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public void BadUrl(string domainAndAccount, string host)

var result = task.Execute();

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

Expand Down Expand Up @@ -155,7 +154,6 @@ public void Project_Team_NonVisualStudioHost()

var result = task.Execute();

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

Expand Down Expand Up @@ -285,5 +283,56 @@ public void VisualStudioHost_ImplicitHost_DeafultCollection_Project_Team(string
AssertEx.AreEqual($"https://{domain}/project/_apis/git/repositories/repo/items?api-version=1.0&versionType=commit&version=0123456789abcdefABCDEF000000000000000000&path=/*", task.SourceLinkUrl);
Assert.True(result);
}

[Fact]
public void DevAzureCom_RepositoryName_WithDotGit_IsNotIgnored()
{
var urlWithoutDotGit = ExecuteDevAzureCom("https://dev.azure.com/org/project/_git/repo");
var urlWithDotGit = ExecuteDevAzureCom("https://dev.azure.com/org/project/_git/repo.git");

Assert.True(
!string.Equals(urlWithoutDotGit, urlWithDotGit, StringComparison.Ordinal),
$"Repository name is ignored: URLs are identical.\n" +
$"Input without .git: https://dev.azure.com/org/project/_git/repo\n" +
$"Input with .git: https://dev.azure.com/org/project/_git/repo.git\n" +
$"Output: {urlWithoutDotGit}");
}

[Fact]
public void DevAzureCom_RepositoryName_WithDotGit_IsPreservedInOutput()
{
var url = ExecuteDevAzureCom("https://dev.azure.com/org/project/_git/repo.git");

// Ensure the '.git' suffix is preserved in the repository segment of the URL, not just anywhere.
Assert.Contains(
"project/_apis/git/repositories/repo.git/items",
url);
}

private static string ExecuteDevAzureCom(string repositoryUrl)
{
var engine = new MockEngine();

var task = new GetSourceLinkUrl()
{
BuildEngine = engine,
SourceRoot = new MockItem("/src/",
KVP("RepositoryUrl", repositoryUrl),
KVP("SourceControl", "git"),
KVP("RevisionId", "0123456789abcdefABCDEF000000000000000000")),
Hosts = new[]
{
new MockItem("dev.azure.com")
}
};

var result = task.Execute();

AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log);
Assert.True(result);
Assert.False(string.IsNullOrEmpty(task.SourceLinkUrl));

return task.SourceLinkUrl!;
}
}
}
2 changes: 1 addition & 1 deletion src/SourceLink.AzureRepos.Git/GetSourceLinkUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override Uri GetDefaultContentUriFromRepositoryUri(Uri repositoryUri)

protected override string? BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem? hostItem)
{
if (!AzureDevOpsUrlParser.TryParseHostedHttp(gitUri.GetHost(), relativeUrl, out var projectPath, out var repositoryName))
if (!AzureDevOpsUrlParser.TryParseHostedHttp(gitUri.GetHost(), gitUri.GetPath(), out var projectPath, out var repositoryName))
{
Log.LogError(CommonResources.ValueOfWithIdentityIsInvalid, Names.SourceRoot.RepositoryUrlFullName, SourceRoot!.ItemSpec, gitUri);
return null;
Expand Down
Loading