-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9755 from NuGet/dev
[ReleasePrep][2023.12.13]RI of dev into main for NuGetGallery
- Loading branch information
Showing
24 changed files
with
1,143 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
src/NuGetGallery.Core/Frameworks/IFrameworkCompatibilityService.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/NuGetGallery/Areas/Admin/Controllers/CorrectIsLatestController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/NuGetGallery/Areas/Admin/Models/CorrectIsLatestPackage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/NuGetGallery/Areas/Admin/ViewModels/CorrectIsLatestRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
Oops, something went wrong.