Repository navigation
[Package Data Model] Adding package models and reusable capabilities - #6370
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new abstract package model along with several concrete package model types and reusable capabilities for handling package vulnerabilities and deprecation. Key changes include refactoring the PackageItemLoader to leverage a PackageModelFactory for creating package models, adding new package model classes (e.g., RemotePackageModel, TransitivelyReferencedPackageModel, RecommendedPackageModel), and implementing various capability classes for vulnerability and deprecation data retrieval.
Reviewed Changes
Copilot reviewed 49 out of 50 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| PackageItemLoader.cs | Refactored view model creation logic to use the new PackageModelFactory and updated transitive package handling. |
| VulnerablePackageMetadataCapability.cs | Introduced a capability to retrieve vulnerability data from package metadata. |
| VulnerableDatabaseCapability.cs | Added a capability to obtain vulnerability data via a package vulnerability service. |
| VulnerableCapabilityBase.cs | Created a base class for vulnerability capabilities with built-in sorting of vulnerability data. |
| TransitivelyReferencedPackageModel.cs, RemotePackageModel.cs, ReferencedPackageModel.cs, RecommededPackageModel.cs | New package model implementations encapsulating domain package information and capabilities. |
| PackageModelFactory.cs | Factory class to encapsulate the creation of various package model types based on metadata. |
| Other files (PackageModel.cs, PackageMetadataRetrievalAdapter.cs, LocalPackageModel.cs, etc.) | Support classes and interfaces for handling embedded resources and package metadata retrieval. |
Files not reviewed (1)
- src/NuGet.Clients/NuGet.PackageManagement.UI/Design/PackageItemListViewSampleData.xaml: Language not supported
Comments suppressed due to low confidence (1)
src/NuGet.Clients/NuGet.PackageManagement.UI/Models/Package/PackageModelFactory.cs:24
- The use of 'nameof(_searchService)' in the constructor argument null check should reference the parameter 'searchService' instead (e.g., nameof(searchService)).
_searchService = searchService ?? throw new ArgumentNullException(nameof(_searchService));
…ities for a package domain model (#6279)
* Add local embedded resouce * Added remote resource * Added tests * Pr comments * Switched to value task * remove local * Added ReadmeUri back as a property * typo * rename tests * Update test * combine test * rename tests
* Add new fields * added summary * only use ownerlist
* Add known owners capability * Add access modifier
…#6313) * Updated model * Updated to include readme * Add class modifiers * rename * remove newline
* Added known owners to RemotePackageModel * Update known owners capability to be private var
* Add self hydration to deprecation * update deprecation * add private * add mock to constructor
* Added some vulnerability capabilities * Update to have refresh action * Added tests and use interface * PR comments * Pr comments * Remove unused variable * Remove extra parameters * update tests * update words * combine throw * add readonly * simplify * fix words * update
* Added capabilities to different models * moved vulnerabiity off of base package * update access modifiers to internal * rename * Update test/NuGet.Clients.Tests/NuGet.PackageManagement.UI.Test/Models/Package/LocalPackageModelTests.cs
152d2dd to
0b41801
Compare
nkolev92
left a comment
There was a problem hiding this comment.
This is looking great!
Thanks for addressing all the feedback.
I have a few comments that can be resolved in this or a future PR.
During the walkthrough we discussed init properties for the models, was the decision in the end to not use them?

Bug
Fixes: https://github.com/NuGet/Client.Engineering/issues/3214
Description
Package Model:
Introduced a new abstract package model to serve as the domain model for packages and implementations for package types.
Capabilities and Implementations:
Introduced flexible, reusable, and testable capabilities for composing packages and their behaviors.
View Model and Control Changes:
The
PackageItemViewModelis now made to leverage the new package domain model, an improvement over having the ViewModel maintain properties to determine the package state.PackageItemLoaderto use the factory to build the appropriate package model type given aPackageSearchMetadataContextInfoand selected tab.PackageItemViewModelto use the new domain model as its backing model, reducing functionality within the view model itself.UpdateTransitivePackageStatusto avoid passing in the version, reducing potential errors.Package Metadata Retrieval Adapter:
Tests:
PackageMetadataRetrievalAdapter.PackageDeprecationReasonEnum
DetailControlModelrelated to deprecation reasons to this new class.Refactoring to reduce Code Duplication:
PackageItemViewModelcombinedReloadTopLevelPackageMetadataAsyncandReloadTransitivePackageMetadataAsyncinto a single methodReloadPackageMetadataAsyncto encapsulate the package type into the ViewModel and simplify the caller's responsibilities.RunOperationAsyncto reduce code duplication.PR Checklist
Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.It's worth mentioning that we had a manual test pass of the NuGet Package Manager from the source branch that helped us discovered one bug with the deprecation label in the package list. We fixed that already and the fix is included in this PR. All other tests from that validation passed!