Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
03c73384
Commit
03c73384
authored
Aug 28, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert global templates to vendored templates via a ::TemplateFinder
parent
db28db41
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
19 deletions
+79
-19
app/finders/template_finder.rb
app/finders/template_finder.rb
+27
-0
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+16
-13
lib/api/templates.rb
lib/api/templates.rb
+3
-6
spec/finders/template_finder_spec.rb
spec/finders/template_finder_spec.rb
+33
-0
No files found.
app/finders/template_finder.rb
0 → 100644
View file @
03c73384
class
TemplateFinder
VENDORED_TEMPLATES
=
{
dockerfiles:
::
Gitlab
::
Template
::
DockerfileTemplate
,
gitignores:
::
Gitlab
::
Template
::
GitignoreTemplate
,
gitlab_ci_ymls:
::
Gitlab
::
Template
::
GitlabCiYmlTemplate
}.
freeze
attr_reader
:type
,
:params
attr_reader
:vendored_templates
private
:vendored_templates
def
initialize
(
type
,
params
=
{})
@type
=
type
@params
=
params
@vendored_templates
=
VENDORED_TEMPLATES
.
fetch
(
type
)
end
def
execute
if
params
[
:name
]
vendored_templates
.
find
(
params
[
:name
])
else
vendored_templates
.
all
end
end
end
app/helpers/blob_helper.rb
View file @
03c73384
...
...
@@ -158,32 +158,35 @@ module BlobHelper
end
def
licenses_for_select
return
@licenses_for_select
if
defined?
(
@licenses_for_select
)
grouped_licenses
=
LicenseTemplateFinder
.
new
.
execute
.
group_by
(
&
:category
)
categories
=
grouped_licenses
.
keys
@licenses_for_select
=
categories
.
each_with_object
({})
do
|
category
,
hash
|
hash
[
category
]
=
grouped_licenses
[
category
].
map
do
|
license
|
{
name:
license
.
name
,
id:
license
.
id
}
end
end
@licenses_for_select
||=
dropdown_names
(
LicenseTemplateFinder
.
new
.
execute
)
end
def
ref_project
@ref_project
||=
@target_project
||
@project
end
def
dropdown_names
(
items
)
grouped
=
items
.
group_by
(
&
:category
)
categories
=
grouped
.
keys
categories
.
each_with_object
({})
do
|
category
,
hash
|
hash
[
category
]
=
grouped
[
category
].
map
do
|
item
|
{
name:
item
.
name
,
id:
item
.
id
}
end
end
end
private
:dropdown_names
def
gitignore_names
@gitignore_names
||=
Gitlab
::
Template
::
GitignoreTemplate
.
dropdown_names
@gitignore_names
||=
dropdown_names
(
TemplateFinder
.
new
(
:gitignores
).
execute
)
end
def
gitlab_ci_ymls
@gitlab_ci_ymls
||=
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
dropdown_names
(
params
[
:context
]
)
@gitlab_ci_ymls
||=
dropdown_names
(
TemplateFinder
.
new
(
:gitlab_ci_ymls
).
execute
)
end
def
dockerfile_names
@dockerfile_names
||=
Gitlab
::
Template
::
DockerfileTemplate
.
dropdown_names
@dockerfile_names
||=
dropdown_names
(
TemplateFinder
.
new
(
:dockerfiles
).
execute
)
end
def
blob_editor_paths
...
...
lib/api/templates.rb
View file @
03c73384
...
...
@@ -4,15 +4,12 @@ module API
GLOBAL_TEMPLATE_TYPES
=
{
gitignores:
{
klass:
Gitlab
::
Template
::
GitignoreTemplate
,
gitlab_version:
8.8
},
gitlab_ci_ymls:
{
klass:
Gitlab
::
Template
::
GitlabCiYmlTemplate
,
gitlab_version:
8.9
},
dockerfiles:
{
klass:
Gitlab
::
Template
::
DockerfileTemplate
,
gitlab_version:
8.15
}
}.
freeze
...
...
@@ -63,7 +60,6 @@ module API
end
GLOBAL_TEMPLATE_TYPES
.
each
do
|
template_type
,
properties
|
klass
=
properties
[
:klass
]
gitlab_version
=
properties
[
:gitlab_version
]
desc
'Get the list of the available template'
do
...
...
@@ -74,7 +70,7 @@ module API
use
:pagination
end
get
"templates/
#{
template_type
}
"
do
templates
=
::
Kaminari
.
paginate_array
(
klass
.
all
)
templates
=
::
Kaminari
.
paginate_array
(
TemplateFinder
.
new
(
template_type
).
execute
)
present
paginate
(
templates
),
with:
Entities
::
TemplatesList
end
...
...
@@ -86,7 +82,8 @@ module API
requires
:name
,
type:
String
,
desc:
'The name of the template'
end
get
"templates/
#{
template_type
}
/:name"
do
new_template
=
klass
.
find
(
declared
(
params
)[
:name
])
finder
=
TemplateFinder
.
new
(
template_type
,
name:
declared
(
params
)[
:name
])
new_template
=
finder
.
execute
render_response
(
template_type
,
new_template
)
end
...
...
spec/finders/template_finder_spec.rb
0 → 100644
View file @
03c73384
require
'spec_helper'
describe
TemplateFinder
do
using
RSpec
::
Parameterized
::
TableSyntax
describe
'#execute'
do
where
(
:type
,
:vendored_name
)
do
:dockerfiles
|
'Binary'
:gitignores
|
'Actionscript'
:gitlab_ci_ymls
|
'Android'
end
with_them
do
it
'returns all vendored templates when no name is specified'
do
result
=
described_class
.
new
(
type
).
execute
expect
(
result
).
to
include
(
have_attributes
(
name:
vendored_name
))
end
it
'returns only the specified vendored template when a name is specified'
do
result
=
described_class
.
new
(
type
,
name:
vendored_name
).
execute
expect
(
result
).
to
have_attributes
(
name:
vendored_name
)
end
it
'returns nil when an unknown name is specified'
do
result
=
described_class
.
new
(
type
,
name:
'unknown'
).
execute
expect
(
result
).
to
be_nil
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment