Skip to content

Commit

Permalink
(NuGet#9) Provide server related information
Browse files Browse the repository at this point in the history
Along with moderation related information, provide other data that is
provided by the server metadata.

- PackageHash
- PackageHashAlgorithm
- PackageSize
- VersionDownloadCount
- IsApproved
- PackageStatus
- PackageSubmittedStatus
- PackageTestResultStatus
- PackageTestResultStatusDate
- PackageValidationResultStatus
- PackageValidationResultDate
- PackageCleanupResultDate
- PackageReviewedDate
- PackageApprovedDate
- PackageReviewer
- IsDownloadCacheAvailable
- DownloadCacheDate
- DownloadCache

Based on these commits:
chocolatey/nuget-chocolatey@3866411
chocolatey/nuget-chocolatey@133552a

Co-Authored-By: Rob Reynolds <[email protected]>
  • Loading branch information
2 people authored and gep13 committed Nov 21, 2022
1 parent 895238f commit 3c891b1
Show file tree
Hide file tree
Showing 27 changed files with 1,358 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.

//////////////////////////////////////////////////////////
// Chocolatey Specific Modification
//////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using NuGet.Protocol.Core.Types;

namespace NuGet.VisualStudio.Internal.Contracts
{
public partial class TransitivePackageSearchMetadata : IPackageSearchMetadata
{
public string PackageHash => _packageSearchMetadata.PackageHash;
public string PackageHashAlgorithm => _packageSearchMetadata.PackageHashAlgorithm;
public long? PackageSize => _packageSearchMetadata.PackageSize;
public int? VersionDownloadCount => _packageSearchMetadata.VersionDownloadCount;
public bool IsApproved => _packageSearchMetadata.IsApproved;
public string PackageStatus => _packageSearchMetadata.PackageStatus;
public string PackageSubmittedStatus => _packageSearchMetadata.PackageSubmittedStatus;
public string PackageTestResultStatus => _packageSearchMetadata.PackageTestResultStatus;
public DateTime? PackageTestResultStatusDate => _packageSearchMetadata.PackageTestResultStatusDate;
public string PackageValidationResultStatus => _packageSearchMetadata.PackageValidationResultStatus;
public DateTime? PackageValidationResultDate => _packageSearchMetadata.PackageValidationResultDate;
public DateTime? PackageCleanupResultDate => _packageSearchMetadata.PackageCleanupResultDate;
public DateTime? PackageReviewedDate => _packageSearchMetadata.PackageReviewedDate;
public DateTime? PackageApprovedDate => _packageSearchMetadata.PackageApprovedDate;
public string PackageReviewer => _packageSearchMetadata.PackageReviewer;

public bool IsDownloadCacheAvailable => _packageSearchMetadata.IsDownloadCacheAvailable;
public DateTime? DownloadCacheDate => _packageSearchMetadata.DownloadCacheDate;
public IEnumerable<DownloadCache> DownloadCache => _packageSearchMetadata.DownloadCache;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@
NuGet.VisualStudio.Internal.Contracts.INuGetProjectManagerService.GetInstallActionsAsync(System.Collections.Generic.IReadOnlyCollection<string!>! projectIds, NuGet.Packaging.Core.PackageIdentity! packageIdentity, NuGet.PackageManagement.VersionConstraints versionConstraints, bool includePrelease, NuGet.Resolver.DependencyBehavior dependencyBehavior, System.Collections.Generic.IReadOnlyList<string!>! packageSourceNames, NuGet.Versioning.VersionRange! versionRange, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<System.Collections.Generic.IReadOnlyList<NuGet.VisualStudio.Internal.Contracts.ProjectAction!>!>
NuGet.VisualStudio.Internal.Contracts.INuGetSearchService.GetPackageVersionsAsync(NuGet.Packaging.Core.PackageIdentity! identity, System.Collections.Generic.IReadOnlyCollection<NuGet.VisualStudio.Internal.Contracts.PackageSourceContextInfo!>! packageSources, bool includePrerelease, bool isTransitive, System.Collections.Generic.IEnumerable<NuGet.VisualStudio.Internal.Contracts.IProjectContextInfo!>! projects, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<System.Collections.Generic.IReadOnlyCollection<NuGet.VisualStudio.Internal.Contracts.VersionInfoContextInfo!>!>
NuGet.VisualStudio.Internal.Contracts.INuGetSearchService.GetPackageVersionsAsync(NuGet.Packaging.Core.PackageIdentity! identity, System.Collections.Generic.IReadOnlyCollection<NuGet.VisualStudio.Internal.Contracts.PackageSourceContextInfo!>! packageSources, bool includePrerelease, bool isTransitive, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<System.Collections.Generic.IReadOnlyCollection<NuGet.VisualStudio.Internal.Contracts.VersionInfoContextInfo!>!>
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.DownloadCache.get -> System.Collections.Generic.IEnumerable<NuGet.Protocol.Core.Types.DownloadCache!>!
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.DownloadCacheDate.get -> System.DateTime?
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.IsApproved.get -> bool
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.IsDownloadCacheAvailable.get -> bool
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageApprovedDate.get -> System.DateTime?
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageCleanupResultDate.get -> System.DateTime?
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageHash.get -> string!
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageHashAlgorithm.get -> string!
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageReviewedDate.get -> System.DateTime?
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageReviewer.get -> string!
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageSize.get -> long?
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageStatus.get -> string!
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageSubmittedStatus.get -> string!
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageTestResultStatus.get -> string!
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageTestResultStatusDate.get -> System.DateTime?
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageValidationResultDate.get -> System.DateTime?
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.PackageValidationResultStatus.get -> string!
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.VersionDownloadCount.get -> int?
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@

namespace NuGet.VisualStudio.Internal.Contracts
{
public class TransitivePackageSearchMetadata : IPackageSearchMetadata
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

public partial class TransitivePackageSearchMetadata : IPackageSearchMetadata

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

{
public IReadOnlyCollection<PackageIdentity> TransitiveOrigins { get; private set; }

Expand Down
11 changes: 11 additions & 0 deletions src/NuGet.Core/NuGet.Protocol/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,14 @@
[assembly: SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "We convert packageId to lower case for api call.", Scope = "member", Target = "~M:NuGet.Protocol.PackageMetadataResourceV3.GetRegistratioIndexPageAsync(NuGet.Protocol.HttpSource,System.String,System.String,NuGet.Versioning.NuGetVersion,NuGet.Versioning.NuGetVersion,NuGet.Protocol.Core.Types.HttpSourceCacheContext,NuGet.Common.ILogger,System.Threading.CancellationToken)~System.Threading.Tasks.Task{NuGet.Protocol.Model.RegistrationPage}")]
[assembly: SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "We convert packageId to lower case for api call.", Scope = "member", Target = "~M:NuGet.Protocol.PackageMetadataResourceV3.LoadRegistrationIndexAsync(NuGet.Protocol.HttpSource,System.Uri,System.String,NuGet.Protocol.Core.Types.SourceCacheContext,System.Func{NuGet.Protocol.HttpSourceResult,System.Threading.Tasks.Task{NuGet.Protocol.Model.RegistrationIndex}},NuGet.Common.ILogger,System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.ValueTuple{NuGet.Protocol.Model.RegistrationIndex,NuGet.Protocol.Core.Types.HttpSourceCacheContext}}")]
[assembly: SuppressMessage("Usage", "CA2237:Mark ISerializable types with serializable", Justification = "<Pending>", Scope = "type", Target = "~T:NuGet.Protocol.PackageNotFoundProtocolException")]

//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

[assembly: SuppressMessage("Design", "CA1054:Uri parameters should not be strings", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Protocol.V2FeedPackageInfo.#ctor(NuGet.Packaging.Core.PackageIdentity,System.String,System.String,System.String,System.Collections.Generic.IEnumerable{System.String},System.Collections.Generic.IEnumerable{System.String},System.String,System.String,System.String,System.String,System.String,System.String,System.Nullable{System.DateTimeOffset},System.Nullable{System.DateTimeOffset},System.Nullable{System.DateTimeOffset},System.String,System.Boolean,System.String,System.String,System.String,System.String,NuGet.Versioning.NuGetVersion,System.Nullable{System.Int64},System.Nullable{System.Int32},System.Boolean,System.String,System.String,System.String,System.Nullable{System.DateTime},System.String,System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.String,System.Boolean,System.Nullable{System.DateTime},System.String)")]
[assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "<Pending>", Scope = "member", Target = "~P:NuGet.Protocol.PackageSearchMetadataV2Feed.DownloadCache")]

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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.

//////////////////////////////////////////////////////////
// Chocolatey Specific Modification
//////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using NuGet.Packaging.Core;
using NuGet.Versioning;

namespace NuGet.Protocol
{
public partial class V2FeedPackageInfo : PackageIdentity
{
private readonly long? _packageSize;
private readonly int? _versionDownloadCount;
private readonly bool _isApproved;
private readonly string _packageStatus;
private readonly string _packageSubmittedStatus;
private readonly string _packageTestResultStatus;
private readonly DateTime? _packageTestResultStatusDate;
private readonly string _packageValidationResultStatus;
private readonly DateTime? _packageValidationResultDate;
private readonly DateTime? _packageCleanupResultDate;
private readonly DateTime? _packageReviewedDate;
private readonly DateTime? _packageApprovedDate;
private readonly string _packageReviewer;
private readonly bool _isDownloadCacheAvailable;
private readonly DateTime? _downloadCacheDate;
private readonly string _downloadCacheString;

public V2FeedPackageInfo(PackageIdentity identity, string title, string summary, string description, IEnumerable<string> authors, IEnumerable<string> owners,
string iconUrl, string licenseUrl, string projectUrl, string reportAbuseUrl, string galleryDetailsUrl,
string tags, DateTimeOffset? created, DateTimeOffset? lastEdited, DateTimeOffset? published, string dependencies, bool requireLicenseAccept, string downloadUrl,
string downloadCount, string packageHash, string packageHashAlgorithm, NuGetVersion minClientVersion, long? packageSize, int? versionDownloadCount, bool isApproved,
string packageStatus, string packageSubmittedStatus, string packageTestResultStatus, DateTime? packageTestResultStatusDate, string packageValidationResultStatus,
DateTime? packageValidationResultDate, DateTime? packageCleanupResultDate, DateTime? packageReviewedDate, DateTime? packageApprovedDate,
string packageReviewer, bool isDownloadCacheAvailable, DateTime? downloadCacheDate, string downloadCacheString)
: base(identity.Id, identity.Version)
{
_summary = summary;
_description = description;
_authors = authors == null ? Array.Empty<string>() : authors.ToArray();
_owners = owners == null ? Array.Empty<string>() : owners.ToArray();
_iconUrl = iconUrl;
_licenseUrl = licenseUrl;
_projectUrl = projectUrl;
_reportAbuseUrl = reportAbuseUrl;
_galleryDetailsUrl = galleryDetailsUrl;
_description = description;
_summary = summary;
_tags = tags;
_dependencies = dependencies;
_requireLicenseAcceptance = requireLicenseAccept;
_title = title;
_downloadUrl = downloadUrl;
_downloadCount = downloadCount;
_created = created;
_lastEdited = lastEdited;
_published = published;
_packageHash = packageHash;
_packageHashAlgorithm = packageHashAlgorithm;
_minClientVersion = minClientVersion;
_packageSize = packageSize;
_versionDownloadCount = versionDownloadCount;
_isApproved = isApproved;
_packageStatus = packageStatus;
_packageSubmittedStatus = packageSubmittedStatus;
_packageTestResultStatus = packageTestResultStatus;
_packageTestResultStatusDate = packageTestResultStatusDate;
_packageValidationResultStatus = packageValidationResultStatus;
_packageValidationResultDate = packageValidationResultDate;
_packageCleanupResultDate = packageCleanupResultDate;
_packageReviewedDate = packageReviewedDate;
_packageApprovedDate = packageApprovedDate;
_packageReviewer = packageReviewer;
_isDownloadCacheAvailable = isDownloadCacheAvailable;
_downloadCacheDate = downloadCacheDate;
_downloadCacheString = downloadCacheString;
}

public long? PackageSize => _packageSize;
public int? VersionDownloadCount => _versionDownloadCount;
public bool IsApproved => _isApproved;
public string PackageStatus => _packageStatus;
public string PackageSubmittedStatus => _packageSubmittedStatus;
public string PackageTestResultStatus => _packageTestResultStatus;
public DateTime? PackageTestResultStatusDate => _packageTestResultStatusDate;
public string PackageValidationResultStatus => _packageValidationResultStatus;
public DateTime? PackageValidationResultDate => _packageValidationResultDate;
public DateTime? PackageCleanupResultDate => _packageCleanupResultDate;
public DateTime? PackageReviewedDate => _packageReviewedDate;
public DateTime? PackageApprovedDate => _packageApprovedDate;
public string PackageReviewer => _packageReviewer;

public bool IsDownloadCacheAvailable => _isDownloadCacheAvailable;
public DateTime? DownloadCacheDate => _downloadCacheDate;
public string DownloadCacheString => _downloadCacheString;
}
}
83 changes: 83 additions & 0 deletions src/NuGet.Core/NuGet.Protocol/LegacyFeed/ChocolateyV2FeedParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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.

//////////////////////////////////////////////////////////
// Chocolatey Specific Modification
//////////////////////////////////////////////////////////

using System;
using System.Xml.Linq;

namespace NuGet.Protocol
{
public sealed partial class V2FeedParser : IV2FeedParser
{
#pragma warning disable IDE1006 // Naming Styles
private static readonly XName _xnamePackageSize = XName.Get("PackageSize", DataServicesNS);
private static readonly XName _xnameVersionDownloadCount = XName.Get("VersionDownloadCount", DataServicesNS);
private static readonly XName _xnameIsApproved = XName.Get("IsApproved", DataServicesNS);
private static readonly XName _xnamePackageStatus = XName.Get("PackageStatus", DataServicesNS);
private static readonly XName _xnamePackageSubmittedStatus = XName.Get("PackageSubmittedStatus", DataServicesNS);
private static readonly XName _xnamePackageTestResultStatus = XName.Get("PackageTestResultStatus", DataServicesNS);
private static readonly XName _xnamePackageTestResultStatusDate = XName.Get("PackageTestResultStatusDate", DataServicesNS);
private static readonly XName _xnamePackageValidationResultStatus = XName.Get("PackageValidationResultStatus", DataServicesNS);
private static readonly XName _xnamePackageValidationResultDate = XName.Get("PackageValidationResultDate", DataServicesNS);
private static readonly XName _xnamePackageCleanupResultDate = XName.Get("PackageCleanupResultDate", DataServicesNS);
private static readonly XName _xnamePackageReviewedDate = XName.Get("PackageReviewedDate", DataServicesNS);
private static readonly XName _xnamePackageApprovedDate = XName.Get("PackageApprovedDate", DataServicesNS);
private static readonly XName _xnamePackageReviewer = XName.Get("PackageReviewer", DataServicesNS);
private static readonly XName _xnameIsDownloadCacheAvailable = XName.Get("IsDownloadCacheAvailable", DataServicesNS);
private static readonly XName _xnameDownloadCacheDate = XName.Get("DownloadCacheDate", DataServicesNS);
private static readonly XName _xnameDownloadCache = XName.Get("DownloadCache", DataServicesNS);
#pragma warning restore IDE1006 // Naming Styles


/// <summary>
/// Retrieve an XML <see cref="DateTime"/> value safely
/// </summary>
private static DateTime? GetNoOffsetDate(XElement parent, XName childName)
{
var dateString = GetString(parent, childName);

DateTime date;
if (DateTime.TryParse(dateString, out date))
{
return date;
}

return null;
}

/// <summary>
/// Retrieve an XML <see cref="long"/> value safely
/// </summary>
private static long? GetLong(XElement parent, XName childName)
{
var numberString = GetString(parent, childName);

long number;
if (long.TryParse(numberString, out number))
{
return number;
}

return null;
}

/// <summary>
/// Retrieve an XML <see cref="int"/> value safely
/// </summary>
private static int? GetInt(XElement parent, XName childName)
{
var numberString = GetString(parent, childName);

int number;
if (int.TryParse(numberString, out number))
{
return number;
}

return null;
}
}
}
13 changes: 11 additions & 2 deletions src/NuGet.Core/NuGet.Protocol/LegacyFeed/V2FeedPackageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@

namespace NuGet.Protocol
{
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

/// <summary>
/// Represents a V2 package entry from the OData feed. This object primarily just holds the strings parsed from XML, all parsing
/// Represents a V2 package entry from the OData feed. This object primarily just holds the strings parsed from XML, all parsing
/// and converting should be done after based on the scenario.
/// </summary>
public class V2FeedPackageInfo : PackageIdentity
public partial class V2FeedPackageInfo : PackageIdentity

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

{
private readonly string _title;
private readonly string _summary;
Expand Down
Loading

0 comments on commit 3c891b1

Please sign in to comment.