Class: Resolvers::LastCommitResolver

Inherits:
BaseResolver
  • Object
show all
Defined in:
app/graphql/resolvers/last_commit_resolver.rb

Instance Method Summary collapse

Methods inherited from BaseResolver

as_single, authorization, authorized?, before_connection_authorization, before_connection_authorization_block, calculate_ext_conn_complexity, calls_gitaly!, calls_gitaly?, complexity, complexity_multiplier, #current_user, last, #object, #offset_pagination, requires_argument!, requires_argument?, resolver_complexity, #select_result, single, #single?, single_definition_blocks, singular_type, when_single

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Instance Method Details

#resolve(**args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/graphql/resolvers/last_commit_resolver.rb', line 25

def resolve(**args)
  repo = container.is_a?(Tree) ? container.repository : container

  ref = args[:ref]
  ref = container.sha if container.respond_to?(:sha)

  path = args[:path]
  path = container.path if container.respond_to?(:path)

  ref_type = args[:ref_type]
  ref_type = container.ref_type if container.respond_to?(:ref_type)

  # Set the default here instead of in the argument definition. This allows us
  # to extract the path correctly from "args" or "container".
  path = '' if path.nil?

  # Ensure merge commits can be returned by sending nil to Gitaly instead of '/'
  path = path == '/' ? nil : path
  commit = Gitlab::Git::Commit.last_for_path(repo,
    ExtractsRef::RefExtractor.qualify_ref(ref, ref_type), path, literal_pathspec: true)

  ::Commit.new(commit, repo.project) if commit
end