Class: Types::MergeRequestType

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseObject

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

Methods included from Gitlab::Graphql::Present

#present, #unpresented

Class Method Details

.authorization_scopesObject



15
16
17
# File 'app/graphql/types/merge_request_type.rb', line 15

def self.authorization_scopes
  super + [:ai_workflows]
end

Instance Method Details

#available_auto_merge_strategiesObject



350
351
352
# File 'app/graphql/types/merge_request_type.rb', line 350

def available_auto_merge_strategies
  AutoMergeService.new(object.project, current_user).available_strategies(object)
end

#closed_atObject



354
355
356
# File 'app/graphql/types/merge_request_type.rb', line 354

def closed_at
  object.metrics&.latest_closed_at
end

#commitsObject



358
359
360
361
362
# File 'app/graphql/types/merge_request_type.rb', line 358

def commits
  object.commits(
    load_from_gitaly: true
  ).commits
end

#commits_without_merge_commitsObject



364
365
366
367
368
# File 'app/graphql/types/merge_request_type.rb', line 364

def commits_without_merge_commits
  object.commits(
    load_from_gitaly: true
  ).without_merge_commits
end

#committersObject

This is temporary to fix a bug where committers is already loaded and memoized and calling it again with a certain GraphQL query can cause the Rails to to throw a ActiveRecord::UnmodifiableRelation error



389
390
391
392
393
394
395
# File 'app/graphql/types/merge_request_type.rb', line 389

def committers
  if Feature.enabled?(:load_commits_from_gitaly_in_graphql, object.project)
    object.commits(load_from_gitaly: true).committers
  else
    object.commits.committers
  end
end

#default_merge_commit_messageObject



342
343
344
# File 'app/graphql/types/merge_request_type.rb', line 342

def default_merge_commit_message
  object.default_merge_commit_message(include_description: false, user: current_user)
end

#default_squash_commit_messageObject



346
347
348
# File 'app/graphql/types/merge_request_type.rb', line 346

def default_squash_commit_message
  object.default_squash_commit_message(user: current_user)
end

#detailed_merge_statusObject



382
383
384
# File 'app/graphql/types/merge_request_type.rb', line 382

def detailed_merge_status
  ::MergeRequests::Mergeability::DetailedMergeStatusService.new(merge_request: object).execute
end

#diff_stats(path: nil) ⇒ Object



320
321
322
323
324
325
326
327
328
# File 'app/graphql/types/merge_request_type.rb', line 320

def diff_stats(path: nil)
  stats = Array.wrap(object.diff_stats&.to_a)

  if path.present?
    stats.select { |s| s.path == path }
  else
    stats
  end
end

#diff_stats_summaryObject



330
331
332
# File 'app/graphql/types/merge_request_type.rb', line 330

def diff_stats_summary
  BatchLoaders::MergeRequestDiffSummaryBatchLoader.load_for(object)
end

#discussion_lockedObject



338
339
340
# File 'app/graphql/types/merge_request_type.rb', line 338

def discussion_locked
  !!object.discussion_locked
end

#merge_afterObject



378
379
380
# File 'app/graphql/types/merge_request_type.rb', line 378

def merge_after
  object.merge_schedule&.merge_after
end

#merge_userObject



374
375
376
# File 'app/graphql/types/merge_request_type.rb', line 374

def merge_user
  object.metrics&.merged_by || object.merge_user
end

#notes_count_for_collection(key) ⇒ Object



409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'app/graphql/types/merge_request_type.rb', line 409

def notes_count_for_collection(key)
  BatchLoader::GraphQL.for(object.id).batch(key: key) do |ids, loader, _args|
    counts = Note.count_for_collection(
      ids,
      'MergeRequest',
      'COUNT(DISTINCT discussion_id) as count'
    )
    counts = yield(counts).index_by(&:noteable_id)

    ids.each do |id|
      loader.call(id, counts[id]&.count || 0)
    end
  end
end

#pipeline_creation_requestsObject



424
425
426
# File 'app/graphql/types/merge_request_type.rb', line 424

def pipeline_creation_requests
  ::Ci::PipelineCreation::Requests.for_merge_request(object)
end

#resolvable_discussions_countObject



401
402
403
# File 'app/graphql/types/merge_request_type.rb', line 401

def resolvable_discussions_count
  notes_count_for_collection(:merge_request_resolvable_discussions_count, &:resolvable)
end

#resolved_discussions_countObject



405
406
407
# File 'app/graphql/types/merge_request_type.rb', line 405

def resolved_discussions_count
  notes_count_for_collection(:merge_request_resolved_discussions_count, &:resolved)
end

#security_auto_fixObject



370
371
372
# File 'app/graphql/types/merge_request_type.rb', line 370

def security_auto_fix
  object.author == ::Users::Internal.in_organization(object.project.organization).security_bot
end

#source_branch_protectedObject



334
335
336
# File 'app/graphql/types/merge_request_type.rb', line 334

def source_branch_protected
  object.source_project.present? && ProtectedBranch.protected?(object.source_project, object.source_branch)
end

#web_pathObject



397
398
399
# File 'app/graphql/types/merge_request_type.rb', line 397

def web_path
  ::Gitlab::Routing.url_helpers.project_merge_request_path(object.project, object)
end