Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
b8c4a65d
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 搜索 >>
未验证
提交
b8c4a65d
编写于
4月 22, 2016
作者:
R
Rémy Coutable
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix license detection to detect all license files, not only known licenses
Fixes #15470. Signed-off-by:
N
Rémy Coutable
<
remy@rymai.me
>
上级
2eee6a0c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
48 deletion
+59
-48
CHANGELOG
CHANGELOG
+3
-2
app/helpers/projects_helper.rb
app/helpers/projects_helper.rb
+12
-8
app/models/repository.rb
app/models/repository.rb
+3
-7
spec/helpers/projects_helper_spec.rb
spec/helpers/projects_helper_spec.rb
+26
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+15
-31
未找到文件。
CHANGELOG
浏览文件 @
b8c4a65d
...
...
@@ -4,8 +4,9 @@ v 8.8.0 (unreleased)
- Remove future dates from contribution calendar graph.
v 8.7.1 (unreleased)
- Use the `can?` helper instead of `current_user.can?`
- Fix .gitlab-ci.yml parsing issue when hidde job is a template without script definition
- Fix .gitlab-ci.yml parsing issue when hidde job is a template without script definition. !3849
- Fix license detection to detect all license files, not only known licenses. !3878
- Use the `can?` helper instead of `current_user.can?`. !3882
v 8.7.0
- Gitlab::GitAccess and Gitlab::GitAccessWiki are now instrumented
...
...
app/helpers/projects_helper.rb
浏览文件 @
b8c4a65d
...
...
@@ -123,6 +123,18 @@ module ProjectsHelper
end
end
def
license_short_name
(
project
)
no_license_key
=
project
.
repository
.
license_key
.
nil?
||
# Back-compat if cache contains 'no-license', can be removed in a few weeks
project
.
repository
.
license_key
==
'no-license'
return
'LICENSE'
if
no_license_key
license
=
Licensee
::
License
.
new
(
project
.
repository
.
license_key
)
license
.
nickname
||
license
.
name
end
private
def
get_project_nav_tabs
(
project
,
current_user
)
...
...
@@ -320,14 +332,6 @@ module ProjectsHelper
@ref
||
@repository
.
try
(
:root_ref
)
end
def
license_short_name
(
project
)
license
=
Licensee
::
License
.
new
(
project
.
repository
.
license_key
)
license
.
nickname
||
license
.
name
end
private
def
filename_path
(
project
,
filename
)
if
project
&&
blob
=
project
.
repository
.
send
(
filename
)
namespace_project_blob_path
(
...
...
app/models/repository.rb
浏览文件 @
b8c4a65d
...
...
@@ -466,8 +466,8 @@ class Repository
return
nil
if
!
exists?
||
empty?
cache
.
fetch
(
:license_blob
)
do
if
licensee_project
.
license
blob_at_branch
(
root_ref
,
licensee_project
.
matched_file
.
filename
)
tree
(
:head
).
blobs
.
find
do
|
file
|
file
.
name
=~
/\A(licen[sc]e|copying)(\..+|\z)/i
end
end
end
...
...
@@ -476,7 +476,7 @@ class Repository
return
nil
if
!
exists?
||
empty?
cache
.
fetch
(
:license_key
)
do
licensee_project
.
license
.
try
(
:key
)
||
'no-license'
Licensee
.
license
(
path
).
try
(
:key
)
end
end
...
...
@@ -959,8 +959,4 @@ class Repository
def
cache
@cache
||=
RepositoryCache
.
new
(
path_with_namespace
)
end
def
licensee_project
@licensee_project
||=
Licensee
.
project
(
path
)
end
end
spec/helpers/projects_helper_spec.rb
浏览文件 @
b8c4a65d
...
...
@@ -105,4 +105,30 @@ describe ProjectsHelper do
end
end
end
describe
'#license_short_name'
do
let
(
:project
)
{
create
(
:project
)
}
context
'when project.repository has a license_key'
do
it
'returns the nickname of the license if present'
do
allow
(
project
.
repository
).
to
receive
(
:license_key
).
and_return
(
'agpl-3.0'
)
expect
(
helper
.
license_short_name
(
project
)).
to
eq
(
'GNU AGPLv3'
)
end
it
'returns the name of the license if nickname is not present'
do
allow
(
project
.
repository
).
to
receive
(
:license_key
).
and_return
(
'mit'
)
expect
(
helper
.
license_short_name
(
project
)).
to
eq
(
'MIT License'
)
end
end
context
'when project.repository has no license_key but a license_blob'
do
it
'returns LICENSE'
do
allow
(
project
.
repository
).
to
receive
(
:license_key
).
and_return
(
nil
)
expect
(
helper
.
license_short_name
(
project
)).
to
eq
(
'LICENSE'
)
end
end
end
end
spec/models/repository_spec.rb
浏览文件 @
b8c4a65d
...
...
@@ -132,7 +132,6 @@ describe Repository, models: true do
it
{
expect
(
subject
.
basename
).
to
eq
(
'a/b/c'
)
}
end
end
end
describe
'#license_blob'
do
...
...
@@ -148,39 +147,18 @@ describe Repository, models: true do
expect
(
repository
.
license_blob
).
to
be_nil
end
it
'favors license file with no extension'
do
repository
.
commit_file
(
user
,
'LICENSE'
,
Licensee
::
License
.
new
(
'mit'
).
content
,
'Add LICENSE'
,
'master'
,
false
)
repository
.
commit_file
(
user
,
'LICENSE.md'
,
Licensee
::
License
.
new
(
'mit'
).
content
,
'Add LICENSE.md'
,
'master'
,
false
)
expect
(
repository
.
license_blob
.
name
).
to
eq
(
'LICENSE'
)
end
it
'favors .md file to .txt'
do
repository
.
commit_file
(
user
,
'LICENSE.md'
,
Licensee
::
License
.
new
(
'mit'
).
content
,
'Add LICENSE.md'
,
'master'
,
false
)
repository
.
commit_file
(
user
,
'LICENSE.txt'
,
Licensee
::
License
.
new
(
'mit'
).
content
,
'Add LICENSE.txt'
,
'master'
,
false
)
expect
(
repository
.
license_blob
.
name
).
to
eq
(
'LICENSE.md'
)
end
it
'favors LICENCE to LICENSE'
do
repository
.
commit_file
(
user
,
'LICENSE'
,
Licensee
::
License
.
new
(
'mit'
).
content
,
'Add LICENSE'
,
'master'
,
false
)
repository
.
commit_file
(
user
,
'LICENCE'
,
Licensee
::
License
.
new
(
'mit'
).
content
,
'Add LICENCE'
,
'master'
,
false
)
expect
(
repository
.
license_blob
.
name
).
to
eq
(
'LICENCE'
)
end
it
'favors LICENSE to COPYING'
do
repository
.
commit_file
(
user
,
'LICENSE'
,
Licensee
::
License
.
new
(
'mit'
).
content
,
'Add LICENSE'
,
'master'
,
false
)
repository
.
commit_file
(
user
,
'COPYING'
,
Licensee
::
License
.
new
(
'mit'
).
content
,
'Add COPYING'
,
'master'
,
false
)
it
'detects license file with no recognizable open-source license content'
do
repository
.
commit_file
(
user
,
'LICENSE'
,
'Copyright!'
,
'Add LICENSE'
,
'master'
,
false
)
expect
(
repository
.
license_blob
.
name
).
to
eq
(
'LICENSE'
)
end
it
'favors LICENCE to COPYING'
do
repository
.
commit_file
(
user
,
'LICENCE'
,
Licensee
::
License
.
new
(
'mit'
).
content
,
'Add LICENCE'
,
'master'
,
false
)
repository
.
commit_file
(
user
,
'COPYING'
,
Licensee
::
License
.
new
(
'mit'
).
content
,
'Add COPYING'
,
'master'
,
false
)
%w[LICENSE LICENCE LiCensE LICENSE.md LICENSE.foo COPYING COPYING.md]
.
each
do
|
filename
|
it
"detects '
#{
filename
}
'"
do
repository
.
commit_file
(
user
,
filename
,
Licensee
::
License
.
new
(
'mit'
).
content
,
"Add
#{
filename
}
"
,
'master'
,
false
)
expect
(
repository
.
license_blob
.
name
).
to
eq
(
'LICENCE'
)
expect
(
repository
.
license_blob
.
name
).
to
eq
(
filename
)
end
end
end
...
...
@@ -190,8 +168,14 @@ describe Repository, models: true do
repository
.
remove_file
(
user
,
'LICENSE'
,
'Remove LICENSE'
,
'master'
)
end
it
'returns "no-license" when no license is detected'
do
expect
(
repository
.
license_key
).
to
eq
(
'no-license'
)
it
'returns nil when no license is detected'
do
expect
(
repository
.
license_key
).
to
be_nil
end
it
'detects license file with no recognizable open-source license content'
do
repository
.
commit_file
(
user
,
'LICENSE'
,
'Copyright!'
,
'Add LICENSE'
,
'master'
,
false
)
expect
(
repository
.
license_key
).
to
be_nil
end
it
'returns the license key'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录