Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sequential_importer.rb « github_import « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb6b20172084c2b7d6bcc655ccc7237a4e62c027 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

module Gitlab
  module GithubImport
    # The SequentialImporter imports a GitHub project in a single thread,
    # without using Sidekiq. This makes it useful for testing purposes as well
    # as Rake tasks, but it should be avoided for anything else in favour of the
    # parallel importer.
    class SequentialImporter
      attr_reader :project, :client

      SEQUENTIAL_IMPORTERS = [
        Importer::LabelsImporter,
        Importer::MilestonesImporter,
        Importer::ReleasesImporter
      ].freeze

      PARALLEL_IMPORTERS = [
        Importer::PullRequestsImporter,
        Importer::IssuesImporter,
        Importer::DiffNotesImporter,
        Importer::NotesImporter,
        Importer::LfsObjectsImporter
      ].freeze

      # project - The project to import the data into.
      # token - The token to use for the GitHub API.
      # host - The GitHub hostname. If nil, github.com will be used.
      def initialize(project, token: nil, host: nil)
        @project = project
        @client = GithubImport
          .new_client_for(project, token: token, host: host, parallel: false)
      end

      def execute
        Importer::RepositoryImporter.new(project, client).execute

        SEQUENTIAL_IMPORTERS.each do |klass|
          klass.new(project, client).execute
        end

        PARALLEL_IMPORTERS.each do |klass|
          klass.new(project, client, parallel: false).execute
        end

        true
      end
    end
  end
end