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
Léo-Paul Géneau
gitlab-ce
Commits
ca92fcd9
Commit
ca92fcd9
authored
Sep 05, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow the TemplateFinder to handle licenses as well
parent
03c73384
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
3 deletions
+28
-3
app/finders/template_finder.rb
app/finders/template_finder.rb
+10
-0
lib/api/templates.rb
lib/api/templates.rb
+3
-3
spec/finders/template_finder_spec.rb
spec/finders/template_finder_spec.rb
+15
-0
No files found.
app/finders/template_finder.rb
View file @
ca92fcd9
...
@@ -5,6 +5,16 @@ class TemplateFinder
...
@@ -5,6 +5,16 @@ class TemplateFinder
gitlab_ci_ymls:
::
Gitlab
::
Template
::
GitlabCiYmlTemplate
gitlab_ci_ymls:
::
Gitlab
::
Template
::
GitlabCiYmlTemplate
}.
freeze
}.
freeze
class
<<
self
def
build
(
type
,
params
=
{})
if
type
==
:licenses
LicenseTemplateFinder
.
new
(
params
)
else
new
(
type
,
params
)
end
end
end
attr_reader
:type
,
:params
attr_reader
:type
,
:params
attr_reader
:vendored_templates
attr_reader
:vendored_templates
...
...
lib/api/templates.rb
View file @
ca92fcd9
...
@@ -33,7 +33,7 @@ module API
...
@@ -33,7 +33,7 @@ module API
popular
=
declared
(
params
)[
:popular
]
popular
=
declared
(
params
)[
:popular
]
popular
=
to_boolean
(
popular
)
if
popular
.
present?
popular
=
to_boolean
(
popular
)
if
popular
.
present?
templates
=
LicenseTemplateFinder
.
new
(
popular:
popular
).
execute
templates
=
TemplateFinder
.
build
(
:licenses
,
popular:
popular
).
execute
present
paginate
(
::
Kaminari
.
paginate_array
(
templates
)),
with:
::
API
::
Entities
::
License
present
paginate
(
::
Kaminari
.
paginate_array
(
templates
)),
with:
::
API
::
Entities
::
License
end
end
...
@@ -46,7 +46,7 @@ module API
...
@@ -46,7 +46,7 @@ module API
requires
:name
,
type:
String
,
desc:
'The name of the template'
requires
:name
,
type:
String
,
desc:
'The name of the template'
end
end
get
"templates/licenses/:name"
,
requirements:
{
name:
/[\w\.-]+/
}
do
get
"templates/licenses/:name"
,
requirements:
{
name:
/[\w\.-]+/
}
do
templates
=
LicenseTemplateFinder
.
new
.
execute
templates
=
TemplateFinder
.
build
(
:licenses
)
.
execute
template
=
templates
.
find
{
|
template
|
template
.
key
==
params
[
:name
]
}
template
=
templates
.
find
{
|
template
|
template
.
key
==
params
[
:name
]
}
not_found!
(
'License'
)
unless
template
.
present?
not_found!
(
'License'
)
unless
template
.
present?
...
@@ -82,7 +82,7 @@ module API
...
@@ -82,7 +82,7 @@ module API
requires
:name
,
type:
String
,
desc:
'The name of the template'
requires
:name
,
type:
String
,
desc:
'The name of the template'
end
end
get
"templates/
#{
template_type
}
/:name"
do
get
"templates/
#{
template_type
}
/:name"
do
finder
=
TemplateFinder
.
new
(
template_type
,
name:
declared
(
params
)[
:name
])
finder
=
TemplateFinder
.
build
(
template_type
,
name:
declared
(
params
)[
:name
])
new_template
=
finder
.
execute
new_template
=
finder
.
execute
render_response
(
template_type
,
new_template
)
render_response
(
template_type
,
new_template
)
...
...
spec/finders/template_finder_spec.rb
View file @
ca92fcd9
...
@@ -3,6 +3,21 @@ require 'spec_helper'
...
@@ -3,6 +3,21 @@ require 'spec_helper'
describe
TemplateFinder
do
describe
TemplateFinder
do
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
describe
'#build'
do
where
(
:type
,
:expected_class
)
do
:dockerfiles
|
described_class
:gitignores
|
described_class
:gitlab_ci_ymls
|
described_class
:licenses
|
::
LicenseTemplateFinder
end
with_them
do
subject
{
described_class
.
build
(
type
)
}
it
{
is_expected
.
to
be_a
(
expected_class
)
}
end
end
describe
'#execute'
do
describe
'#execute'
do
where
(
:type
,
:vendored_name
)
do
where
(
:type
,
:vendored_name
)
do
:dockerfiles
|
'Binary'
:dockerfiles
|
'Binary'
...
...
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