Class: Types::ProjectType

Inherits:
BaseObject
  • Object
show all
Defined in:
app/graphql/types/project_type.rb

Instance Method Summary collapse

Methods inherited from BaseObject

accepts, assignable?, authorization, authorize, authorized?, #current_user, #id

Methods included from Gitlab::Graphql::Present

#present, #unpresented

Instance Method Details

#avatar_urlObject



668
669
670
# File 'app/graphql/types/project_type.rb', line 668

def avatar_url
  object.avatar_url(only_path: false)
end

#ci_config_variables(ref:) ⇒ Object



702
703
704
705
706
707
708
709
710
# File 'app/graphql/types/project_type.rb', line 702

def ci_config_variables(ref:)
  result = ::Ci::ListConfigVariablesService.new(object, context[:current_user]).execute(ref)

  return if result.nil?

  result.map do |var_key, var_config|
    { key: var_key, **var_config }
  end
end

#container_repositories_countObject



698
699
700
# File 'app/graphql/types/project_type.rb', line 698

def container_repositories_count
  project.container_repositories.size
end

#forks_countObject



680
681
682
# File 'app/graphql/types/project_type.rb', line 680

def forks_count
  BatchLoader::GraphQL.wrap(object.forks_count)
end

#is_catalog_resourceObject

rubocop:disable Naming/PredicateName



684
685
686
687
688
689
690
691
692
# File 'app/graphql/types/project_type.rb', line 684

def is_catalog_resource # rubocop:disable Naming/PredicateName
  lazy_catalog_resource = BatchLoader::GraphQL.for(object.id).batch do |project_ids, loader|
    ::Ci::Catalog::Resource.for_projects(project_ids).each do |catalog_resource|
      loader.call(catalog_resource.project_id, catalog_resource)
    end
  end

  Gitlab::Graphql::Lazy.with_value(lazy_catalog_resource, &:present?)
end

#job(id:) ⇒ Object



712
713
714
715
# File 'app/graphql/types/project_type.rb', line 712

def job(id:)
  object.commit_statuses.find(id.model_id)
rescue ActiveRecord::RecordNotFound
end

#jobs_enabledObject



672
673
674
# File 'app/graphql/types/project_type.rb', line 672

def jobs_enabled
  object.feature_available?(:builds, context[:current_user])
end

#label(title:) ⇒ Object



642
643
644
645
646
647
648
649
# File 'app/graphql/types/project_type.rb', line 642

def label(title:)
  BatchLoader::GraphQL.for(title).batch(key: project) do |titles, loader, args|
    LabelsFinder
      .new(current_user, project: args[:key], title: titles)
      .execute
      .each { |label| loader.call(label.title, label) }
  end
end

#languagesObject



734
735
736
# File 'app/graphql/types/project_type.rb', line 734

def languages
  ::Projects::RepositoryLanguagesService.new(project, current_user).execute
end

#open_issues_countObject



676
677
678
# File 'app/graphql/types/project_type.rb', line 676

def open_issues_count
  BatchLoader::GraphQL.wrap(object.open_issues_count) if object.feature_available?(:issues, context[:current_user])
end

#sast_ci_configurationObject



717
718
719
720
721
722
723
724
725
726
# File 'app/graphql/types/project_type.rb', line 717

def sast_ci_configuration
  return unless Ability.allowed?(current_user, :read_code, object)

  if project.repository.empty?
    raise Gitlab::Graphql::Errors::MutationError,
      _(format('You must %s before using Security features.', add_file_docs_link.html_safe)).html_safe
  end

  ::Security::CiConfiguration::SastParserService.new(object).configuration
end

#service_desk_addressObject



728
729
730
731
732
# File 'app/graphql/types/project_type.rb', line 728

def service_desk_address
  return unless Ability.allowed?(current_user, :admin_issue, project)

  object.service_desk_address
end

#statisticsObject



694
695
696
# File 'app/graphql/types/project_type.rb', line 694

def statistics
  Gitlab::Graphql::Loaders::BatchProjectStatisticsLoader.new(object.id).find
end

#statistics_details_pathsObject



748
749
750
751
752
753
754
755
756
757
758
759
# File 'app/graphql/types/project_type.rb', line 748

def statistics_details_paths
  root_ref = project.repository.root_ref || project.default_branch_or_main

  {
    repository: Gitlab::Routing.url_helpers.project_tree_url(project, root_ref),
    wiki: Gitlab::Routing.url_helpers.project_wikis_pages_url(project),
    build_artifacts: Gitlab::Routing.url_helpers.project_artifacts_url(project),
    packages: Gitlab::Routing.url_helpers.project_packages_url(project),
    snippets: Gitlab::Routing.url_helpers.project_snippets_url(project),
    container_registry: Gitlab::Routing.url_helpers.project_container_registry_index_url(project)
  }
end

#timelog_categoriesObject



638
639
640
# File 'app/graphql/types/project_type.rb', line 638

def timelog_categories
  object.project_namespace.timelog_categories if Feature.enabled?(:timelog_categories)
end

#visible_forks(minimum_access_level: nil) ⇒ Object



738
739
740
741
742
743
744
745
746
# File 'app/graphql/types/project_type.rb', line 738

def visible_forks(minimum_access_level: nil)
  if minimum_access_level.nil?
    object.forks.public_or_visible_to_user(current_user)
  else
    return [] if current_user.nil?

    object.forks.visible_to_user_and_access_level(current_user, minimum_access_level)
  end
end