Skip to content

Commit

Permalink
Add logic to convert internal repo uris in version.details.xml (#12852)
Browse files Browse the repository at this point in the history
* Add logic to convert internal repo uris in version.details.xml

* code review updates
  • Loading branch information
MichaelSimons committed Dec 17, 2021
1 parent f58d51e commit 586476f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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

0 comments on commit 586476f

Please sign in to comment.