Class: Types::MergeRequestType

Inherits:
BaseObject
  • Object
show all
Defined in:
app/graphql/types/merge_request_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

#available_auto_merge_strategiesObject



357
358
359
# File 'app/graphql/types/merge_request_type.rb', line 357

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

#closed_atObject



361
362
363
# File 'app/graphql/types/merge_request_type.rb', line 361

def closed_at
  object.metrics&.latest_closed_at
end

#commitsObject



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

def commits
  object.commits.commits
end

#commits_without_merge_commitsObject



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

def commits_without_merge_commits
  object.commits.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::ImmutableRelation error



392
393
394
# File 'app/graphql/types/merge_request_type.rb', line 392

def committers
  object.commits.committers
end

#default_merge_commit_messageObject



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

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

#default_squash_commit_messageObject



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

def default_squash_commit_message
  object.default_squash_commit_message(user: current_user)
end

#detailed_merge_statusObject



385
386
387
# File 'app/graphql/types/merge_request_type.rb', line 385

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

#diff_stats(path: nil) ⇒ Object



327
328
329
330
331
332
333
334
335
# File 'app/graphql/types/merge_request_type.rb', line 327

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



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

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

#discussion_lockedObject



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

def discussion_locked
  !!object.discussion_locked
end

#merge_afterObject



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

def merge_after
  object.merge_schedule&.merge_after
end

#merge_userObject



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

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

#security_auto_fixObject



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

def security_auto_fix
  object.author == ::Users::Internal.security_bot
end

#source_branch_protectedObject



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

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

#user_discussions_countObject



313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'app/graphql/types/merge_request_type.rb', line 313

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

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

#user_notes_countObject



303
304
305
306
307
308
309
310
311
# File 'app/graphql/types/merge_request_type.rb', line 303

def user_notes_count
  BatchLoader::GraphQL.for(object.id).batch(key: :merge_request_user_notes_count) do |ids, loader, args|
    counts = Note.count_for_collection(ids, 'MergeRequest').index_by(&:noteable_id)

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

#web_pathObject



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

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