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, authorization_scopes, authorize, authorized?, #current_user, #id

Methods included from Gitlab::Graphql::Present

#present, #unpresented

Instance Method Details

#avatar_urlObject



816
817
818
# File 'app/graphql/types/project_type.rb', line 816

def avatar_url
  object.avatar_url(only_path: false)
end

#ci_config_variables(ref:) ⇒ Object



862
863
864
865
866
867
868
869
870
# File 'app/graphql/types/project_type.rb', line 862

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



858
859
860
# File 'app/graphql/types/project_type.rb', line 858

def container_repositories_count
  project.container_repositories.size
end

#explore_catalog_pathObject



848
849
850
851
852
# File 'app/graphql/types/project_type.rb', line 848

def explore_catalog_path
  return unless project.catalog_resource

  Gitlab::Routing.url_helpers.explore_catalog_path(project.catalog_resource)
end

#forks_countObject



834
835
836
# File 'app/graphql/types/project_type.rb', line 834

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

#is_catalog_resourceObject

rubocop:disable Naming/PredicateName



838
839
840
841
842
843
844
845
846
# File 'app/graphql/types/project_type.rb', line 838

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



872
873
874
875
# File 'app/graphql/types/project_type.rb', line 872

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

#jobs_enabledObject



820
821
822
# File 'app/graphql/types/project_type.rb', line 820

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

#label(title:) ⇒ Object



777
778
779
780
781
782
783
784
# File 'app/graphql/types/project_type.rb', line 777

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



894
895
896
# File 'app/graphql/types/project_type.rb', line 894

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

#max_access_levelObject



921
922
923
924
925
926
927
928
929
# File 'app/graphql/types/project_type.rb', line 921

def max_access_level
  return Gitlab::Access::NO_ACCESS if current_user.nil?

  BatchLoader::GraphQL.for(object.id).batch do |project_ids, loader|
    current_user.max_member_access_for_project_ids(project_ids).each do |project_id, max_access_level|
      loader.call(project_id, max_access_level)
    end
  end
end

#open_issues_countObject



824
825
826
# File 'app/graphql/types/project_type.rb', line 824

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

#open_merge_requests_countObject



828
829
830
831
832
# File 'app/graphql/types/project_type.rb', line 828

def open_merge_requests_count
  return unless object.feature_available?(:merge_requests, context[:current_user])

  BatchLoader::GraphQL.wrap(object.open_merge_requests_count)
end

#organization_edit_pathObject



931
932
933
934
935
936
937
938
939
# File 'app/graphql/types/project_type.rb', line 931

def organization_edit_path
  return if project.organization.nil?

  ::Gitlab::Routing.url_helpers.edit_namespace_projects_organization_path(
    project.organization,
    id: project.to_param,
    namespace_id: project.namespace.to_param
  )
end

#protectable_branchesObject



769
770
771
# File 'app/graphql/types/project_type.rb', line 769

def protectable_branches
  ProtectableDropdown.new(project, :branches).protectable_ref_names
end

#sast_ci_configurationObject



877
878
879
880
881
882
883
884
885
886
# File 'app/graphql/types/project_type.rb', line 877

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



888
889
890
891
892
# File 'app/graphql/types/project_type.rb', line 888

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

  object.service_desk_address
end

#statisticsObject



854
855
856
# File 'app/graphql/types/project_type.rb', line 854

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

#statistics_details_pathsObject



908
909
910
911
912
913
914
915
916
917
918
919
# File 'app/graphql/types/project_type.rb', line 908

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



773
774
775
# File 'app/graphql/types/project_type.rb', line 773

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

#visible_forks(minimum_access_level: nil) ⇒ Object



898
899
900
901
902
903
904
905
906
# File 'app/graphql/types/project_type.rb', line 898

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