Class: Gitlab::BackgroundMigration::BackfillSecurityProjectTrackedContextsDefaultBranch::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/backfill_security_project_tracked_contexts_default_branch.rb

Overview

This class depends on following classes

GlRepository class defined in `lib/gitlab/gl_repository.rb`
Repository class defined in `lib/gitlab/git/repository.rb`.

Constant Summary collapse

FORMAT_SHA256 =
'sha256'

Instance Method Summary collapse

Constructor Details

#initialize(full_path, container, shard:, disk_path: nil, repo_type: ::Gitlab::GlRepository::PROJECT) ⇒ Repository

Returns a new instance of Repository.



117
118
119
120
121
122
123
124
# File 'lib/gitlab/background_migration/backfill_security_project_tracked_contexts_default_branch.rb', line 117

def initialize(full_path, container, shard:, disk_path: nil, repo_type: ::Gitlab::GlRepository::PROJECT)
  @full_path = full_path
  @shard = shard
  @disk_path = disk_path || full_path
  @container = container
  @commit_cache = {}
  @repo_type = repo_type
end

Instance Method Details

#commit_files(user, **options) ⇒ Object



150
151
152
# File 'lib/gitlab/background_migration/backfill_security_project_tracked_contexts_default_branch.rb', line 150

def commit_files(user, **options)
  raw_repository.commit_files(user, **options.merge(sign: false))
end

#create_file(user, path, content, **options) ⇒ Object



145
146
147
148
# File 'lib/gitlab/background_migration/backfill_security_project_tracked_contexts_default_branch.rb', line 145

def create_file(user, path, content, **options)
  actions = create_file_actions(path, content)
  commit_files(user, **options.merge(actions: actions))
end

#create_file_actions(path, content) ⇒ Object



141
142
143
# File 'lib/gitlab/background_migration/backfill_security_project_tracked_contexts_default_branch.rb', line 141

def create_file_actions(path, content)
  [{ action: :create, file_path: path, content: content }]
end

#create_repository(default_branch) ⇒ Object



126
127
128
# File 'lib/gitlab/background_migration/backfill_security_project_tracked_contexts_default_branch.rb', line 126

def create_repository(default_branch)
  raw_repository.create_repository(default_branch, object_format: FORMAT_SHA256)
end

#exists?Boolean

Returns:

  • (Boolean)


135
136
137
138
139
# File 'lib/gitlab/background_migration/backfill_security_project_tracked_contexts_default_branch.rb', line 135

def exists?
  return false unless full_path

  raw_repository.exists?
end

#root_refObject



130
131
132
133
# File 'lib/gitlab/background_migration/backfill_security_project_tracked_contexts_default_branch.rb', line 130

def root_ref
  raw_repository&.root_ref
rescue ::Gitlab::Git::Repository::NoRepository
end