debian-mirror-gitlab/lib/gitlab/github_import/sequential_importer.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2 KiB
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
# 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,
2018-11-08 19:23:39 +05:30
Importer::NotesImporter,
Importer::LfsObjectsImporter
2018-03-17 18:26:18 +05:30
].freeze
# project - The project to import the data into.
# token - The token to use for the GitHub API.
2021-01-29 00:20:46 +05:30
# host - The GitHub hostname. If nil, github.com will be used.
def initialize(project, token: nil, host: nil)
2018-03-17 18:26:18 +05:30
@project = project
@client = GithubImport
2021-01-29 00:20:46 +05:30
.new_client_for(project, token: token, host: host, parallel: false)
2018-03-17 18:26:18 +05:30
end
def execute
2021-11-18 22:05:49 +05:30
metrics.track_start_import
2018-03-17 18:26:18 +05:30
2021-11-18 22:05:49 +05:30
begin
Importer::RepositoryImporter.new(project, client).execute
SEQUENTIAL_IMPORTERS.each do |klass|
klass.new(project, client).execute
end
rescue StandardError => e
Gitlab::Import::ImportFailureService.track(
project_id: project.id,
error_source: self.class.name,
exception: e,
fail_import: true,
metrics: true
)
raise(e)
2018-03-17 18:26:18 +05:30
end
PARALLEL_IMPORTERS.each do |klass|
klass.new(project, client, parallel: false).execute
end
2021-11-18 22:05:49 +05:30
metrics.track_finished_import
2018-03-17 18:26:18 +05:30
true
end
2021-11-18 22:05:49 +05:30
private
def metrics
@metrics ||= Gitlab::Import::Metrics.new(:github_importer, project)
end
2018-03-17 18:26:18 +05:30
end
end
end