summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/templates.rb6
-rw-r--r--lib/gitlab/template/base_template.rb4
-rw-r--r--lib/gitlab/template/gitlab_ci_yml.rb2
-rw-r--r--lib/tasks/gitlab/update_templates.rake18
4 files changed, 19 insertions, 11 deletions
diff --git a/lib/api/templates.rb b/lib/api/templates.rb
index 9f5f10a5088..33cbb0c9e1b 100644
--- a/lib/api/templates.rb
+++ b/lib/api/templates.rb
@@ -2,7 +2,7 @@ module API
class Templates < Grape::API
TEMPLATE_TYPES = {
gitignores: Gitlab::Template::Gitignore,
- gitlab_ci_ymls: Gitlab::Template::GitlabCIYml
+ gitlab_ci_ymls: Gitlab::Template::GitlabCiYml
}.freeze
TEMPLATE_TYPES.each do |template, klass|
@@ -29,6 +29,10 @@ module API
new_template = klass.find(params[:name])
not_found!("#{template.to_s.singularize}") unless new_template
+ if new_template.class == Gitlab::Template::GitlabCiYml
+ new_template.content = "# This file is a template, and might need editing before it works on your project.\n" + new_template.content
+ end
+
present new_template, with: Entities::Template
end
end
diff --git a/lib/gitlab/template/base_template.rb b/lib/gitlab/template/base_template.rb
index 652a496b57b..4086d8701bf 100644
--- a/lib/gitlab/template/base_template.rb
+++ b/lib/gitlab/template/base_template.rb
@@ -1,6 +1,8 @@
module Gitlab
module Template
class BaseTemplate
+ attr_writer :content
+
def initialize(path)
@path = path
end
@@ -10,7 +12,7 @@ module Gitlab
end
def content
- File.read(@path)
+ @content ||= File.read(@path)
end
def categories
diff --git a/lib/gitlab/template/gitlab_ci_yml.rb b/lib/gitlab/template/gitlab_ci_yml.rb
index da7273b8d70..f1e96d22d64 100644
--- a/lib/gitlab/template/gitlab_ci_yml.rb
+++ b/lib/gitlab/template/gitlab_ci_yml.rb
@@ -1,6 +1,6 @@
module Gitlab
module Template
- class GitlabCIYml < BaseTemplate
+ class GitlabCiYml < BaseTemplate
class << self
def extension
'.gitlab-ci.yml'
diff --git a/lib/tasks/gitlab/update_templates.rake b/lib/tasks/gitlab/update_templates.rake
index 14277fe4c4b..2d3c7993445 100644
--- a/lib/tasks/gitlab/update_templates.rake
+++ b/lib/tasks/gitlab/update_templates.rake
@@ -37,14 +37,16 @@ namespace :gitlab do
private
Template = Struct.new(:repo_url, :cleanup_regex)
- TEMPLATE_DATA = [Template.new(
- "https://github.com/github/gitignore.git",
- /(\.{1,2}|LICENSE|Global|\.gitignore)\z/
- ),
- Template.new(
- "https://gitlab.com/gitlab-org/gitlab-ci-yml.git",
- /(\.{1,2}|LICENSE|Pages|\.gitlab-ci.yml)\z/
- )]
+ TEMPLATE_DATA = [
+ Template.new(
+ "https://github.com/github/gitignore.git",
+ /(\.{1,2}|LICENSE|Global|\.gitignore)\z/
+ ),
+ Template.new(
+ "https://gitlab.com/gitlab-org/gitlab-ci-yml.git",
+ /(\.{1,2}|LICENSE|Pages|\.gitlab-ci.yml)\z/
+ )
+ ]
def vendor_directory
Rails.root.join('vendor')