PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/gitlab/import_sources.rb

https://bitbucket.org/terrchen/gitlab-ce
Ruby | 44 lines | 32 code | 6 blank | 6 comment | 1 complexity | e5ef3dbf1be55858abd592515ce7ffaf MD5 | raw file
Possible License(s): Apache-2.0, CC0-1.0
  1. # Gitlab::ImportSources module
  2. #
  3. # Define import sources that can be used
  4. # during the creation of new project
  5. #
  6. module Gitlab
  7. module ImportSources
  8. ImportSource = Struct.new(:name, :title, :importer)
  9. # We exclude `bare_repository` here as it has no import class associated
  10. ImportTable = [
  11. ImportSource.new('github', 'GitHub', Gitlab::GithubImport::ParallelImporter),
  12. ImportSource.new('bitbucket', 'Bitbucket', Gitlab::BitbucketImport::Importer),
  13. ImportSource.new('gitlab', 'GitLab.com', Gitlab::GitlabImport::Importer),
  14. ImportSource.new('google_code', 'Google Code', Gitlab::GoogleCodeImport::Importer),
  15. ImportSource.new('fogbugz', 'FogBugz', Gitlab::FogbugzImport::Importer),
  16. ImportSource.new('git', 'Repo by URL', nil),
  17. ImportSource.new('gitlab_project', 'GitLab export', Gitlab::ImportExport::Importer),
  18. ImportSource.new('gitea', 'Gitea', Gitlab::LegacyGithubImport::Importer)
  19. ].freeze
  20. class << self
  21. def options
  22. @options ||= Hash[ImportTable.map { |importer| [importer.title, importer.name] }]
  23. end
  24. def values
  25. @values ||= ImportTable.map(&:name)
  26. end
  27. def importer_names
  28. @importer_names ||= ImportTable.select(&:importer).map(&:name)
  29. end
  30. def importer(name)
  31. ImportTable.find { |import_source| import_source.name == name }.importer
  32. end
  33. def title(name)
  34. options.key(name)
  35. end
  36. end
  37. end
  38. end