debian-mirror-gitlab/app/graphql/resolvers/snippets/blobs_resolver.rb

40 lines
1.3 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
module Resolvers
module Snippets
class BlobsResolver < BaseResolver
include Gitlab::Graphql::Authorize::AuthorizeResource
2021-01-29 00:20:46 +05:30
type Types::Snippets::BlobType.connection_type, null: true
2021-02-22 17:27:13 +05:30
authorize :read_snippet
2021-04-17 20:07:23 +05:30
calls_gitaly!
2021-04-29 21:17:54 +05:30
authorizes_object!
2021-01-29 00:20:46 +05:30
2021-01-03 14:25:43 +05:30
alias_method :snippet, :object
2021-10-27 15:23:28 +05:30
argument :paths, [GraphQL::Types::String],
2021-01-03 14:25:43 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Paths of the blobs.'
2021-01-03 14:25:43 +05:30
2021-03-11 19:13:27 +05:30
def resolve(paths: [])
2021-01-03 14:25:43 +05:30
return [snippet.blob] if snippet.empty_repo?
2022-02-27 12:50:16 +05:30
paths = snippet.all_files if paths.empty?
blobs = snippet.blobs(paths)
# TODO: Some blobs, e.g. those with non-utf8 filenames, are returned as nil from the
# repository. We need to provide a flag to notify the user of this until we come up with a
# way to retrieve and display these blobs. We will be exploring a more holistic solution for
# this general problem of making all blobs retrievable as part
# of https://gitlab.com/gitlab-org/gitlab/-/issues/323082, at which point this attribute may
# be removed.
context[:unretrievable_blobs?] = blobs.size < paths.size
blobs
2021-01-03 14:25:43 +05:30
end
end
end
end
2022-01-26 12:08:38 +05:30
Resolvers::Snippets::BlobsResolver.prepend_mod