Class: MergeRequestContextCommit

Inherits:
ApplicationRecord show all
Includes:
CachedCommit, ShaAttribute
Defined in:
app/models/merge_request_context_commit.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CachedCommit

#parent_ids, #to_hash

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.bulk_insert(*args) ⇒ Object

create MergeRequestContextCommit by given commit sha and it's diff file record


25
26
27
# File 'app/models/merge_request_context_commit.rb', line 25

def self.bulk_insert(*args)
  Gitlab::Database.bulk_insert('merge_request_context_commits', *args) # rubocop:disable Gitlab/BulkInsert
end

.delete_bulk(merge_request, commits) ⇒ Object

delete all MergeRequestContextCommit & MergeRequestContextCommitDiffFile for given merge_request & commit SHAs


19
20
21
22
# File 'app/models/merge_request_context_commit.rb', line 19

def self.delete_bulk(merge_request, commits)
  commit_ids = commits.map(&:sha)
  merge_request.merge_request_context_commits.where(sha: commit_ids).delete_all
end

Instance Method Details

#to_commitObject


29
30
31
32
33
34
35
36
37
# File 'app/models/merge_request_context_commit.rb', line 29

def to_commit
  # Here we are storing the commit sha because to_hash removes the sha parameter and we lose
  # the reference, this happens because we are storing the ID in db and the Commit class replaces
  # id with sha and removes it, so in our case it will be some incremented integer which is not
  # what we want
  commit_hash = attributes.except('id').to_hash
  commit_hash['id'] = sha
  Commit.from_hash(commit_hash, merge_request.target_project)
end