Class: SnippetRepository

Inherits:
ApplicationRecord show all
Includes:
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$/.freeze
CommitError =
Class.new(StandardError)
InvalidPathError =
Class.new(CommitError)
InvalidSignatureError =
Class.new(CommitError)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shardable

#shard_name, #shard_name=

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

.find_snippet(disk_path) ⇒ Object


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

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

Instance Method Details

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


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

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.multi_action(user, **options) }
ensure
  Gitlab::ExclusiveLease.cancel(lease_key, uuid)
end