2018-09-11 19:08:34 +00:00
# frozen_string_literal: true
2018-05-23 07:55:14 +00:00
module Types
class ProjectType < BaseObject
graphql_name 'Project'
2017-08-16 13:04:41 +00:00
2019-03-04 02:30:32 +00:00
authorize :read_project
expose_permissions Types :: PermissionTypes :: Project
2019-10-31 12:06:26 +00:00
field :id , GraphQL :: ID_TYPE , null : false ,
description : 'ID of the project'
2017-08-16 13:04:41 +00:00
2019-10-31 12:06:26 +00:00
field :full_path , GraphQL :: ID_TYPE , null : false ,
description : 'Full path of the project'
field :path , GraphQL :: STRING_TYPE , null : false ,
description : 'Path of the project'
2017-08-16 13:04:41 +00:00
2019-10-31 12:06:26 +00:00
field :name_with_namespace , GraphQL :: STRING_TYPE , null : false ,
description : 'Full name of the project with its namespace'
field :name , GraphQL :: STRING_TYPE , null : false ,
description : 'Name of the project (without namespace)'
2017-08-16 13:04:41 +00:00
2019-10-31 12:06:26 +00:00
field :description , GraphQL :: STRING_TYPE , null : true ,
description : 'Short description of the project'
2019-06-20 08:02:33 +00:00
markdown_field :description_html , null : true
2017-08-16 13:04:41 +00:00
2019-10-31 12:06:26 +00:00
field :tag_list , GraphQL :: STRING_TYPE , null : true ,
2020-04-21 15:21:10 +00:00
description : 'List of project topics (not Git tags)'
2019-10-31 12:06:26 +00:00
field :ssh_url_to_repo , GraphQL :: STRING_TYPE , null : true ,
description : 'URL to connect to the project via SSH'
field :http_url_to_repo , GraphQL :: STRING_TYPE , null : true ,
description : 'URL to connect to the project via HTTPS'
field :web_url , GraphQL :: STRING_TYPE , null : true ,
description : 'Web URL of the project'
field :star_count , GraphQL :: INT_TYPE , null : false ,
description : 'Number of times the project has been starred'
field :forks_count , GraphQL :: INT_TYPE , null : false , calls_gitaly : true , # 4 times
description : 'Number of times the project has been forked'
field :created_at , Types :: TimeType , null : true ,
description : 'Timestamp of the project creation'
field :last_activity_at , Types :: TimeType , null : true ,
description : 'Timestamp of the project last activity'
field :archived , GraphQL :: BOOLEAN_TYPE , null : true ,
2020-01-08 00:07:43 +00:00
description : 'Indicates the archived status of the project'
2019-10-31 12:06:26 +00:00
field :visibility , GraphQL :: STRING_TYPE , null : true ,
description : 'Visibility of the project'
field :container_registry_enabled , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'Indicates if the project stores Docker container images in a container registry'
field :shared_runners_enabled , GraphQL :: BOOLEAN_TYPE , null : true ,
2020-04-06 03:09:23 +00:00
description : 'Indicates if Shared Runners are enabled for the project'
2019-10-31 12:06:26 +00:00
field :lfs_enabled , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'Indicates if the project has Large File Storage (LFS) enabled'
field :merge_requests_ff_only_enabled , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'Indicates if no merge commits should be created and all merges should instead be fast-forwarded, which means that merging is only allowed if the branch could be fast-forwarded.'
2020-07-09 09:09:27 +00:00
field :service_desk_enabled , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'Indicates if the project has service desk enabled.'
field :service_desk_address , GraphQL :: STRING_TYPE , null : true ,
description : 'E-mail address of the service desk.'
2019-10-31 12:06:26 +00:00
field :avatar_url , GraphQL :: STRING_TYPE , null : true , calls_gitaly : true ,
description : 'URL to avatar image file of the project' ,
resolve : - > ( project , args , ctx ) do
project . avatar_url ( only_path : false )
end
2017-08-16 13:04:41 +00:00
2018-05-23 07:55:14 +00:00
% i [ issues merge_requests wiki snippets ] . each do | feature |
2019-10-31 12:06:26 +00:00
field " #{ feature } _enabled " , GraphQL :: BOOLEAN_TYPE , null : true ,
2020-04-06 03:09:23 +00:00
description : " Indicates if #{ feature . to_s . titleize . pluralize } are enabled for the current user " ,
2019-10-31 12:06:26 +00:00
resolve : - > ( project , args , ctx ) do
project . feature_available? ( feature , ctx [ :current_user ] )
end
2017-08-16 13:04:41 +00:00
end
2019-10-31 12:06:26 +00:00
field :jobs_enabled , GraphQL :: BOOLEAN_TYPE , null : true ,
2020-04-06 03:09:23 +00:00
description : 'Indicates if CI/CD pipeline jobs are enabled for the current user' ,
2019-10-31 12:06:26 +00:00
resolve : - > ( project , args , ctx ) do
project . feature_available? ( :builds , ctx [ :current_user ] )
end
field :public_jobs , GraphQL :: BOOLEAN_TYPE , method : :public_builds , null : true ,
description : 'Indicates if there is public access to pipelines and job details of the project, including output logs and artifacts'
field :open_issues_count , GraphQL :: INT_TYPE , null : true ,
description : 'Number of open issues for the project' ,
resolve : - > ( project , args , ctx ) do
project . open_issues_count if project . feature_available? ( :issues , ctx [ :current_user ] )
end
field :import_status , GraphQL :: STRING_TYPE , null : true ,
2020-03-26 12:07:48 +00:00
description : 'Status of import background job of the project'
field :jira_import_status , GraphQL :: STRING_TYPE , null : true ,
description : 'Status of Jira import background job of the project'
2019-10-31 12:06:26 +00:00
field :only_allow_merge_if_pipeline_succeeds , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'Indicates if merge requests of the project can only be merged with successful jobs'
2020-06-10 21:09:29 +00:00
field :allow_merge_on_skipped_pipeline , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'If `only_allow_merge_if_pipeline_succeeds` is true, indicates if merge requests of the project can also be merged with skipped jobs'
2019-10-31 12:06:26 +00:00
field :request_access_enabled , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'Indicates if users can request member access to the project'
field :only_allow_merge_if_all_discussions_are_resolved , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'Indicates if merge requests of the project can only be merged when all the discussions are resolved'
field :printing_merge_request_link_enabled , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'Indicates if a link to create or view a merge request should display after a push to Git repositories of the project from the command line'
field :remove_source_branch_after_merge , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'Indicates if `Delete source branch` option should be enabled by default for all new merge requests of the project'
2020-01-08 00:07:43 +00:00
field :autoclose_referenced_issues , GraphQL :: BOOLEAN_TYPE , null : true ,
description : 'Indicates if issues referenced by merge requests and commits within the default branch are closed automatically'
2020-01-13 12:08:04 +00:00
field :suggestion_commit_message , GraphQL :: STRING_TYPE , null : true ,
description : 'The commit message used to apply merge request suggestions'
2019-10-31 12:06:26 +00:00
field :namespace , Types :: NamespaceType , null : true ,
description : 'Namespace of the project'
field :group , Types :: GroupType , null : true ,
description : 'Group of the project'
field :statistics , Types :: ProjectStatisticsType ,
2019-06-14 20:40:21 +00:00
null : true ,
2019-10-31 12:06:26 +00:00
description : 'Statistics of the project' ,
2019-05-12 21:10:46 +00:00
resolve : - > ( obj , _args , _ctx ) { Gitlab :: Graphql :: Loaders :: BatchProjectStatisticsLoader . new ( obj . id ) . find }
2019-10-31 12:06:26 +00:00
field :repository , Types :: RepositoryType , null : true ,
description : 'Git repository of the project'
2019-05-22 11:43:35 +00:00
2019-10-31 12:06:26 +00:00
field :merge_requests ,
2019-01-30 19:00:30 +00:00
Types :: MergeRequestType . connection_type ,
null : true ,
2019-10-31 12:06:26 +00:00
description : 'Merge requests of the project' ,
2020-06-05 21:08:27 +00:00
extras : [ :lookahead ] ,
2019-03-04 02:30:32 +00:00
resolver : Resolvers :: MergeRequestsResolver
2019-01-30 19:00:30 +00:00
2019-10-31 12:06:26 +00:00
field :merge_request ,
2018-06-14 13:06:53 +00:00
Types :: MergeRequestType ,
null : true ,
2019-10-31 12:06:26 +00:00
description : 'A single merge request of the project' ,
2019-03-04 02:30:32 +00:00
resolver : Resolvers :: MergeRequestsResolver . single
2018-06-26 16:31:05 +00:00
2019-10-31 12:06:26 +00:00
field :issues ,
2018-11-27 15:10:40 +00:00
Types :: IssueType . connection_type ,
null : true ,
2019-10-31 12:06:26 +00:00
description : 'Issues of the project' ,
2018-11-27 15:10:40 +00:00
resolver : Resolvers :: IssuesResolver
2020-07-30 18:09:39 +00:00
field :milestones , Types :: MilestoneType . connection_type , null : true ,
description : 'Milestones of the project' ,
resolver : Resolvers :: ProjectMilestoneResolver
2020-06-04 15:08:21 +00:00
field :project_members ,
Types :: ProjectMemberType . connection_type ,
description : 'Members of the project' ,
resolver : Resolvers :: ProjectMembersResolver
2020-01-16 18:08:46 +00:00
field :environments ,
Types :: EnvironmentType . connection_type ,
null : true ,
description : 'Environments of the project' ,
resolver : Resolvers :: EnvironmentsResolver
2020-07-06 03:09:07 +00:00
field :sast_ci_configuration , :: Types :: CiConfiguration :: Sast :: Type , null : true ,
description : 'SAST CI configuration for the project' ,
resolver : :: Resolvers :: CiConfiguration :: SastResolver
2019-10-31 12:06:26 +00:00
field :issue ,
2019-11-18 15:06:27 +00:00
Types :: IssueType ,
2019-02-12 16:31:18 +00:00
null : true ,
2019-10-31 12:06:26 +00:00
description : 'A single issue of the project' ,
2019-02-12 16:31:18 +00:00
resolver : Resolvers :: IssuesResolver . single
2020-07-17 06:09:11 +00:00
field :packages , Types :: PackageType . connection_type , null : true ,
description : 'Packages of the project' ,
resolver : Resolvers :: PackagesResolver
2019-10-31 12:06:26 +00:00
field :pipelines ,
2018-06-26 16:31:05 +00:00
Types :: Ci :: PipelineType . connection_type ,
2019-03-04 02:30:32 +00:00
null : true ,
2019-10-31 12:06:26 +00:00
description : 'Build pipelines of the project' ,
2018-06-26 16:31:05 +00:00
resolver : Resolvers :: ProjectPipelinesResolver
2019-12-06 09:06:39 +00:00
2020-06-15 18:08:43 +00:00
field :pipeline ,
Types :: Ci :: PipelineType ,
null : true ,
description : 'Build pipeline of the project' ,
resolver : Resolvers :: ProjectPipelineResolver
2019-12-06 09:06:39 +00:00
field :sentry_detailed_error ,
Types :: ErrorTracking :: SentryDetailedErrorType ,
null : true ,
description : 'Detailed version of a Sentry error on the project' ,
resolver : Resolvers :: ErrorTracking :: SentryDetailedErrorResolver
2019-12-10 07:53:40 +00:00
2020-01-07 21:07:50 +00:00
field :grafana_integration ,
Types :: GrafanaIntegrationType ,
null : true ,
description : 'Grafana integration details for the project' ,
resolver : Resolvers :: Projects :: GrafanaIntegrationResolver
2019-12-10 07:53:40 +00:00
field :snippets ,
Types :: SnippetType . connection_type ,
null : true ,
description : 'Snippets of the project' ,
resolver : Resolvers :: Projects :: SnippetsResolver
2020-01-29 12:09:08 +00:00
field :sentry_errors ,
Types :: ErrorTracking :: SentryErrorCollectionType ,
null : true ,
description : 'Paginated collection of Sentry errors on the project' ,
resolver : Resolvers :: ErrorTracking :: SentryErrorCollectionResolver
2020-02-19 00:09:15 +00:00
field :boards ,
Types :: BoardType . connection_type ,
null : true ,
description : 'Boards of the project' ,
2020-03-18 15:09:45 +00:00
max_page_size : 2000 ,
2020-02-19 00:09:15 +00:00
resolver : Resolvers :: BoardsResolver
2020-02-24 18:09:05 +00:00
field :board ,
Types :: BoardType ,
null : true ,
description : 'A single board of the project' ,
resolver : Resolvers :: BoardsResolver . single
2020-03-26 12:07:48 +00:00
field :jira_imports ,
Types :: JiraImportType . connection_type ,
null : true ,
description : 'Jira imports into the project' ,
resolver : Resolvers :: Projects :: JiraImportsResolver
2020-04-08 06:09:54 +00:00
field :services ,
Types :: Projects :: ServiceType . connection_type ,
null : true ,
description : 'Project services' ,
resolver : Resolvers :: Projects :: ServicesResolver
2020-04-28 15:09:29 +00:00
field :alert_management_alerts ,
Types :: AlertManagement :: AlertType . connection_type ,
null : true ,
description : 'Alert Management alerts of the project' ,
2020-06-11 00:08:35 +00:00
extras : [ :lookahead ] ,
2020-06-09 00:08:47 +00:00
resolver : Resolvers :: AlertManagement :: AlertResolver
2020-04-28 15:09:29 +00:00
field :alert_management_alert ,
Types :: AlertManagement :: AlertType ,
null : true ,
description : 'A single Alert Management alert of the project' ,
2020-06-09 00:08:47 +00:00
resolver : Resolvers :: AlertManagement :: AlertResolver . single
2020-05-07 00:11:11 +00:00
2020-05-20 00:08:20 +00:00
field :alert_management_alert_status_counts ,
Types :: AlertManagement :: AlertStatusCountsType ,
null : true ,
description : 'Counts of alerts by status for the project' ,
resolver : Resolvers :: AlertManagement :: AlertStatusCountsResolver
2020-05-07 00:11:11 +00:00
field :releases ,
Types :: ReleaseType . connection_type ,
null : true ,
description : 'Releases of the project' ,
2020-06-25 03:08:52 +00:00
resolver : Resolvers :: ReleasesResolver
2020-05-07 00:11:11 +00:00
field :release ,
Types :: ReleaseType ,
null : true ,
description : 'A single release of the project' ,
resolver : Resolvers :: ReleasesResolver . single ,
2020-06-18 06:08:33 +00:00
authorize : :download_code
2020-05-28 00:08:37 +00:00
field :container_expiration_policy ,
Types :: ContainerExpirationPolicyType ,
null : true ,
description : 'The container expiration policy of the project'
2020-06-03 00:08:38 +00:00
field :label ,
Types :: LabelType ,
null : true ,
description : 'A label available on this project' do
argument :title , GraphQL :: STRING_TYPE ,
required : true ,
description : 'Title of the label'
end
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
field :labels ,
Types :: LabelType . connection_type ,
null : true ,
description : 'Labels available on this project' do
argument :search_term , GraphQL :: STRING_TYPE ,
required : false ,
description : 'A search term to find labels with'
end
def labels ( search_term : nil )
LabelsFinder
. new ( current_user , project : project , search : search_term )
. execute
end
private
def project
@project || = object . respond_to? ( :sync ) ? object . sync : object
end
2018-05-23 07:55:14 +00:00
end
2017-08-16 13:04:41 +00:00
end
2019-12-11 12:08:10 +00:00
Types :: ProjectType . prepend_if_ee ( '::EE::Types::ProjectType' )