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

[ReleasePrep][2023.12.13]RI of dev into main for NuGetGallery #9755

Merged
merged 7 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -7,13 +7,13 @@

namespace NuGetGallery.Frameworks
{
public class FrameworkCompatibilityService : IFrameworkCompatibilityService
public static class FrameworkCompatibilityService
{
private static readonly IFrameworkCompatibilityProvider CompatibilityProvider = DefaultCompatibilityProvider.Instance;
private static readonly IReadOnlyList<NuGetFramework> AllSupportedFrameworks = SupportedFrameworks.AllSupportedNuGetFrameworks;
private static readonly IReadOnlyDictionary<NuGetFramework, ISet<NuGetFramework>> CompatibilityMatrix = GetCompatibilityMatrix();

public ISet<NuGetFramework> GetCompatibleFrameworks(IEnumerable<NuGetFramework> packageFrameworks)
public static ISet<NuGetFramework> GetCompatibleFrameworks(IEnumerable<NuGetFramework> packageFrameworks)
{
if (packageFrameworks == null)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ public class PackageFrameworkCompatibilityFactory : IPackageFrameworkCompatibili
private readonly NuGetFrameworkSorter Sorter = new NuGetFrameworkSorter();
private readonly int NetStartingMajorVersion = 5;

private readonly IFrameworkCompatibilityService _compatibilityService;

public PackageFrameworkCompatibilityFactory(IFrameworkCompatibilityService compatibilityService)
{
_compatibilityService = compatibilityService ?? throw new ArgumentNullException();
}

public PackageFrameworkCompatibility Create(ICollection<PackageFramework> packageFrameworks)
{
if (packageFrameworks == null)
Expand All @@ -53,7 +46,7 @@ public PackageFrameworkCompatibility Create(ICollection<PackageFramework> packag

private IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityTableData>> CreateFrameworkCompatibilityTable(ICollection<NuGetFramework> filteredPackageFrameworks)
{
var compatibleFrameworks = _compatibilityService.GetCompatibleFrameworks(filteredPackageFrameworks);
var compatibleFrameworks = FrameworkCompatibilityService.GetCompatibleFrameworks(filteredPackageFrameworks);

var table = new Dictionary<string, SortedSet<PackageFrameworkCompatibilityTableData>>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PackageFrameworkCompatibilityTableData
public NuGetFramework Framework { get; set; }

/// <summary>
/// <see langword="true"/> if the <see cref="Framework"/> was computed from <see cref="IFrameworkCompatibilityService"/>.<br></br>
/// <see langword="true"/> if the <see cref="Framework"/> was computed from <see cref="FrameworkCompatibilityService"/>.<br></br>
/// <see langword="false"/> if the <see cref="Framework"/> was retrieved from the package asset frameworks.
/// </summary>
public bool IsComputed { get; set; }
Expand Down
5 changes: 0 additions & 5 deletions src/NuGetGallery/App_Start/DefaultDependenciesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,6 @@ protected override void Load(ContainerBuilder builder)
.As<IPackageVulnerabilitiesCacheService>()
.SingleInstance();

builder.RegisterType<FrameworkCompatibilityService>()
.AsSelf()
.As<IFrameworkCompatibilityService>()
.SingleInstance();

builder.RegisterType<PackageFrameworkCompatibilityFactory>()
.AsSelf()
.As<IPackageFrameworkCompatibilityFactory>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web.Mvc;
using NuGetGallery.Areas.Admin.Models;
using NuGetGallery.Areas.Admin.ViewModels;

namespace NuGetGallery.Areas.Admin.Controllers
{
public class CorrectIsLatestController : AdminControllerBase
{
private readonly IPackageService _packageService;
private readonly IEntitiesContext _entitiesContext;
private readonly IPackageFileService _packageFileService;
private readonly ITelemetryService _telemetryService;

public CorrectIsLatestController(IPackageService packageService, IEntitiesContext entitiesContext, IPackageFileService packageFileService, ITelemetryService telemetryService)
{
_packageService = packageService ?? throw new ArgumentNullException(nameof(packageService));
_entitiesContext = entitiesContext ?? throw new ArgumentNullException(nameof(entitiesContext));
_packageFileService = packageFileService ?? throw new ArgumentNullException(nameof(packageFileService));
_telemetryService = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
}

[HttpGet]
public ActionResult Index()
{
return View();
}

[HttpGet]
public ActionResult CorrectIsLatestPackages()
{
var result = _entitiesContext
.PackageRegistrations
.Where(pr => pr.Packages.Any(p => p.IsLatest || p.IsLatestStable || p.IsLatestSemVer2 || p.IsLatestStableSemVer2))
.Select(pr => new CorrectIsLatestPackage()
{
Id = pr.Id,
Version = pr.Packages
.Where(p => p.IsLatest || p.IsLatestStable || p.IsLatestSemVer2 || p.IsLatestStableSemVer2)
.FirstOrDefault()
.Version,
IsLatestCount = pr.Packages.Where(p => p.IsLatest).Count(),
IsLatestStableCount = pr.Packages.Where(p => p.IsLatestStable).Count(),
IsLatestSemVer2Count = pr.Packages.Where(p => p.IsLatestSemVer2).Count(),
IsLatestStableSemVer2Count = pr.Packages.Where(p => p.IsLatestStableSemVer2).Count(),
HasIsLatestUnlisted = pr.Packages.Any(p =>
!p.Listed
&& (p.IsLatest
|| p.IsLatestStable
|| p.IsLatestSemVer2
|| p.IsLatestStableSemVer2))
})
.Where(pr => pr.IsLatestCount > 1
|| pr.IsLatestStableCount > 1
|| pr.IsLatestSemVer2Count > 1
|| pr.IsLatestStableSemVer2Count > 1
|| pr.HasIsLatestUnlisted)
.OrderBy(pr => pr.Id)
.ToList();

return Json(result, JsonRequestBehavior.AllowGet);
}

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ReflowPackages(CorrectIsLatestRequest request)
{
if (request == null || request.Packages == null || request.Packages.Count == 0)
{
return Json(HttpStatusCode.BadRequest, "Packages cannot be null or empty.", JsonRequestBehavior.AllowGet);
}

var reflowPackageService = new ReflowPackageService(
_entitiesContext,
(PackageService)_packageService,
_packageFileService,
_telemetryService);

var totalPackagesReflowed = 0;
var totalPackagesFailReflowed = 0;

foreach (var package in request.Packages)
{
try
{
await reflowPackageService.ReflowAsync(package.Id, package.Version);
totalPackagesReflowed++;
}
catch (Exception ex)
{
ex.Log();
totalPackagesFailReflowed++;
}
}

var reflowedPackagesMessage = totalPackagesReflowed == 1 ? $"{totalPackagesReflowed} package reflowed" : $"{totalPackagesReflowed} packages reflowed";
var failedPackagesMessage = totalPackagesFailReflowed == 1 ? $"{totalPackagesFailReflowed} package fail reflow" : $"{totalPackagesFailReflowed} packages fail reflow";

return Json(HttpStatusCode.OK, $"{reflowedPackagesMessage}, {failedPackagesMessage}.", JsonRequestBehavior.AllowGet);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,55 @@ public ActionResult ValidateInputs(string packagesFromInput, string packagesToIn
}

// create validated input result
var input = new PopularityTransferItem(CreatePackageSearchResult(packageFrom.Packages.First()),
CreatePackageSearchResult(packageTo.Packages.First()),
packageFrom.Key,
packageTo.Key);
result.ValidatedInputs.Add(new PopularityTransferItem(packageFrom, packageTo));

result.ValidatedInputs.Add(input);
// checking for existing entries in the PackageRenames table
// 1. 'From' input that already has a 'From' entry in the PackageRenames table -- Conflict
var existingRenames = _packageRenameService.GetPackageRenames(packageFrom);

// check for existing entries in the PackageRename table for the 'From' packages
var existingRenamesFrom = _packageRenameService.GetPackageRenames(packageFrom);

if (existingRenamesFrom.Any())
if (existingRenames.Any())
{
if (existingRenamesFrom.Count == 1)
if (existingRenames.Count == 1)
{
var existingRenamesMessage = $"{packageFrom.Id} already has 1 entry in the PackageRenames table. This will be removed with this operation.";
result.ExistingPackageRenames.Add(existingRenamesMessage);
result.ExistingPackageRenamesMessagesConflict.Add($"{packageFrom.Id} already has 1 entry in the PackageRenames table. This will be removed with this operation.");
}
else
{
var existingRenamesMessage = $"{packageFrom.Id} already has {existingRenamesFrom.Count} entries in the PackageRenames table. These will be removed with this operation.";
result.ExistingPackageRenames.Add(existingRenamesMessage);
result.ExistingPackageRenamesMessagesConflict.Add($"{packageFrom.Id} already has {existingRenames.Count} entries in the PackageRenames table. These will be removed with this operation.");
}

foreach (var existingRename in existingRenames)
{
result.ExistingPackageRenamesConflict.Add(new PopularityTransferItem(existingRename.FromPackageRegistration, existingRename.ToPackageRegistration));
}
}

// 2. 'From' input that already has a 'To' entry in the PackageRenames table -- Transitive
existingRenames = _packageRenameService.GetPackageRenamesTo(packageFrom);

if (existingRenames.Any())
{
var existingRenamesMessage = $"{packageFrom.Id} already has entries in the PackageRenames table. This popularity transfer will result in a new transitive relationship. Please look at the PackageRenames table and verify your input before proceeding.";
result.ExistingPackageRenamesMessagesTransitive.Add(existingRenamesMessage);

foreach (var existingRename in existingRenames)
{
result.ExistingPackageRenamesTransitive.Add(new PopularityTransferItem(existingRename.FromPackageRegistration, existingRename.ToPackageRegistration));
}
}

// check for existing entries in the PackageRename table for the 'To' packages
var existingRenamesTo = _packageRenameService.GetPackageRenames(packageTo);
// 3. 'To' input that already has a 'From' entry in the PackageRenames table -- Transitive
existingRenames = _packageRenameService.GetPackageRenames(packageTo);

if (existingRenamesTo.Any())
if (existingRenames.Any())
{
var existingRenamesMessage = $"{packageTo.Id} already has entries in the PackageRenames table. This popularity transfer will result in a new transitive relationship. Please look at the PackageRenames table and verify your input before proceeding.";
result.ExistingPackageRenames.Insert(0, existingRenamesMessage);
result.ExistingPackageRenamesMessagesTransitive.Add(existingRenamesMessage);

foreach (var existingRename in existingRenames)
{
result.ExistingPackageRenamesTransitive.Add(new PopularityTransferItem(existingRename.FromPackageRegistration, existingRename.ToPackageRegistration));
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/NuGetGallery/Areas/Admin/Models/CorrectIsLatestPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace NuGetGallery.Areas.Admin.Models
{
public class CorrectIsLatestPackage
{
public string Id { get; set; }
public string Version { get; set; }
public int IsLatestCount { get; set; }
public int IsLatestStableCount { get; set; }
public int IsLatestSemVer2Count { get; set; }
public int IsLatestStableSemVer2Count { get; set; }
public bool HasIsLatestUnlisted { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.


using System.Collections.Generic;

namespace NuGetGallery.Areas.Admin.ViewModels
{
public class CorrectIsLatestRequest
{
public ICollection<CorrectIsLatestPackageRequest> Packages { get; set; }
}

public class CorrectIsLatestPackageRequest
{
public string Id { get; set; }
public string Version { get; set; }
}
}
Loading