import_sources.rb 1.97 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5 6 7 8 9
# Gitlab::ImportSources module
#
# Define import sources that can be used
# during the creation of new project
#
module Gitlab
  module ImportSources
10 11
    ImportSource = Struct.new(:name, :title, :importer)

James Lopez's avatar
James Lopez committed
12
    # We exclude `bare_repository` here as it has no import class associated
13
    IMPORT_TABLE = [
14 15
      ImportSource.new('github',           'GitHub',           Gitlab::GithubImport::ParallelImporter),
      ImportSource.new('bitbucket',        'Bitbucket Cloud',  Gitlab::BitbucketImport::Importer),
16
      ImportSource.new('bitbucket_server', 'Bitbucket Server', Gitlab::BitbucketServerImport::Importer),
17 18 19 20 21 22
      ImportSource.new('gitlab',           'GitLab.com',       Gitlab::GitlabImport::Importer),
      ImportSource.new('google_code',      'Google Code',      Gitlab::GoogleCodeImport::Importer),
      ImportSource.new('fogbugz',          'FogBugz',          Gitlab::FogbugzImport::Importer),
      ImportSource.new('git',              'Repo by URL',      nil),
      ImportSource.new('gitlab_project',   'GitLab export',    Gitlab::ImportExport::Importer),
      ImportSource.new('gitea',            'Gitea',            Gitlab::LegacyGithubImport::Importer),
23 24
      ImportSource.new('manifest',         'Manifest file',    nil),
      ImportSource.new('phabricator',      'Phabricator',      Gitlab::PhabricatorImport::Importer)
25 26
    ].freeze

27
    class << self
28
      prepend_if_ee('EE::Gitlab::ImportSources') # rubocop: disable Cop/InjectEnterpriseEditionModule
29

30
      def options
31
        Hash[import_table.map { |importer| [importer.title, importer.name] }]
32 33
      end

34
      def values
35
        import_table.map(&:name)
36 37
      end

38
      def importer_names
39
        import_table.select(&:importer).map(&:name)
40 41 42
      end

      def importer(name)
43
        import_table.find { |import_source| import_source.name == name }.importer
44 45 46 47
      end

      def title(name)
        options.key(name)
48
      end
49 50

      def import_table
51
        IMPORT_TABLE
52
      end
53 54 55
    end
  end
end