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 @@
labelsPath: "/api/:version/projects/:id/labels"
licensePath: "/api/:version/licenses/:key"
gitignorePath: "/api/:version/gitignores/:key"
gitlabCIYmlPath: "/api/:version/gitlab_ci_ymls/:key"
gitlabCiYmlPath: "/api/:version/gitlab_ci_ymls/:key"
group: (group_id, callback) ->
url = Api.buildUrl(Api.groupPath)
......@@ -111,8 +111,8 @@
$.get url, (gitignore) ->
callback(gitignore)
gitlabCIYml: (key, callback) ->
url = Api.buildUrl(Api.gitlabCIYmlPath).replace(':key', key)
gitlabCiYml: (key, callback) ->
url = Api.buildUrl(Api.gitlabCiYmlPath).replace(':key', key)
$.get url, (file) ->
callback(file)
......
......@@ -2,7 +2,7 @@
class @BlobCiYamlSelector extends TemplateSelector
requestFile: (query) ->
Api.gitlabCIYml query.name, @requestFileSuccess.bind(@)
Api.gitlabCiYml query.name, @requestFileSuccess.bind(@)
class @BlobCiYamlSelectors
constructor: (opts) ->
......
......@@ -194,8 +194,8 @@ module BlobHelper
def gitlab_ci_ymls
@gitlab_ci_ymls ||=
Gitlab::Template::GitlabCIYml.categories.keys.map do |k|
[k, Gitlab::Template::GitlabCIYml.by_category(k).map { |t| { name: t.name } }]
Gitlab::Template::GitlabCiYml.categories.keys.map do |k|
[k, Gitlab::Template::GitlabCiYml.by_category(k).map { |t| { name: t.name } }]
end.to_h
end
end
......@@ -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
......
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
......
module Gitlab
module Template
class GitlabCIYml < BaseTemplate
class GitlabCiYml < BaseTemplate
class << self
def extension
'.gitlab-ci.yml'
......
......@@ -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')
......
......@@ -40,4 +40,13 @@ describe API::Templates, api: true do
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
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