summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-04-20 01:38:49 +0000
committerRobert Speicher <robert@gitlab.com>2016-04-20 01:38:49 +0000
commit3d4875f86a3b23789f5ea801c096754fced25166 (patch)
tree3d3c370437a606dcdf2498546f5efd1f13eb44b6 /app/models
parent9617c274ab301e4d2401b2d9a179f40649259d3c (diff)
parent50bee8e9198f65a692e32710a32089270e166f6b (diff)
downloadgitlab-ce-3d4875f86a3b23789f5ea801c096754fced25166.tar.gz
Merge branch 'license-templates-and-api-12804' into 'master'
License templates when creating/editing a LICENSE file Closes #12804 See merge request !3660
Diffstat (limited to 'app/models')
-rw-r--r--app/models/repository.rb37
1 files changed, 18 insertions, 19 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index c6d7a439c05..da751591103 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -228,7 +228,8 @@ class Repository
def cache_keys
%i(size branch_names tag_names commit_count
- readme version contribution_guide changelog license)
+ readme version contribution_guide changelog
+ license_blob license_key)
end
def build_cache
@@ -461,27 +462,21 @@ class Repository
end
end
- def license
- cache.fetch(:license) do
- licenses = tree(:head).blobs.find_all do |file|
- file.name =~ /\A(copying|license|licence)/i
- end
-
- preferences = [
- /\Alicen[sc]e\z/i, # LICENSE, LICENCE
- /\Alicen[sc]e\./i, # LICENSE.md, LICENSE.txt
- /\Acopying\z/i, # COPYING
- /\Acopying\.(?!lesser)/i, # COPYING.txt
- /Acopying.lesser/i # COPYING.LESSER
- ]
+ def license_blob
+ return nil if !exists? || empty?
- license = nil
- preferences.each do |r|
- license = licenses.find { |l| l.name =~ r }
- break if license
+ cache.fetch(:license_blob) do
+ if licensee_project.license
+ blob_at_branch(root_ref, licensee_project.matched_file.filename)
end
+ end
+ end
- license
+ def license_key
+ return nil if !exists? || empty?
+
+ cache.fetch(:license_key) do
+ licensee_project.license.try(:key) || 'no-license'
end
end
@@ -964,4 +959,8 @@ class Repository
def cache
@cache ||= RepositoryCache.new(path_with_namespace)
end
+
+ def licensee_project
+ @licensee_project ||= Licensee.project(path)
+ end
end