Class: SnippetRepository

Inherits:
ApplicationRecord show all
Includes:
EachBatch, Shardable
Defined in:
app/models/snippet_repository.rb

Constant Summary collapse

DEFAULT_EMPTY_FILE_NAME =
'snippetfile'
EMPTY_FILE_PATTERN =
/^#{DEFAULT_EMPTY_FILE_NAME}(\d+)\.txt$/
CommitError =
Class.new(StandardError)
InvalidPathError =
Class.new(CommitError)
InvalidSignatureError =
Class.new(CommitError)

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shardable

#shard_name, #shard_name=

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.find_snippet(disk_path) ⇒ Object



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

def find_snippet(disk_path)
  find_by(disk_path: disk_path)&.snippet
end

Instance Method Details

#multi_files_action(user, files = [], **options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/snippet_repository.rb', line 24

def multi_files_action(user, files = [], **options)
  return if files.nil? || files.empty?

  lease_key = "multi_files_action:#{snippet_id}"

  lease = Gitlab::ExclusiveLease.new(lease_key, timeout: 120)
  raise CommitError, 'Snippet is already being updated' unless uuid = lease.try_obtain

  options[:actions] = transform_file_entries(files)

  capture_git_error { repository.commit_files(user, **options) }
ensure
  Gitlab::ExclusiveLease.cancel(lease_key, uuid)
end