Class: Gitlab::GithubImport::Importer::ProtectedBranchesImporter

Inherits:
Object
  • Object
show all
Includes:
ParallelScheduling
Defined in:
lib/gitlab/github_import/importer/protected_branches_importer.rb

Constant Summary

Constants included from ParallelScheduling

ParallelScheduling::ALREADY_IMPORTED_CACHE_KEY, ParallelScheduling::JOB_WAITER_CACHE_KEY, ParallelScheduling::JOB_WAITER_REMAINING_CACHE_KEY

Instance Attribute Summary

Attributes included from ParallelScheduling

#already_imported_cache_key, #client, #job_waiter_cache_key, #job_waiter_remaining_cache_key, #page_counter, #project

Instance Method Summary collapse

Methods included from ParallelScheduling

#abort_on_failure, #already_imported?, #collection_options, #execute, #increment_object_counter?, #initialize, #mark_as_imported, #parallel?, #parallel_import, #sequential_import, #spread_parallel_import

Methods included from JobDelayCalculator

#parallel_import_batch

Instance Method Details

#collection_methodObject



44
45
46
# File 'lib/gitlab/github_import/importer/protected_branches_importer.rb', line 44

def collection_method
  :protected_branches
end

#each_object_to_importObject

The method that will be called for traversing through all the objects to import, yielding them to the supplied block.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/github_import/importer/protected_branches_importer.rb', line 11

def each_object_to_import
  repo = project.import_source

  protected_branches = client.branches(repo).select { |branch| branch.dig(:protection, :enabled) }
  protected_branches.each do |protected_branch|
    next if already_imported?(protected_branch)

    object = client.branch_protection(repo, protected_branch[:name])
    next if object.nil?

    yield object

    Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched)
    mark_as_imported(protected_branch)
  end
end

#id_for_already_imported_cache(protected_branch) ⇒ Object



48
49
50
# File 'lib/gitlab/github_import/importer/protected_branches_importer.rb', line 48

def id_for_already_imported_cache(protected_branch)
  protected_branch[:name]
end

#importer_classObject



28
29
30
# File 'lib/gitlab/github_import/importer/protected_branches_importer.rb', line 28

def importer_class
  ProtectedBranchImporter
end

#object_typeObject



40
41
42
# File 'lib/gitlab/github_import/importer/protected_branches_importer.rb', line 40

def object_type
  :protected_branch
end

#representation_classObject



32
33
34
# File 'lib/gitlab/github_import/importer/protected_branches_importer.rb', line 32

def representation_class
  Gitlab::GithubImport::Representation::ProtectedBranch
end

#sidekiq_worker_classObject



36
37
38
# File 'lib/gitlab/github_import/importer/protected_branches_importer.rb', line 36

def sidekiq_worker_class
  ImportProtectedBranchWorker
end