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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
|
# frozen_string_literal: true
module Types
class ProjectType < BaseObject
graphql_name 'Project'
connection_type_class(Types::CountableConnectionType)
authorize :read_project
expose_permissions Types::PermissionTypes::Project
field :id, GraphQL::Types::ID,
null: false,
description: 'ID of the project.'
field :ci_config_path_or_default, GraphQL::Types::String,
null: false,
description: 'Path of the CI configuration file.'
field :ci_config_variables, [Types::Ci::ConfigVariableType],
null: true,
calls_gitaly: true,
authorize: :create_pipeline,
alpha: { milestone: '15.3' },
description: 'CI/CD config variable.' do
argument :sha, GraphQL::Types::String,
required: true,
description: 'Sha.'
end
field :full_path, GraphQL::Types::ID,
null: false,
description: 'Full path of the project.'
field :path, GraphQL::Types::String,
null: false,
description: 'Path of the project.'
field :incident_management_timeline_event_tags, [Types::IncidentManagement::TimelineEventTagType],
null: true,
description: 'Timeline event tags for the project.'
field :sast_ci_configuration, Types::CiConfiguration::Sast::Type,
null: true,
calls_gitaly: true,
description: 'SAST CI configuration for the project.'
field :name, GraphQL::Types::String,
null: false,
description: 'Name of the project (without namespace).'
field :name_with_namespace, GraphQL::Types::String,
null: false,
description: 'Full name of the project with its namespace.'
field :description, GraphQL::Types::String,
null: true,
description: 'Short description of the project.'
field :tag_list, GraphQL::Types::String,
null: true,
deprecated: { reason: 'Use `topics`', milestone: '13.12' },
description: 'List of project topics (not Git tags).',
method: :topic_list
field :topics, [GraphQL::Types::String],
null: true,
description: 'List of project topics.',
method: :topic_list
field :http_url_to_repo, GraphQL::Types::String,
null: true,
description: 'URL to connect to the project via HTTPS.'
field :ssh_url_to_repo, GraphQL::Types::String,
null: true,
description: 'URL to connect to the project via SSH.'
field :web_url, GraphQL::Types::String,
null: true,
description: 'Web URL of the project.'
field :forks_count, GraphQL::Types::Int,
null: false,
calls_gitaly: true, # 4 times
description: 'Number of times the project has been forked.'
field :star_count, GraphQL::Types::Int,
null: false,
description: 'Number of times the project has been starred.'
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::Types::Boolean,
null: true,
description: 'Indicates the archived status of the project.'
field :visibility, GraphQL::Types::String,
null: true,
description: 'Visibility of the project.'
field :lfs_enabled, GraphQL::Types::Boolean,
null: true,
description: 'Indicates if the project has Large File Storage (LFS) enabled.'
field :merge_requests_ff_only_enabled, GraphQL::Types::Boolean,
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.'
field :shared_runners_enabled, GraphQL::Types::Boolean,
null: true,
description: 'Indicates if shared runners are enabled for the project.'
field :service_desk_enabled, GraphQL::Types::Boolean,
null: true,
description: 'Indicates if the project has Service Desk enabled.'
field :service_desk_address, GraphQL::Types::String,
null: true,
description: 'E-mail address of the Service Desk.'
field :avatar_url, GraphQL::Types::String,
null: true,
calls_gitaly: true,
description: 'URL to avatar image file of the project.'
field :jobs_enabled, GraphQL::Types::Boolean,
null: true,
description: 'Indicates if CI/CD pipeline jobs are enabled for the current user.'
field :public_jobs, GraphQL::Types::Boolean,
null: true,
description: 'Indicates if there is public access to pipelines and job details of the project, ' \
'including output logs and artifacts.',
method: :public_builds
field :open_issues_count, GraphQL::Types::Int,
null: true,
description: 'Number of open issues for the project.'
field :allow_merge_on_skipped_pipeline, GraphQL::Types::Boolean,
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.'
field :autoclose_referenced_issues, GraphQL::Types::Boolean,
null: true,
description: 'Indicates if issues referenced by merge requests and commits within the default branch ' \
'are closed automatically.'
field :import_status, GraphQL::Types::String,
null: true,
description: 'Status of import background job of the project.'
field :jira_import_status, GraphQL::Types::String,
null: true,
description: 'Status of Jira import background job of the project.'
field :only_allow_merge_if_all_discussions_are_resolved, GraphQL::Types::Boolean,
null: true,
description: 'Indicates if merge requests of the project can only be merged when all the discussions are resolved.'
field :only_allow_merge_if_pipeline_succeeds, GraphQL::Types::Boolean,
null: true,
description: 'Indicates if merge requests of the project can only be merged with successful jobs.'
field :printing_merge_request_link_enabled, GraphQL::Types::Boolean,
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::Types::Boolean,
null: true,
description: 'Indicates if `Delete source branch` option should be enabled by default for all ' \
'new merge requests of the project.'
field :request_access_enabled, GraphQL::Types::Boolean,
null: true,
description: 'Indicates if users can request member access to the project.'
field :squash_read_only, GraphQL::Types::Boolean,
null: false,
description: 'Indicates if `squashReadOnly` is enabled.',
method: :squash_readonly?
field :suggestion_commit_message, GraphQL::Types::String,
null: true,
description: 'Commit message used to apply merge request suggestions.'
# No, the quotes are not a typo. Used to get around circular dependencies.
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27536#note_871009675
field :group, 'Types::GroupType',
null: true,
description: 'Group of the project.'
field :namespace, Types::NamespaceType,
null: true,
description: 'Namespace of the project.'
field :statistics, Types::ProjectStatisticsType,
null: true,
description: 'Statistics of the project.'
field :repository, Types::RepositoryType,
null: true,
description: 'Git repository of the project.'
field :merge_requests,
Types::MergeRequestType.connection_type,
null: true,
description: 'Merge requests of the project.',
extras: [:lookahead],
resolver: Resolvers::ProjectMergeRequestsResolver
field :merge_request,
Types::MergeRequestType,
null: true,
description: 'A single merge request of the project.',
resolver: Resolvers::MergeRequestsResolver.single
field :issues,
Types::IssueType.connection_type,
null: true,
description: 'Issues of the project.',
resolver: Resolvers::ProjectIssuesResolver
field :work_items,
Types::WorkItemType.connection_type,
null: true,
alpha: { milestone: '15.1' },
description: 'Work items of the project.',
extras: [:lookahead],
resolver: Resolvers::WorkItemsResolver
field :issue_status_counts,
Types::IssueStatusCountsType,
null: true,
description: 'Counts of issues by status for the project.',
resolver: Resolvers::IssueStatusCountsResolver
field :milestones, Types::MilestoneType.connection_type,
null: true,
description: 'Milestones of the project.',
resolver: Resolvers::ProjectMilestonesResolver
field :project_members,
description: 'Members of the project.',
resolver: Resolvers::ProjectMembersResolver
field :environments,
Types::EnvironmentType.connection_type,
null: true,
description: 'Environments of the project. ' \
'This field can only be resolved for one project in any single request.',
resolver: Resolvers::EnvironmentsResolver do
extension ::Gitlab::Graphql::Limit::FieldCallCount, limit: 1
end
field :environment,
Types::EnvironmentType,
null: true,
description: 'A single environment of the project.',
resolver: Resolvers::EnvironmentsResolver.single
field :nested_environments,
Types::NestedEnvironmentType.connection_type,
null: true,
calls_gitaly: true,
description: 'Environments for this project with nested folders, ' \
'can only be resolved for one project in any single request',
resolver: Resolvers::Environments::NestedEnvironmentsResolver do
extension ::Gitlab::Graphql::Limit::FieldCallCount, limit: 1
end
field :deployment,
Types::DeploymentType,
null: true,
description: 'Details of the deployment of the project.',
resolver: Resolvers::DeploymentResolver.single
field :issue,
Types::IssueType,
null: true,
description: 'A single issue of the project.',
resolver: Resolvers::ProjectIssuesResolver.single
field :packages,
description: 'Packages of the project.',
resolver: Resolvers::ProjectPackagesResolver
field :packages_cleanup_policy,
Types::Packages::Cleanup::PolicyType,
null: true,
description: 'Packages cleanup policy for the project.'
field :jobs,
type: Types::Ci::JobType.connection_type,
null: true,
authorize: :read_build,
description: 'Jobs of a project. This field can only be resolved for one project in any single request.',
resolver: Resolvers::ProjectJobsResolver
field :job,
type: Types::Ci::JobType,
null: true,
authorize: :read_build,
description: 'One job belonging to the project, selected by ID.' do
argument :id, Types::GlobalIDType[::CommitStatus],
required: true,
description: 'ID of the job.'
end
field :pipelines,
null: true,
description: 'Build pipelines of the project.',
extras: [:lookahead],
resolver: Resolvers::ProjectPipelinesResolver
field :pipeline_schedules,
type: Types::Ci::PipelineScheduleType.connection_type,
null: true,
description: 'Pipeline schedules of the project. This field can only be resolved for one project per request.',
resolver: Resolvers::ProjectPipelineSchedulesResolver
field :pipeline, Types::Ci::PipelineType,
null: true,
description: 'Build pipeline of the project.',
extras: [:lookahead],
resolver: Resolvers::ProjectPipelineResolver
field :pipeline_counts, Types::Ci::PipelineCountsType,
null: true,
description: 'Build pipeline counts of the project.',
resolver: Resolvers::Ci::ProjectPipelineCountsResolver
field :ci_variables, Types::Ci::ProjectVariableType.connection_type,
null: true,
description: "List of the project's CI/CD variables.",
authorize: :admin_build,
resolver: Resolvers::Ci::VariablesResolver
field :ci_cd_settings, Types::Ci::CiCdSettingType,
null: true,
description: 'CI/CD settings for the project.'
field :sentry_detailed_error, Types::ErrorTracking::SentryDetailedErrorType,
null: true,
description: 'Detailed version of a Sentry error on the project.',
resolver: Resolvers::ErrorTracking::SentryDetailedErrorResolver
field :grafana_integration, Types::GrafanaIntegrationType,
null: true,
description: 'Grafana integration details for the project.',
resolver: Resolvers::Projects::GrafanaIntegrationResolver
field :snippets, Types::SnippetType.connection_type,
null: true,
description: 'Snippets of the project.',
resolver: Resolvers::Projects::SnippetsResolver
field :sentry_errors, Types::ErrorTracking::SentryErrorCollectionType,
null: true,
description: 'Paginated collection of Sentry errors on the project.',
resolver: Resolvers::ErrorTracking::SentryErrorCollectionResolver
field :boards, Types::BoardType.connection_type,
null: true,
description: 'Boards of the project.',
max_page_size: 2000,
resolver: Resolvers::BoardsResolver
field :recent_issue_boards, Types::BoardType.connection_type,
null: true,
description: 'List of recently visited boards of the project. Maximum size is 4.',
resolver: Resolvers::RecentBoardsResolver
field :board, Types::BoardType,
null: true,
description: 'A single board of the project.',
resolver: Resolvers::BoardResolver
field :jira_imports, Types::JiraImportType.connection_type,
null: true,
description: 'Jira imports into the project.'
field :services, Types::Projects::ServiceType.connection_type,
null: true,
deprecated: {
reason: 'This will be renamed to `Project.integrations`',
milestone: '15.9'
},
description: 'Project services.',
resolver: Resolvers::Projects::ServicesResolver
field :alert_management_alerts, Types::AlertManagement::AlertType.connection_type,
null: true,
description: 'Alert Management alerts of the project.',
extras: [:lookahead],
resolver: Resolvers::AlertManagement::AlertResolver
field :alert_management_alert, Types::AlertManagement::AlertType,
null: true,
description: 'A single Alert Management alert of the project.',
resolver: Resolvers::AlertManagement::AlertResolver.single
field :alert_management_alert_status_counts, Types::AlertManagement::AlertStatusCountsType,
null: true,
description: 'Counts of alerts by status for the project.',
resolver: Resolvers::AlertManagement::AlertStatusCountsResolver
field :alert_management_integrations, Types::AlertManagement::IntegrationType.connection_type,
null: true,
description: 'Integrations which can receive alerts for the project.',
resolver: Resolvers::AlertManagement::IntegrationsResolver
field :alert_management_http_integrations, Types::AlertManagement::HttpIntegrationType.connection_type,
null: true,
description: 'HTTP Integrations which can receive alerts for the project.',
resolver: Resolvers::AlertManagement::HttpIntegrationsResolver
field :incident_management_timeline_events, Types::IncidentManagement::TimelineEventType.connection_type,
null: true,
description: 'Incident Management Timeline events associated with the incident.',
extras: [:lookahead],
resolver: Resolvers::IncidentManagement::TimelineEventsResolver
field :incident_management_timeline_event, Types::IncidentManagement::TimelineEventType,
null: true,
description: 'Incident Management Timeline event associated with the incident.',
resolver: Resolvers::IncidentManagement::TimelineEventsResolver.single
field :releases, Types::ReleaseType.connection_type,
null: true,
description: 'Releases of the project.',
resolver: Resolvers::ReleasesResolver
field :release, Types::ReleaseType,
null: true,
description: 'A single release of the project.',
resolver: Resolvers::ReleasesResolver.single,
authorize: :read_release
field :container_expiration_policy, Types::ContainerExpirationPolicyType,
null: true,
description: 'Container expiration policy of the project.'
field :container_repositories, Types::ContainerRepositoryType.connection_type,
null: true,
description: 'Container repositories of the project.',
resolver: Resolvers::ContainerRepositoriesResolver
field :container_repositories_count, GraphQL::Types::Int,
null: false,
description: 'Number of container repositories in the project.'
field :label, Types::LabelType,
null: true,
description: 'Label available on this project.' do
argument :title, GraphQL::Types::String,
required: true,
description: 'Title of the label.'
end
field :terraform_state, Types::Terraform::StateType,
null: true,
description: 'Find a single Terraform state by name.',
resolver: Resolvers::Terraform::StatesResolver.single
field :terraform_states, Types::Terraform::StateType.connection_type,
null: true,
description: 'Terraform states associated with the project.',
resolver: Resolvers::Terraform::StatesResolver
field :pipeline_analytics, Types::Ci::AnalyticsType,
null: true,
description: 'Pipeline analytics.',
resolver: Resolvers::ProjectPipelineStatisticsResolver
field :ci_template, Types::Ci::TemplateType,
null: true,
description: 'Find a single CI/CD template by name.',
resolver: Resolvers::Ci::TemplateResolver
field :ci_job_token_scope, Types::Ci::JobTokenScopeType,
null: true,
description: 'The CI Job Tokens scope of access.',
resolver: Resolvers::Ci::JobTokenScopeResolver
field :timelogs, Types::TimelogType.connection_type,
null: true,
description: 'Time logged on issues and merge requests in the project.',
extras: [:lookahead],
complexity: 5,
resolver: ::Resolvers::TimelogResolver
field :agent_configurations, ::Types::Kas::AgentConfigurationType.connection_type,
null: true,
description: 'Agent configurations defined by the project',
resolver: ::Resolvers::Kas::AgentConfigurationsResolver
field :cluster_agent, ::Types::Clusters::AgentType,
null: true,
description: 'Find a single cluster agent by name.',
resolver: ::Resolvers::Clusters::AgentsResolver.single
field :cluster_agents, ::Types::Clusters::AgentType.connection_type,
extras: [:lookahead],
null: true,
description: 'Cluster agents associated with the project.',
resolver: ::Resolvers::Clusters::AgentsResolver
field :merge_commit_template, GraphQL::Types::String,
null: true,
description: 'Template used to create merge commit message in merge requests.'
field :squash_commit_template, GraphQL::Types::String,
null: true,
description: 'Template used to create squash commit message in merge requests.'
field :labels, Types::LabelType.connection_type,
null: true,
description: 'Labels available on this project.',
resolver: Resolvers::LabelsResolver
field :work_item_types, Types::WorkItems::TypeType.connection_type,
resolver: Resolvers::WorkItems::TypesResolver,
description: 'Work item types available to the project.'
field :timelog_categories, Types::TimeTracking::TimelogCategoryType.connection_type,
null: true,
description: "Timelog categories for the project.",
alpha: { milestone: '15.3' }
field :fork_targets, Types::NamespaceType.connection_type,
resolver: Resolvers::Projects::ForkTargetsResolver,
description: 'Namespaces in which the current user can fork the project into.'
field :fork_details, Types::Projects::ForkDetailsType,
calls_gitaly: true,
alpha: { milestone: '15.7' },
authorize: :read_code,
resolver: Resolvers::Projects::ForkDetailsResolver,
description: 'Details of the fork project compared to its upstream project.'
field :branch_rules,
Types::Projects::BranchRuleType.connection_type,
null: true,
description: "Branch rules configured for the project.",
resolver: Resolvers::Projects::BranchRulesResolver
field :languages, [Types::Projects::RepositoryLanguageType],
null: true,
description: "Programming languages used in the project.",
calls_gitaly: true
field :runners, Types::Ci::RunnerType.connection_type,
null: true,
resolver: ::Resolvers::Ci::ProjectRunnersResolver,
description: "Find runners visible to the current user."
field :data_transfer, Types::DataTransfer::ProjectDataTransferType,
null: true, # disallow null once data_transfer_monitoring feature flag is rolled-out!
resolver: Resolvers::DataTransferResolver.project,
description: 'Data transfer data point for a specific period. This is mocked data under a development feature flag.'
field :visible_forks, Types::ProjectType.connection_type,
null: true,
alpha: { milestone: '15.10' },
description: "Visible forks of the project." do
argument :minimum_access_level,
type: ::Types::AccessLevelEnum,
required: false,
description: 'Minimum access level.'
end
def timelog_categories
object.project_namespace.timelog_categories if Feature.enabled?(:timelog_categories)
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
{
issues: "Issues are",
merge_requests: "Merge Requests are",
wiki: 'Wikis are',
snippets: 'Snippets are',
container_registry: 'Container Registry is'
}.each do |feature, name_string|
field "#{feature}_enabled", GraphQL::Types::Boolean, null: true,
description: "Indicates if #{name_string} enabled for the current user"
define_method "#{feature}_enabled" do
object.feature_available?(feature, context[:current_user])
end
end
markdown_field :description_html, null: true
def avatar_url
object.avatar_url(only_path: false)
end
def jobs_enabled
object.feature_available?(:builds, context[:current_user])
end
def open_issues_count
BatchLoader::GraphQL.wrap(object.open_issues_count) if object.feature_available?(:issues, context[:current_user])
end
def forks_count
BatchLoader::GraphQL.wrap(object.forks_count)
end
def statistics
Gitlab::Graphql::Loaders::BatchProjectStatisticsLoader.new(object.id).find
end
def container_repositories_count
project.container_repositories.size
end
# Even if the parameter name is `sha`, it is actually a ref name. We always send `ref` to the endpoint.
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/389065
def ci_config_variables(sha:)
result = ::Ci::ListConfigVariablesService.new(object, context[:current_user]).execute(sha)
return if result.nil?
result.map do |var_key, var_config|
{ key: var_key, **var_config }
end
end
def job(id:)
object.commit_statuses.find(id.model_id)
rescue ActiveRecord::RecordNotFound
end
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
def service_desk_address
return unless Ability.allowed?(current_user, :admin_issue, project)
object.service_desk_address
end
def languages
::Projects::RepositoryLanguagesService.new(project, current_user).execute
end
def visible_forks(minimum_access_level: nil)
if minimum_access_level.nil?
object.forks.public_or_visible_to_user(current_user)
else
object.forks.visible_to_user_and_access_level(current_user, minimum_access_level)
end
end
private
def project
@project ||= object.respond_to?(:sync) ? object.sync : object
end
def add_file_docs_link
ActionController::Base.helpers.link_to _('add at least one file to the repository'),
Rails.application.routes.url_helpers.help_page_url(
'user/project/repository/index.md',
anchor: 'add-files-to-a-repository'),
target: '_blank',
rel: 'noopener noreferrer'
end
end
end
Types::ProjectType.prepend_mod_with('Types::ProjectType')
|