diff options
author | Rémy Coutable <remy@rymai.me> | 2016-12-16 11:15:30 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-12-19 19:35:51 +0300 |
commit | 8fc63d1f648fa38eac9e5422dd42667d8e7f1b49 (patch) | |
tree | 0b211c3385aa55518e76c43b6469c3e612e34c60 /lib/gitlab/import_sources.rb | |
parent | 99ddd1dcbed35b642d7bd8a52cc6e5e5453b9f8b (diff) |
Improve Gitlab::ImportSources
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/gitlab/import_sources.rb')
-rw-r--r-- | lib/gitlab/import_sources.rb | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/lib/gitlab/import_sources.rb b/lib/gitlab/import_sources.rb index 34587582bd1..45958710c13 100644 --- a/lib/gitlab/import_sources.rb +++ b/lib/gitlab/import_sources.rb @@ -7,22 +7,38 @@ module Gitlab module ImportSources extend CurrentSettings + 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 + class << self + def options + @options ||= Hash[ImportTable.map { |importer| [importer.title, importer.name] }] + end + def values - options.values + @values ||= ImportTable.map(&:name) end - def options - { - 'GitHub' => 'github', - 'Bitbucket' => 'bitbucket', - 'GitLab.com' => 'gitlab', - 'Google Code' => 'google_code', - 'FogBugz' => 'fogbugz', - 'Repo by URL' => 'git', - 'GitLab export' => 'gitlab_project', - 'Gitea' => 'gitea' - } + 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) end end end |