Welcome to mirror list, hosted at ThFree Co, Russian Federation.

blobs_resolver.rb « snippets « resolvers « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 569b82149d3d47e2200e36d92a4172da0d70f080 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

module Resolvers
  module Snippets
    class BlobsResolver < BaseResolver
      prepend ManualAuthorization
      include Gitlab::Graphql::Authorize::AuthorizeResource

      type Types::Snippets::BlobType.connection_type, null: true
      authorize :read_snippet
      calls_gitaly!

      alias_method :snippet, :object

      argument :paths, [GraphQL::STRING_TYPE],
               required: false,
               description: 'Paths of the blobs.'

      def resolve(paths: [])
        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