diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-08-01 11:54:23 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-08-01 11:54:23 +0300 |
commit | bd659f70b18be07dac184ca249c7eee17c703e56 (patch) | |
tree | 0c2091386dc5528f27928d1c5868eea2f140226e /lib | |
parent | e53e4d45296c32e699b98cefdcb4bcde5e1a44bf (diff) | |
parent | 60943a60d822ea490c65914ca3cec5a488742c93 (diff) |
Merge branch 'fj-6860-instance-level-project-templates' into 'master'
[CE Port]: Implement instance level project templates
See merge request gitlab-org/gitlab-ce!20761
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/import_sources.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/template_helper.rb | 22 |
2 files changed, 30 insertions, 4 deletions
diff --git a/lib/gitlab/import_sources.rb b/lib/gitlab/import_sources.rb index af9b880ef9e..45816bee176 100644 --- a/lib/gitlab/import_sources.rb +++ b/lib/gitlab/import_sources.rb @@ -22,24 +22,28 @@ module Gitlab class << self def options - @options ||= Hash[ImportTable.map { |importer| [importer.title, importer.name] }] + Hash[import_table.map { |importer| [importer.title, importer.name] }] end def values - @values ||= ImportTable.map(&:name) + import_table.map(&:name) end def importer_names - @importer_names ||= ImportTable.select(&:importer).map(&:name) + import_table.select(&:importer).map(&:name) end def importer(name) - ImportTable.find { |import_source| import_source.name == name }.importer + import_table.find { |import_source| import_source.name == name }.importer end def title(name) options.key(name) end + + def import_table + ImportTable + end end end end diff --git a/lib/gitlab/template_helper.rb b/lib/gitlab/template_helper.rb new file mode 100644 index 00000000000..3b8e45e0688 --- /dev/null +++ b/lib/gitlab/template_helper.rb @@ -0,0 +1,22 @@ +module Gitlab + module TemplateHelper + include Gitlab::Utils::StrongMemoize + + def prepare_template_environment(file_path) + return unless file_path.present? + + FileUtils.mkdir_p(File.dirname(import_upload_path)) + FileUtils.copy_entry(file_path, import_upload_path) + end + + def import_upload_path + strong_memoize(:import_upload_path) do + Gitlab::ImportExport.import_upload_path(filename: tmp_filename) + end + end + + def tmp_filename + SecureRandom.hex + end + end +end |