summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2017-07-26 14:21:53 +0200
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-07-28 11:32:46 +0200
commit1d3815f89b9b9f5ecfd6dd15158a2988603b9ed8 (patch)
treea694e1e05f58fc3fe5ae00135d4a439eef7c8150 /lib
parentd964816b9fe56679ffc0b331e701f7b24db5c6a9 (diff)
downloadgitlab-ce-1d3815f89b9b9f5ecfd6dd15158a2988603b9ed8.tar.gz
Allow projects to be started from a template
Started implementation for the first iteration of gitlab-org/gitlab-ce#32420. This will allow users to select a template to start with, instead of an empty repository in the project just created. Internally this is basically a small extension of the ImportExport GitLab projects we already support. We just import a certain import tar archive. This commits includes the first one: Ruby on Rails. In the future more will be added.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/import_export.rb4
-rw-r--r--lib/gitlab/project_template.rb39
2 files changed, 42 insertions, 1 deletions
diff --git a/lib/gitlab/import_export.rb b/lib/gitlab/import_export.rb
index 3470a09eaf0..9f23d29218b 100644
--- a/lib/gitlab/import_export.rb
+++ b/lib/gitlab/import_export.rb
@@ -15,7 +15,9 @@ module Gitlab
end
def import_upload_path(filename:)
- File.join(storage_path, 'uploads', filename)
+ milliseconds = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
+
+ File.join(storage_path, 'uploads', "#{millisecond}-#{filename}")
end
def project_filename
diff --git a/lib/gitlab/project_template.rb b/lib/gitlab/project_template.rb
new file mode 100644
index 00000000000..72fcda154c5
--- /dev/null
+++ b/lib/gitlab/project_template.rb
@@ -0,0 +1,39 @@
+module Gitlab
+ class ProjectTemplate
+ attr_reader :title, :name
+
+ def initialize(name, title)
+ @name, @title = name, title
+ end
+
+ def logo_path
+ "project_templates/#{name}.png"
+ end
+
+ def file
+ template_archive.open
+ end
+
+ def template_archive
+ Rails.root.join("vendor/project_templates/#{name}.tar.gz")
+ end
+
+ def ==(other)
+ name == other.name && title == other.title
+ end
+
+ TemplatesTable = [
+ ProjectTemplate.new('rails', 'Ruby on Rails')
+ ].freeze
+
+ class << self
+ def all
+ TemplatesTable
+ end
+
+ def find(name)
+ all.find { |template| template.name == name.to_s }
+ end
+ end
+ end
+end