Skip to content

Add NuGet package tags support

David Fernandez requested to merge 42680-10io-nuget-add-tags-support into master

What does this MR do?

This MR add package tags support in the GitLab nuget repository (https://docs.gitlab.com/ee/user/packages/nuget_repository/index.html).

There are two sides:

  1. Extract the package tags from the .nuspec file and save them
  2. Expose them in the nuget API metadata endpoints and search endpoint.

Here is the definition of the package tags in the .nuspec file:

A space-delimited list of tags and keywords that describe the package and aid discoverability of packages through search and filtering.

source: https://docs.microsoft.com/en-us/nuget/reference/nuspec#tags

For (1.), we will update the Packages::Nuget::MetadataExtractionService which is responsible of reading the .nuspec file and extract data from it. The service will do so for package tags and transform them into an array of Strings.

For the persistence part, we will re-use the Packages::Tag model. Currently, this model is only created with the Packages::Npm::CreateTagService. We can't use this service. First, it's one dedicated for NPM and not nuget. Second, it has a custom behavior where a tags are unique and thus adding an existing tag to a package version should delete the existing from the previous version. This is not what we want here for nuget. To solve this situation, we introduce a pretty generic Packages::CreateTagsService. It will insert tags at once using a bulk insert.

Special note on persistence, users can upload multiple times a different archive for the same package name and version. The backend will simply append the files to the Packages::Package and when a request asks for a file, the newest one is returned. For tags, we need to take care of them on each upload. This means that on each upload we have to sync the tags list. By sync, we mean adding tags that are missing in the database and remove those that are not in the .nuspec file.

For (2.), it's just a matter of updating the presenters to handle the tags and recreate a A space-delimited list of tags.

See #42680 (closed)

Screenshots

Given the following .nuspec file:

Screenshot_2020-04-30_at_13.56.46

Tags are extracted and the package details page will look like this:

Screenshot_2020-04-30_at_13.56.07

Here is one of the metadata API responding with tags:

Screenshot_2020-04-30_at_14.01.54

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Mayra Cabrera

Merge request reports