Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,18 @@ public void CompatibleBuildDataWithDuplicatedAssets()
Action act = () => pushMetadata.MergeBuildManifests(ExpectedBuildDataIncompatibleList);
act.Should().Throw<Exception>().WithMessage("Can't merge if one or more manifests have different branch, build number, commit, or repository values.");
}

[TestCase("https://github.com/dotnet/trusted-packages", "trusted/packages")]
[TestCase("https://github.com/dotnet/trusted-packages", "trusted/packages")]
[TestCase("https://dev.azure.com/dnceng/internal/_git/dotnet-trusted-packages", "dotnet/trusted-packages")]
[TestCase("https://dev.azure.com/devdiv/DevDiv/_git/dotnet-trusted-packages-trusted", "dotnet/trusted-packages")]
[TestCase("https://dev.azure.com/dnceng/internal/_git/dotnet-images-trusted", "dotnet/images-trusted")]
[TestCase("https://dev.azure.com/devdiv/DevDiv/_git/dotnet-images-trusted-trusted", "dotnet/images-trusted")]
[TestCase("https://dev.azure.com/devdiv/DevDiv/_git/NuGet-NuGet.Client-Trusted", "nuget/nuget.client")]
public void GetGithubRepoNameTest(string azdoRepoUrl , string expectedRepo )
{
string actualRepo = pushMetadata.GetGithubRepoName(azdoRepoUrl);
Assert.AreEqual(expectedRepo,actualRepo);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,7 @@ private void LookupForMatchingGitHubRepository(BuildData mergedBuild)
}
else
{
string[] segments = mergedBuild.AzureDevOpsRepository.Split('/');
string repoName = segments[segments.Length - 1];
int index = repoName.IndexOf('-');

StringBuilder builder = new StringBuilder(repoName);
builder[index] = '/';

repoIdentity = builder.ToString();
repoIdentity = GetGithubRepoName(mergedBuild.AzureDevOpsRepository);
}

client.BaseAddress = new Uri($"https://api.{gitHubHost}");
Expand All @@ -606,6 +599,29 @@ private void LookupForMatchingGitHubRepository(BuildData mergedBuild)
}
}

/// <summary>
/// Get repo name from the AzdoRepo url
/// </summary>
/// <param name="repoUrl"></param>
/// <returns></returns>
public string GetGithubRepoName(string repoUrl)
{
string[] segments = repoUrl.Split('/');
string repoName = segments[segments.Length - 1].ToLower();

if (repoUrl.Contains("DevDiv", StringComparison.OrdinalIgnoreCase)
&& repoName.EndsWith("-Trusted", StringComparison.OrdinalIgnoreCase))
{
repoName = repoName.Remove(repoName.LastIndexOf("-trusted"));
}
int index = repoName.IndexOf('-');

StringBuilder builder = new StringBuilder(repoName);
builder[index] = '/';

return builder.ToString();
}

/// <summary>
/// Creates an AssetData object for the merged manifest so it can be injected
/// in itself
Expand Down