Commit 82a4400a authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by Kerri Miller

Add nuget metadata type to Package GraphQl type

parent ea2d8f74
...@@ -6,7 +6,7 @@ module Types ...@@ -6,7 +6,7 @@ module Types
graphql_name 'PackageMetadata' graphql_name 'PackageMetadata'
description 'Represents metadata associated with a Package' description 'Represents metadata associated with a Package'
possible_types ::Types::Packages::Composer::MetadatumType, ::Types::Packages::Conan::MetadatumType, ::Types::Packages::Maven::MetadatumType possible_types ::Types::Packages::Composer::MetadatumType, ::Types::Packages::Conan::MetadatumType, ::Types::Packages::Maven::MetadatumType, ::Types::Packages::Nuget::MetadatumType
def self.resolve_type(object, context) def self.resolve_type(object, context)
case object case object
...@@ -16,6 +16,8 @@ module Types ...@@ -16,6 +16,8 @@ module Types
::Types::Packages::Conan::MetadatumType ::Types::Packages::Conan::MetadatumType
when ::Packages::Maven::Metadatum when ::Packages::Maven::Metadatum
::Types::Packages::Maven::MetadatumType ::Types::Packages::Maven::MetadatumType
when ::Packages::Nuget::Metadatum
::Types::Packages::Nuget::MetadatumType
else else
# NOTE: This method must be kept in sync with `PackageWithoutVersionsType#metadata`, # NOTE: This method must be kept in sync with `PackageWithoutVersionsType#metadata`,
# which must never produce data that this discriminator cannot handle. # which must never produce data that this discriminator cannot handle.
......
# frozen_string_literal: true
module Types
module Packages
module Nuget
class MetadatumType < BaseObject
graphql_name 'NugetMetadata'
description 'Nuget metadata'
authorize :read_package
field :id, ::Types::GlobalIDType[::Packages::Nuget::Metadatum], null: false, description: 'ID of the metadatum.'
field :license_url, GraphQL::STRING_TYPE, null: false, description: 'License URL of the Nuget package.'
field :project_url, GraphQL::STRING_TYPE, null: false, description: 'Project URL of the Nuget package.'
field :icon_url, GraphQL::STRING_TYPE, null: false, description: 'Icon URL of the Nuget package.'
end
end
end
end
...@@ -47,6 +47,8 @@ module Types ...@@ -47,6 +47,8 @@ module Types
object.conan_metadatum object.conan_metadatum
when 'maven' when 'maven'
object.maven_metadatum object.maven_metadatum
when 'nuget'
object.nuget_metadatum
else else
nil nil
end end
......
# frozen_string_literal: true
module Packages
module Nuget
class MetadatumPolicy < BasePolicy
delegate { @subject.package }
end
end
end
---
title: Add nuget metadata type to Package GraphQl type
merge_request: 61695
author:
type: added
...@@ -10452,6 +10452,19 @@ four standard [pagination arguments](#connection-pagination-arguments): ...@@ -10452,6 +10452,19 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="notepermissionsrepositionnote"></a>`repositionNote` | [`Boolean!`](#boolean) | Indicates the user can perform `reposition_note` on this resource. | | <a id="notepermissionsrepositionnote"></a>`repositionNote` | [`Boolean!`](#boolean) | Indicates the user can perform `reposition_note` on this resource. |
| <a id="notepermissionsresolvenote"></a>`resolveNote` | [`Boolean!`](#boolean) | Indicates the user can perform `resolve_note` on this resource. | | <a id="notepermissionsresolvenote"></a>`resolveNote` | [`Boolean!`](#boolean) | Indicates the user can perform `resolve_note` on this resource. |
### `NugetMetadata`
Nuget metadata.
#### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="nugetmetadataiconurl"></a>`iconUrl` | [`String!`](#string) | Icon URL of the Nuget package. |
| <a id="nugetmetadataid"></a>`id` | [`PackagesNugetMetadatumID!`](#packagesnugetmetadatumid) | ID of the metadatum. |
| <a id="nugetmetadatalicenseurl"></a>`licenseUrl` | [`String!`](#string) | License URL of the Nuget package. |
| <a id="nugetmetadataprojecturl"></a>`projectUrl` | [`String!`](#string) | Project URL of the Nuget package. |
### `OncallParticipantType` ### `OncallParticipantType`
The rotation participant and color palette. The rotation participant and color palette.
...@@ -15013,6 +15026,12 @@ A `PackagesMavenMetadatumID` is a global ID. It is encoded as a string. ...@@ -15013,6 +15026,12 @@ A `PackagesMavenMetadatumID` is a global ID. It is encoded as a string.
An example `PackagesMavenMetadatumID` is: `"gid://gitlab/Packages::Maven::Metadatum/1"`. An example `PackagesMavenMetadatumID` is: `"gid://gitlab/Packages::Maven::Metadatum/1"`.
### `PackagesNugetMetadatumID`
A `PackagesNugetMetadatumID` is a global ID. It is encoded as a string.
An example `PackagesNugetMetadatumID` is: `"gid://gitlab/Packages::Nuget::Metadatum/1"`.
### `PackagesPackageFileID` ### `PackagesPackageFileID`
A `PackagesPackageFileID` is a global ID. It is encoded as a string. A `PackagesPackageFileID` is a global ID. It is encoded as a string.
...@@ -15149,6 +15168,7 @@ One of: ...@@ -15149,6 +15168,7 @@ One of:
- [`ComposerMetadata`](#composermetadata) - [`ComposerMetadata`](#composermetadata)
- [`ConanMetadata`](#conanmetadata) - [`ConanMetadata`](#conanmetadata)
- [`MavenMetadata`](#mavenmetadata) - [`MavenMetadata`](#mavenmetadata)
- [`NugetMetadata`](#nugetmetadata)
#### `VulnerabilityDetail` #### `VulnerabilityDetail`
......
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
{ "$ref": "./package_composer_metadata.json" }, { "$ref": "./package_composer_metadata.json" },
{ "$ref": "./package_conan_metadata.json" }, { "$ref": "./package_conan_metadata.json" },
{ "$ref": "./package_maven_metadata.json" }, { "$ref": "./package_maven_metadata.json" },
{ "$ref": "./package_nuget_metadata.json" },
{ "type": "null" } { "type": "null" }
] ]
}, },
......
{
"type": "object",
"additionalProperties": false,
"required": ["id", "licenseUrl", "projectUrl", "iconUrl"],
"properties": {
"id": {
"type": "string"
},
"licenseUrl": {
"type": "string"
},
"projectUrl": {
"type": "string"
},
"iconUrl": {
"type": "string"
}
}
}
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['MavenMetadata'] do
it 'includes maven metadatum fields' do
expected_fields = %w[
id created_at updated_at path app_group app_version app_name
]
expect(described_class).to include_graphql_fields(*expected_fields)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['NugetMetadata'] do
it 'includes nuget metadatum fields' do
expected_fields = %w[
id license_url project_url icon_url
]
expect(described_class).to include_graphql_fields(*expected_fields)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'nuget package details' do
include GraphqlHelpers
let_it_be(:project) { create(:project) }
let_it_be(:nuget_package) { create(:nuget_package, :with_metadatum, project: project) }
let(:package_global_id) { global_id_of(nuget_package) }
let(:metadata) { query_graphql_fragment('NugetMetadata') }
let(:first_file) { nuget_package.package_files.find { |f| global_id_of(f) == first_file_response['id'] } }
let(:depth) { 3 }
let(:excluded) { %w[metadata apiFuzzingCiConfiguration pipeline packageFiles] }
let(:package_files) { all_graphql_fields_for('PackageFile') }
let(:user) { project.owner }
let(:package_details) { graphql_data_at(:package) }
let(:metadata_response) { graphql_data_at(:package, :metadata) }
let(:package_files_response) { graphql_data_at(:package, :package_files, :nodes) }
let(:first_file_response) { graphql_data_at(:package, :package_files, :nodes, 0)}
let(:query) do
graphql_query_for(:package, { id: package_global_id }, <<~FIELDS)
#{all_graphql_fields_for('PackageDetailsType', max_depth: depth, excluded: excluded)}
metadata {
#{metadata}
}
packageFiles {
nodes {
#{package_files}
}
}
FIELDS
end
subject { post_graphql(query, current_user: user) }
before do
subject
end
it_behaves_like 'a working graphql query' do
it 'matches the JSON schema' do
expect(package_details).to match_schema('graphql/packages/package_details')
end
end
it 'has the correct metadata' do
expect(metadata_response).to include(
'id' => global_id_of(nuget_package.nuget_metadatum),
'licenseUrl' => nuget_package.nuget_metadatum.license_url,
'projectUrl' => nuget_package.nuget_metadatum.project_url,
'iconUrl' => nuget_package.nuget_metadatum.icon_url
)
end
it 'has the right amount of files' do
expect(package_files_response.length).to be(nuget_package.package_files.length)
end
it 'has the basic package files data' do
expect(first_file_response).to include(
'id' => global_id_of(first_file),
'fileName' => first_file.file_name,
'size' => first_file.size.to_s,
'downloadPath' => first_file.download_path,
'fileSha1' => first_file.file_sha1,
'fileMd5' => first_file.file_md5,
'fileSha256' => first_file.file_sha256
)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment