BigW Consortium Gitlab

import_sources.rb 1.42 KB
Newer Older
1 2 3 4 5 6 7
# Gitlab::ImportSources module
#
# Define import sources that can be used
# during the creation of new project
#
module Gitlab
  module ImportSources
8 9 10 11 12 13 14 15 16 17 18 19 20
    ImportSource = Struct.new(:name, :title, :importer)

    ImportTable = [
      ImportSource.new('github',         'GitHub',        Gitlab::GithubImport::Importer),
      ImportSource.new('bitbucket',      'Bitbucket',     Gitlab::BitbucketImport::Importer),
      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::GithubImport::Importer)
    ].freeze

21
    class << self
22 23 24 25
      def options
        @options ||= Hash[ImportTable.map { |importer| [importer.title, importer.name] }]
      end

26
      def values
27
        @values ||= ImportTable.map(&:name)
28 29
      end

30 31 32 33 34 35 36 37 38 39
      def importer_names
        @importer_names ||= ImportTable.select(&:importer).map(&:name)
      end

      def importer(name)
        ImportTable.find { |import_source| import_source.name == name }.importer
      end

      def title(name)
        options.key(name)
40 41 42 43
      end
    end
  end
end