summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-04-22 15:03:54 +0200
committerRémy Coutable <remy@rymai.me>2016-04-25 10:31:28 +0200
commitb8c4a65da7d6551f7c916426ec911fe7199b04cc (patch)
treefc38ebb757b742d33039f4ea3ef14a1e254812d9 /app
parent2eee6a0cbc02c80eb0750a7ca77ee31c4cf0884f (diff)
downloadgitlab-ce-b8c4a65da7d6551f7c916426ec911fe7199b04cc.tar.gz
Fix license detection to detect all license files, not only known licenses
Fixes #15470. Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app')
-rw-r--r--app/helpers/projects_helper.rb20
-rw-r--r--app/models/repository.rb10
2 files changed, 15 insertions, 15 deletions
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index ab85694da3f..3d5e61d2c18 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -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(
diff --git a/app/models/repository.rb b/app/models/repository.rb
index da751591103..61c8dce6060 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -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