diff options
Diffstat (limited to 'app/graphql')
-rw-r--r-- | app/graphql/resolvers/package_details_resolver.rb | 10 | ||||
-rw-r--r-- | app/graphql/types/ci/stage_type.rb | 28 | ||||
-rw-r--r-- | app/graphql/types/packages/conan/file_metadatum_type.rb | 22 | ||||
-rw-r--r-- | app/graphql/types/packages/conan/metadatum_file_type_enum.rb | 16 | ||||
-rw-r--r-- | app/graphql/types/packages/conan/metadatum_type.rb | 22 | ||||
-rw-r--r-- | app/graphql/types/packages/file_metadata_type.rb | 27 | ||||
-rw-r--r-- | app/graphql/types/packages/metadata_type.rb | 4 | ||||
-rw-r--r-- | app/graphql/types/packages/package_details_type.rb | 20 | ||||
-rw-r--r-- | app/graphql/types/packages/package_file_type.rb | 36 | ||||
-rw-r--r-- | app/graphql/types/packages/package_type.rb | 47 | ||||
-rw-r--r-- | app/graphql/types/packages/package_without_versions_type.rb | 44 |
11 files changed, 226 insertions, 50 deletions
diff --git a/app/graphql/resolvers/package_details_resolver.rb b/app/graphql/resolvers/package_details_resolver.rb index e688e34599a..89d79747732 100644 --- a/app/graphql/resolvers/package_details_resolver.rb +++ b/app/graphql/resolvers/package_details_resolver.rb @@ -2,12 +2,20 @@ module Resolvers class PackageDetailsResolver < BaseResolver - type ::Types::Packages::PackageType, null: true + type ::Types::Packages::PackageDetailsType, null: true argument :id, ::Types::GlobalIDType[::Packages::Package], required: true, description: 'The global ID of the package.' + def ready?(**args) + context[self.class] ||= { executions: 0 } + context[self.class][:executions] += 1 + raise GraphQL::ExecutionError, "Package details can be requested only for one package at a time" if context[self.class][:executions] > 1 + + super + end + def resolve(id:) # TODO: remove this line when the compatibility layer is removed # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 diff --git a/app/graphql/types/ci/stage_type.rb b/app/graphql/types/ci/stage_type.rb index 04a7698e323..56b4f248697 100644 --- a/app/graphql/types/ci/stage_type.rb +++ b/app/graphql/types/ci/stage_type.rb @@ -36,6 +36,34 @@ module Types jobs_for_pipeline(pl, indexed.keys, include_needs).each do |stage_id, statuses| key = indexed[stage_id] groups = ::Ci::Group.fabricate(project, key.stage, statuses) + + if Feature.enabled?(:ci_no_empty_groups, project) + groups.each do |group| + rejected = group.jobs.reject { |job| Ability.allowed?(current_user, :read_commit_status, job) } + group.jobs.select! { |job| Ability.allowed?(current_user, :read_commit_status, job) } + next unless group.jobs.empty? + + exc = StandardError.new('Empty Ci::Group') + traces = rejected.map do |job| + trace = [] + policy = Ability.policy_for(current_user, job) + policy.debug(:read_commit_status, trace) + trace + end + extra = { + current_user_id: current_user&.id, + project_id: project.id, + pipeline_id: pl.id, + stage_id: stage_id, + group_name: group.name, + rejected_job_ids: rejected.map(&:id), + rejected_traces: traces + } + Gitlab::ErrorTracking.track_exception(exc, extra) + end + groups.reject! { |group| group.jobs.empty? } + end + loader.call(key, groups) end end diff --git a/app/graphql/types/packages/conan/file_metadatum_type.rb b/app/graphql/types/packages/conan/file_metadatum_type.rb new file mode 100644 index 00000000000..97d5abe6ba4 --- /dev/null +++ b/app/graphql/types/packages/conan/file_metadatum_type.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Types + module Packages + module Conan + class FileMetadatumType < BaseObject + graphql_name 'ConanFileMetadata' + description 'Conan file metadata' + + implements Types::Packages::FileMetadataType + + authorize :read_package + + field :id, ::Types::GlobalIDType[::Packages::Conan::FileMetadatum], null: false, description: 'ID of the metadatum.' + field :recipe_revision, GraphQL::STRING_TYPE, null: false, description: 'Revision of the Conan recipe.' + field :package_revision, GraphQL::STRING_TYPE, null: true, description: 'Revision of the package.' + field :conan_package_reference, GraphQL::STRING_TYPE, null: true, description: 'Reference of the Conan package.' + field :conan_file_type, ::Types::Packages::Conan::MetadatumFileTypeEnum, null: false, description: 'Type of the Conan file.' + end + end + end +end diff --git a/app/graphql/types/packages/conan/metadatum_file_type_enum.rb b/app/graphql/types/packages/conan/metadatum_file_type_enum.rb new file mode 100644 index 00000000000..d8ec3a44d4d --- /dev/null +++ b/app/graphql/types/packages/conan/metadatum_file_type_enum.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Types + module Packages + module Conan + class MetadatumFileTypeEnum < BaseEnum + graphql_name 'ConanMetadatumFileTypeEnum' + description 'Conan file types' + + ::Packages::Conan::FileMetadatum.conan_file_types.keys.each do |file| + value file.upcase, value: file, description: "A #{file.humanize(capitalize: false)} type." + end + end + end + end +end diff --git a/app/graphql/types/packages/conan/metadatum_type.rb b/app/graphql/types/packages/conan/metadatum_type.rb new file mode 100644 index 00000000000..00b84235d27 --- /dev/null +++ b/app/graphql/types/packages/conan/metadatum_type.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Types + module Packages + module Conan + class MetadatumType < BaseObject + graphql_name 'ConanMetadata' + description 'Conan metadata' + + authorize :read_package + + field :id, ::Types::GlobalIDType[::Packages::Conan::Metadatum], null: false, description: 'ID of the metadatum.' + field :created_at, Types::TimeType, null: false, description: 'Date of creation.' + field :updated_at, Types::TimeType, null: false, description: 'Date of most recent update.' + field :package_username, GraphQL::STRING_TYPE, null: false, description: 'Username of the Conan package.' + field :package_channel, GraphQL::STRING_TYPE, null: false, description: 'Channel of the Conan package.' + field :recipe, GraphQL::STRING_TYPE, null: false, description: 'Recipe of the Conan package.' + field :recipe_path, GraphQL::STRING_TYPE, null: false, description: 'Recipe path of the Conan package.' + end + end + end +end diff --git a/app/graphql/types/packages/file_metadata_type.rb b/app/graphql/types/packages/file_metadata_type.rb new file mode 100644 index 00000000000..46ccb424218 --- /dev/null +++ b/app/graphql/types/packages/file_metadata_type.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Types + module Packages + module FileMetadataType + include ::Types::BaseInterface + graphql_name 'PackageFileMetadata' + description 'Represents metadata associated with a Package file' + + field :created_at, ::Types::TimeType, null: false, description: 'Date of creation.' + field :updated_at, ::Types::TimeType, null: false, description: 'Date of most recent update.' + + def self.resolve_type(object, context) + case object + when ::Packages::Conan::FileMetadatum + ::Types::Packages::Conan::FileMetadatumType + else + # NOTE: This method must be kept in sync with `PackageFileType#file_metadata`, + # which must never produce data that this discriminator cannot handle. + raise 'Unsupported file metadata type' + end + end + + orphan_types Types::Packages::Conan::FileMetadatumType + end + end +end diff --git a/app/graphql/types/packages/metadata_type.rb b/app/graphql/types/packages/metadata_type.rb index 26c43b51a69..4ab6707df88 100644 --- a/app/graphql/types/packages/metadata_type.rb +++ b/app/graphql/types/packages/metadata_type.rb @@ -6,12 +6,14 @@ module Types graphql_name 'PackageMetadata' description 'Represents metadata associated with a Package' - possible_types ::Types::Packages::Composer::MetadatumType + possible_types ::Types::Packages::Composer::MetadatumType, ::Types::Packages::Conan::MetadatumType def self.resolve_type(object, context) case object when ::Packages::Composer::Metadatum ::Types::Packages::Composer::MetadatumType + when ::Packages::Conan::Metadatum + ::Types::Packages::Conan::MetadatumType else # NOTE: This method must be kept in sync with `PackageWithoutVersionsType#metadata`, # which must never produce data that this discriminator cannot handle. diff --git a/app/graphql/types/packages/package_details_type.rb b/app/graphql/types/packages/package_details_type.rb new file mode 100644 index 00000000000..510b7e2ba41 --- /dev/null +++ b/app/graphql/types/packages/package_details_type.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Types + module Packages + class PackageDetailsType < PackageType + graphql_name 'PackageDetailsType' + description 'Represents a package details in the Package Registry. Note that this type is in beta and susceptible to changes' + authorize :read_package + + field :versions, ::Types::Packages::PackageType.connection_type, null: true, + description: 'The other versions of the package.' + + field :package_files, Types::Packages::PackageFileType.connection_type, null: true, description: 'Package files.' + + def versions + object.versions + end + end + end +end diff --git a/app/graphql/types/packages/package_file_type.rb b/app/graphql/types/packages/package_file_type.rb new file mode 100644 index 00000000000..e9e38559626 --- /dev/null +++ b/app/graphql/types/packages/package_file_type.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Types + module Packages + class PackageFileType < BaseObject + graphql_name 'PackageFile' + description 'Represents a package file' + authorize :read_package + + field :id, ::Types::GlobalIDType[::Packages::PackageFile], null: false, description: 'ID of the file.' + field :created_at, Types::TimeType, null: false, description: 'The created date.' + field :updated_at, Types::TimeType, null: false, description: 'The updated date.' + field :size, GraphQL::STRING_TYPE, null: false, description: 'Size of the package file.' + field :file_name, GraphQL::STRING_TYPE, null: false, description: 'Name of the package file.' + field :download_path, GraphQL::STRING_TYPE, null: false, description: 'Download path of the package file.' + field :file_md5, GraphQL::STRING_TYPE, null: true, description: 'Md5 of the package file.' + field :file_sha1, GraphQL::STRING_TYPE, null: true, description: 'Sha1 of the package file.' + field :file_sha256, GraphQL::STRING_TYPE, null: true, description: 'Sha256 of the package file.' + field :file_metadata, Types::Packages::FileMetadataType, null: true, + description: 'File metadata.' + + # NOTE: This method must be kept in sync with the union + # type: `Types::Packages::FileMetadataType`. + # + # `Types::Packages::FileMetadataType.resolve_type(metadata, ctx)` must never raise. + def file_metadata + case object.package.package_type + when 'conan' + object.conan_file_metadatum + else + nil + end + end + end + end +end diff --git a/app/graphql/types/packages/package_type.rb b/app/graphql/types/packages/package_type.rb index 331898a1e84..a263ca1577a 100644 --- a/app/graphql/types/packages/package_type.rb +++ b/app/graphql/types/packages/package_type.rb @@ -2,13 +2,52 @@ module Types module Packages - class PackageType < PackageWithoutVersionsType + class PackageType < ::Types::BaseObject graphql_name 'Package' - description 'Represents a package in the Package Registry' + description 'Represents a package in the Package Registry. Note that this type is in beta and susceptible to changes' + authorize :read_package - field :versions, ::Types::Packages::PackageWithoutVersionsType.connection_type, null: true, - description: 'The other versions of the package.' + field :id, ::Types::GlobalIDType[::Packages::Package], null: false, + description: 'ID of the package.' + + field :name, GraphQL::STRING_TYPE, null: false, description: 'Name of the package.' + field :created_at, Types::TimeType, null: false, description: 'Date of creation.' + field :updated_at, Types::TimeType, null: false, description: 'Date of most recent update.' + field :version, GraphQL::STRING_TYPE, null: true, description: 'Version string.' + field :package_type, Types::Packages::PackageTypeEnum, null: false, description: 'Package type.' + field :tags, Types::Packages::PackageTagType.connection_type, null: true, description: 'Package tags.' + field :project, Types::ProjectType, null: false, description: 'Project where the package is stored.' + field :pipelines, Types::Ci::PipelineType.connection_type, null: true, + description: 'Pipelines that built the package.' + field :metadata, Types::Packages::MetadataType, null: true, + description: 'Package metadata.' + field :versions, ::Types::Packages::PackageType.connection_type, null: true, + description: 'The other versions of the package.', + deprecated: { reason: 'This field is now only returned in the PackageDetailsType', milestone: '13.11' } + + def project + Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, object.project_id).find + end + + def versions + [] + end + + # NOTE: This method must be kept in sync with the union + # type: `Types::Packages::MetadataType`. + # + # `Types::Packages::MetadataType.resolve_type(metadata, ctx)` must never raise. + def metadata + case object.package_type + when 'composer' + object.composer_metadatum + when 'conan' + object.conan_metadatum + else + nil + end + end end end end diff --git a/app/graphql/types/packages/package_without_versions_type.rb b/app/graphql/types/packages/package_without_versions_type.rb deleted file mode 100644 index 9c6bb37e6cc..00000000000 --- a/app/graphql/types/packages/package_without_versions_type.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -module Types - module Packages - class PackageWithoutVersionsType < ::Types::BaseObject - graphql_name 'PackageWithoutVersions' - description 'Represents a version of a package in the Package Registry' - - authorize :read_package - - field :id, ::Types::GlobalIDType[::Packages::Package], null: false, - description: 'ID of the package.' - - field :name, GraphQL::STRING_TYPE, null: false, description: 'Name of the package.' - field :created_at, Types::TimeType, null: false, description: 'Date of creation.' - field :updated_at, Types::TimeType, null: false, description: 'Date of most recent update.' - field :version, GraphQL::STRING_TYPE, null: true, description: 'Version string.' - field :package_type, Types::Packages::PackageTypeEnum, null: false, description: 'Package type.' - field :tags, Types::Packages::PackageTagType.connection_type, null: true, description: 'Package tags.' - field :project, Types::ProjectType, null: false, description: 'Project where the package is stored.' - field :pipelines, Types::Ci::PipelineType.connection_type, null: true, - description: 'Pipelines that built the package.' - field :metadata, Types::Packages::MetadataType, null: true, - description: 'Package metadata.' - - def project - Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, object.project_id).find - end - - # NOTE: This method must be kept in sync with the union - # type: `Types::Packages::MetadataType`. - # - # `Types::Packages::MetadataType.resolve_type(metadata, ctx)` must never raise. - def metadata - case object.package_type - when 'composer' - object.composer_metadatum - else - nil - end - end - end - end -end |