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

38 lines
889 B
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
module Resolvers
module Snippets
class BlobsResolver < BaseResolver
2021-02-22 17:27:13 +05:30
prepend ManualAuthorization
2021-01-03 14:25:43 +05:30
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-01-29 00:20:46 +05:30
2021-01-03 14:25:43 +05:30
alias_method :snippet, :object
argument :paths, [GraphQL::STRING_TYPE],
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
authorize!(snippet)
return [snippet.blob] if snippet.empty_repo?
if paths.empty?
snippet.blobs
else
snippet.repository.blobs_at(transformed_blob_paths(paths))
end
end
private
def transformed_blob_paths(paths)
ref = snippet.default_branch
paths.map { |path| [ref, path] }
end
end
end
end