Commit 483dc62e authored by Z.J. van de Weg's avatar Z.J. van de Weg Committed by Alfredo Sumaran

Incorporate review

parent 96ae6099
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
labelsPath: "/api/:version/projects/:id/labels" labelsPath: "/api/:version/projects/:id/labels"
licensePath: "/api/:version/licenses/:key" licensePath: "/api/:version/licenses/:key"
gitignorePath: "/api/:version/gitignores/:key" gitignorePath: "/api/:version/gitignores/:key"
gitlabCIYmlPath: "/api/:version/gitlab_ci_ymls/:key" gitlabCiYmlPath: "/api/:version/gitlab_ci_ymls/:key"
group: (group_id, callback) -> group: (group_id, callback) ->
url = Api.buildUrl(Api.groupPath) url = Api.buildUrl(Api.groupPath)
...@@ -111,8 +111,8 @@ ...@@ -111,8 +111,8 @@
$.get url, (gitignore) -> $.get url, (gitignore) ->
callback(gitignore) callback(gitignore)
gitlabCIYml: (key, callback) -> gitlabCiYml: (key, callback) ->
url = Api.buildUrl(Api.gitlabCIYmlPath).replace(':key', key) url = Api.buildUrl(Api.gitlabCiYmlPath).replace(':key', key)
$.get url, (file) -> $.get url, (file) ->
callback(file) callback(file)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
class @BlobCiYamlSelector extends TemplateSelector class @BlobCiYamlSelector extends TemplateSelector
requestFile: (query) -> requestFile: (query) ->
Api.gitlabCIYml query.name, @requestFileSuccess.bind(@) Api.gitlabCiYml query.name, @requestFileSuccess.bind(@)
class @BlobCiYamlSelectors class @BlobCiYamlSelectors
constructor: (opts) -> constructor: (opts) ->
......
...@@ -194,8 +194,8 @@ module BlobHelper ...@@ -194,8 +194,8 @@ module BlobHelper
def gitlab_ci_ymls def gitlab_ci_ymls
@gitlab_ci_ymls ||= @gitlab_ci_ymls ||=
Gitlab::Template::GitlabCIYml.categories.keys.map do |k| Gitlab::Template::GitlabCiYml.categories.keys.map do |k|
[k, Gitlab::Template::GitlabCIYml.by_category(k).map { |t| { name: t.name } }] [k, Gitlab::Template::GitlabCiYml.by_category(k).map { |t| { name: t.name } }]
end.to_h end.to_h
end end
end end
...@@ -2,7 +2,7 @@ module API ...@@ -2,7 +2,7 @@ module API
class Templates < Grape::API class Templates < Grape::API
TEMPLATE_TYPES = { TEMPLATE_TYPES = {
gitignores: Gitlab::Template::Gitignore, gitignores: Gitlab::Template::Gitignore,
gitlab_ci_ymls: Gitlab::Template::GitlabCIYml gitlab_ci_ymls: Gitlab::Template::GitlabCiYml
}.freeze }.freeze
TEMPLATE_TYPES.each do |template, klass| TEMPLATE_TYPES.each do |template, klass|
...@@ -29,6 +29,10 @@ module API ...@@ -29,6 +29,10 @@ module API
new_template = klass.find(params[:name]) new_template = klass.find(params[:name])
not_found!("#{template.to_s.singularize}") unless new_template 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 present new_template, with: Entities::Template
end end
end end
......
module Gitlab module Gitlab
module Template module Template
class BaseTemplate class BaseTemplate
attr_writer :content
def initialize(path) def initialize(path)
@path = path @path = path
end end
...@@ -10,7 +12,7 @@ module Gitlab ...@@ -10,7 +12,7 @@ module Gitlab
end end
def content def content
File.read(@path) @content ||= File.read(@path)
end end
def categories def categories
......
module Gitlab module Gitlab
module Template module Template
class GitlabCIYml < BaseTemplate class GitlabCiYml < BaseTemplate
class << self class << self
def extension def extension
'.gitlab-ci.yml' '.gitlab-ci.yml'
......
...@@ -37,14 +37,16 @@ namespace :gitlab do ...@@ -37,14 +37,16 @@ namespace :gitlab do
private private
Template = Struct.new(:repo_url, :cleanup_regex) Template = Struct.new(:repo_url, :cleanup_regex)
TEMPLATE_DATA = [Template.new( TEMPLATE_DATA = [
Template.new(
"https://github.com/github/gitignore.git", "https://github.com/github/gitignore.git",
/(\.{1,2}|LICENSE|Global|\.gitignore)\z/ /(\.{1,2}|LICENSE|Global|\.gitignore)\z/
), ),
Template.new( Template.new(
"https://gitlab.com/gitlab-org/gitlab-ci-yml.git", "https://gitlab.com/gitlab-org/gitlab-ci-yml.git",
/(\.{1,2}|LICENSE|Pages|\.gitlab-ci.yml)\z/ /(\.{1,2}|LICENSE|Pages|\.gitlab-ci.yml)\z/
)] )
]
def vendor_directory def vendor_directory
Rails.root.join('vendor') Rails.root.join('vendor')
......
...@@ -40,4 +40,13 @@ describe API::Templates, api: true do ...@@ -40,4 +40,13 @@ describe API::Templates, api: true do
end end
end end
end end
describe 'GET /gitlab_ci_ymls/Ruby' do
it 'adds a disclaimer on the top' do
get api('/gitlab_ci_ymls/Ruby')
expect(response.status).to eq(200)
expect(json_response['content']).to start_with("# This file is a template,")
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment