-
Notifications
You must be signed in to change notification settings - Fork 641
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 #9483 from NuGet/dev
[ReleasePrep][2023.04.25]RI of dev into main
- Loading branch information
Showing
32 changed files
with
793 additions
and
104 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// 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.Collections.Generic; | ||
using System.Linq; | ||
using Newtonsoft.Json.Linq; | ||
using NuGet.Services.Entities; | ||
|
||
namespace NuGetGallery.Helpers | ||
{ | ||
public static class SearchResponseHelper | ||
{ | ||
public static ICollection<PackageDeprecation> GetDeprecationsOrNull(JToken docDeprecation) | ||
{ | ||
PackageDeprecation deprecation = null; | ||
if (docDeprecation != null) | ||
{ | ||
var docReasons = docDeprecation.Value<JArray>("Reasons"); | ||
if (docReasons != null && docReasons.HasValues) | ||
{ | ||
PackageDeprecationStatus status = PackageDeprecationStatus.NotDeprecated; | ||
foreach (var reason in docReasons) | ||
{ | ||
if (Enum.TryParse<PackageDeprecationStatus>(reason.Value<string>(), out var pdStatus)) | ||
{ | ||
status |= pdStatus; | ||
} | ||
} | ||
|
||
var docAlternatePackage = docDeprecation["AlternatePackage"]; | ||
Package alternatePackage = null; | ||
if (docAlternatePackage != null) | ||
{ | ||
var range = docAlternatePackage.Value<string>("Range"); | ||
var id = docAlternatePackage.Value<string>("Id"); | ||
if (!string.IsNullOrEmpty(range) && !string.IsNullOrEmpty(id)) | ||
{ | ||
var version = string.Empty; | ||
var commaIndex = range.IndexOf(","); | ||
if (range.StartsWith("[") && commaIndex > 0) | ||
{ | ||
var startIndex = 1; | ||
version = range.Substring(startIndex, commaIndex - startIndex); | ||
} | ||
|
||
alternatePackage = new Package() | ||
{ | ||
Id = id, | ||
Version = version | ||
}; | ||
} | ||
} | ||
|
||
deprecation = new PackageDeprecation() | ||
{ | ||
CustomMessage = docDeprecation.Value<string>("Message"), | ||
Status = status, | ||
AlternatePackage = alternatePackage | ||
}; | ||
} | ||
} | ||
|
||
return deprecation == null ? null : new List<PackageDeprecation>() { deprecation }; | ||
} | ||
|
||
public static ICollection<VulnerablePackageVersionRange> GetVulnerabilities(JArray docVulnerabilities) | ||
{ | ||
var vulnerabilities = new List<VulnerablePackageVersionRange>(); | ||
if (docVulnerabilities != null) | ||
{ | ||
vulnerabilities = docVulnerabilities.Select(v => new VulnerablePackageVersionRange() | ||
{ | ||
Vulnerability = new PackageVulnerability() | ||
{ | ||
AdvisoryUrl = v.Value<string>("AdvisoryUrl"), | ||
Severity = (PackageVulnerabilitySeverity)v.Value<int>("Severity") | ||
} | ||
}) | ||
.ToList(); | ||
} | ||
|
||
return vulnerabilities; | ||
} | ||
} | ||
} |
Oops, something went wrong.