summaryrefslogtreecommitdiff
path: root/app/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker.rb
blob: e110b7c1c36f755b9c9fada3049bf254647cc227 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module Gitlab
  module GithubImport
    module Stage
      class ImportIssuesAndDiffNotesWorker
        include Sidekiq::Worker
        include GithubImport::Queue
        include StageMethods

        # The importers to run in this stage. Issues can't be imported earlier
        # on as we also use these to enrich pull requests with assigned labels.
        IMPORTERS = [
          Importer::IssuesImporter,
          Importer::DiffNotesImporter
        ].freeze

        # client - An instance of Gitlab::GithubImport::Client.
        # project - An instance of Project.
        def import(client, project)
          waiters = IMPORTERS.each_with_object({}) do |klass, hash|
            waiter = klass.new(project, client).execute
            hash[waiter.key] = waiter.jobs_remaining
          end

          AdvanceStageWorker.perform_async(project.id, waiters, :notes)
        end
      end
    end
  end
end