Class: Gitlab::GithubImport::Importer::PullRequests::ReviewsImporter

Inherits:
Object
  • Object
show all
Includes:
ParallelScheduling
Defined in:
lib/gitlab/github_import/importer/pull_requests/reviews_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?, #mark_as_imported, #parallel?, #parallel_import, #sequential_import, #spread_parallel_import

Methods included from JobDelayCalculator

#parallel_import_batch

Constructor Details

#initializeReviewsImporter

Returns a new instance of ReviewsImporter.



10
11
12
13
14
15
# File 'lib/gitlab/github_import/importer/pull_requests/reviews_importer.rb', line 10

def initialize(...)
  super

  @merge_requests_already_imported_cache_key =
    "github-importer/merge_request/already-imported/#{project.id}"
end

Instance Method Details

#collection_methodObject



29
30
31
# File 'lib/gitlab/github_import/importer/pull_requests/reviews_importer.rb', line 29

def collection_method
  :pull_request_reviews
end

#each_object_to_import(&_block) ⇒ Object

The worker can be interrupted, by rate limit for instance, in different situations. To avoid requesting already imported data, if the worker is interrupted:

  • before importing all reviews of a merge request The reviews page is cached with the ‘PageCounter`, by merge request.

  • before importing all merge requests reviews Merge requests that had all the reviews imported are cached with ‘mark_merge_request_reviews_imported`



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gitlab/github_import/importer/pull_requests/reviews_importer.rb', line 49

def each_object_to_import(&_block)
  each_review_page do |page, merge_request|
    page.objects.each do |review|
      review = review.to_h

      next if already_imported?(review)

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

      review[:merge_request_id] = merge_request.id
      review[:merge_request_iid] = merge_request.iid
      yield(review)

      mark_as_imported(review)
    end
  end
end

#id_for_already_imported_cache(review) ⇒ Object



37
38
39
# File 'lib/gitlab/github_import/importer/pull_requests/reviews_importer.rb', line 37

def id_for_already_imported_cache(review)
  review[:id]
end

#importer_classObject



17
18
19
# File 'lib/gitlab/github_import/importer/pull_requests/reviews_importer.rb', line 17

def importer_class
  ReviewImporter
end

#object_typeObject



33
34
35
# File 'lib/gitlab/github_import/importer/pull_requests/reviews_importer.rb', line 33

def object_type
  :pull_request_review
end

#representation_classObject



21
22
23
# File 'lib/gitlab/github_import/importer/pull_requests/reviews_importer.rb', line 21

def representation_class
  Gitlab::GithubImport::Representation::PullRequestReview
end

#sidekiq_worker_classObject



25
26
27
# File 'lib/gitlab/github_import/importer/pull_requests/reviews_importer.rb', line 25

def sidekiq_worker_class
  Gitlab::GithubImport::PullRequests::ImportReviewWorker
end