Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
f6f62950
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
f6f62950
编写于
8月 14, 2018
作者:
N
Nick Thomas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Convert the license template API to use the new LicenseTemplateFinder
上级
40d1fc1c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
18 addition
and
31 deletion
+18
-31
lib/api/entities.rb
lib/api/entities.rb
+1
-1
lib/api/templates.rb
lib/api/templates.rb
+14
-30
spec/requests/api/templates_spec.rb
spec/requests/api/templates_spec.rb
+3
-0
未找到文件。
lib/api/entities.rb
浏览文件 @
f6f62950
...
...
@@ -1159,7 +1159,7 @@ module API
class
License
<
Grape
::
Entity
expose
:key
,
:name
,
:nickname
expose
:
featured
,
as: :popular
expose
:
popular?
,
as: :popular
expose
:url
,
as: :html_url
expose
(
:source_url
)
{
|
license
|
license
.
meta
[
'source'
]
}
expose
(
:description
)
{
|
license
|
license
.
meta
[
'description'
]
}
...
...
lib/api/templates.rb
浏览文件 @
f6f62950
...
...
@@ -16,31 +16,8 @@ module API
gitlab_version:
8.15
}
}.
freeze
PROJECT_TEMPLATE_REGEX
=
%r{[
\<\{\[
]
(project|description|
one
\s
line
\s
.+
\s
what
\s
it
\s
does
\.
) # matching the start and end is enough here
[
\>\}\]
]}xi
.
freeze
YEAR_TEMPLATE_REGEX
=
/[<{\[](year|yyyy)[>}\]]/i
.
freeze
FULLNAME_TEMPLATE_REGEX
=
%r{[
\<\{\[
]
(fullname|name
\s
of
\s
(author|copyright
\s
owner))
[
\>\}\]
]}xi
.
freeze
helpers
do
def
parsed_license_template
# We create a fresh Licensee::License object since we'll modify its
# content in place below.
template
=
Licensee
::
License
.
new
(
params
[
:name
])
template
.
content
.
gsub!
(
YEAR_TEMPLATE_REGEX
,
Time
.
now
.
year
.
to_s
)
template
.
content
.
gsub!
(
PROJECT_TEMPLATE_REGEX
,
params
[
:project
])
if
params
[
:project
].
present?
fullname
=
params
[
:fullname
].
presence
||
current_user
.
try
(
:name
)
template
.
content
.
gsub!
(
FULLNAME_TEMPLATE_REGEX
,
fullname
)
if
fullname
template
end
def
render_response
(
template_type
,
template
)
not_found!
(
template_type
.
to_s
.
singularize
)
unless
template
present
template
,
with:
Entities
::
Template
...
...
@@ -56,11 +33,12 @@ module API
use
:pagination
end
get
"templates/licenses"
do
options
=
{
featured:
declared
(
params
)[
:popular
].
present?
?
true
:
nil
}
licences
=
::
Kaminari
.
paginate_array
(
Licensee
::
License
.
all
(
options
))
present
paginate
(
licences
),
with:
Entities
::
License
popular
=
declared
(
params
)[
:popular
]
popular
=
to_boolean
(
popular
)
if
popular
.
present?
templates
=
LicenseTemplateFinder
.
new
(
popular:
popular
).
execute
present
paginate
(
::
Kaminari
.
paginate_array
(
templates
)),
with:
::
API
::
Entities
::
License
end
desc
'Get the text for a specific license'
do
...
...
@@ -71,9 +49,15 @@ module API
requires
:name
,
type:
String
,
desc:
'The name of the template'
end
get
"templates/licenses/:name"
,
requirements:
{
name:
/[\w\.-]+/
}
do
not_found!
(
'License'
)
unless
Licensee
::
License
.
find
(
declared
(
params
)[
:name
])
templates
=
LicenseTemplateFinder
.
new
.
execute
template
=
templates
.
find
{
|
template
|
template
.
key
==
params
[
:name
]
}
not_found!
(
'License'
)
unless
template
.
present?
template
=
parsed_license_template
template
.
resolve!
(
project_name:
params
[
:project
].
presence
,
fullname:
params
[
:fullname
].
presence
||
current_user
&
.
name
)
present
template
,
with:
::
API
::
Entities
::
License
end
...
...
spec/requests/api/templates_spec.rb
浏览文件 @
f6f62950
...
...
@@ -56,6 +56,8 @@ describe API::Templates do
end
it
'returns a license template'
do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'key'
]).
to
eq
(
'mit'
)
expect
(
json_response
[
'name'
]).
to
eq
(
'MIT License'
)
expect
(
json_response
[
'nickname'
]).
to
be_nil
...
...
@@ -181,6 +183,7 @@ describe API::Templates do
it
'replaces the copyright owner placeholder with the name of the current user'
do
get
api
(
'/templates/licenses/mit'
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'content'
]).
to
include
(
"Copyright (c)
#{
Time
.
now
.
year
}
#{
user
.
name
}
"
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录