Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic to convert internal repo uris in version.details.xml #12852

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
Expand All @@ -21,6 +22,11 @@ public class Tarball_ReadSourceBuildIntermediateNupkgDependencies : Task
[Required]
public string SourceBuildIntermediateNupkgPrefix { get; set; }

/// <summary>
/// Convert any internal repo references to the public GitHub repos.
/// </summary>
public bool ConvertInternalRepos { get; set; }

/// <summary>
/// The intermediate nupkg RID to use if any RID-specific intermediate nupkgs are required.
/// If this parameter isn't specified, RID-specific intermediate nupkgs can't be used and
Expand Down Expand Up @@ -88,6 +94,11 @@ XName CreateQualifiedName(string plainName)
string dependencyVersion = d.Attribute("Version")?.Value;

string uri = d.Element(CreateQualifiedName("Uri"))?.Value;
if (ConvertInternalRepos)
{
uri = ConvertInternalRepo(uri);
}

string sha = d.Element(CreateQualifiedName("Sha"))?.Value;
string sourceBuildRepoName = sourceBuildElement.Attribute("RepoName")?.Value;

Expand Down Expand Up @@ -137,5 +148,33 @@ XName CreateQualifiedName(string plainName)

return !Log.HasLoggedErrors;
}

private string ConvertInternalRepo(string uri)
{
if (uri.StartsWith("https://dev.azure.com", StringComparison.OrdinalIgnoreCase))
{
string[] repoParts = uri.Substring(uri.LastIndexOf('/')).Split('-', 2);

if (repoParts.Length != 2)
{
Log.LogError($"Repo '{uri}' does not end with the expected <GH organization>-<GH repo> format");
return null;
}

string org = repoParts[0];
string repo = repoParts[1];

// The internal Nuget.Client repo has suffix which needs to be accounted for.
const string trustedSuffix = "-Trusted";
if (uri.EndsWith(trustedSuffix, StringComparison.OrdinalIgnoreCase))
{
repo = repo.Substring(0, repo.Length - trustedSuffix.Length);
}

uri = $"https://github.com/{org}/{repo}";
}

return uri;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<TarballSourceDir>$(TarballRootDir)src/</TarballSourceDir>
<TarballGitInfoDir>$(TarballRootDir)git-info/</TarballGitInfoDir>
<CloneVerbosity>quiet</CloneVerbosity> <!-- Support quiet and full -->
<ConvertInternalRepos Condition="'$(ConvertInternalRepos)' == '' and '$(VSS_NUGET_EXTERNAL_FEED_ENDPOINTS)' == '' ">true</ConvertInternalRepos>
</PropertyGroup>

<Target Name="CreateSourceTarball"
Expand Down Expand Up @@ -203,7 +204,8 @@
<Tarball_ReadSourceBuildIntermediateNupkgDependencies
VersionDetailsXmlFile="$([MSBuild]::NormalizePath($(TarballVersionDetailsFile)))"
SourceBuildIntermediateNupkgPrefix="$(SourceBuildIntermediateNupkgPrefix)"
SourceBuildIntermediateNupkgRid="$(SourceBuildIntermediateNupkgRid)">
SourceBuildIntermediateNupkgRid="$(SourceBuildIntermediateNupkgRid)"
ConvertInternalRepos="$(ConvertInternalRepos)">
<Output TaskParameter="Dependencies" ItemName="SourceBuildRepos" />
</Tarball_ReadSourceBuildIntermediateNupkgDependencies>

Expand Down