diff options
| author | Rémy Coutable <remy@rymai.me> | 2016-04-11 15:49:25 +0200 |
|---|---|---|
| committer | Rémy Coutable <remy@rymai.me> | 2016-04-18 14:47:50 +0200 |
| commit | 13804aba867d19009ca94d820aa7ec650a509f5a (patch) | |
| tree | 64c0d9415d81bb3104ba84af3834115f3a8cc5e1 /app/models | |
| parent | 073c3d15c71a0f877b62c7d3d7417a9721da1dba (diff) | |
| download | gitlab-ce-13804aba867d19009ca94d820aa7ec650a509f5a.tar.gz | |
Continue implementation of the license template selector and /licenses API endpoint
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/repository.rb | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 589756f8531..5d6fe017b5e 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 @@ -925,4 +920,8 @@ class Repository def cache @cache ||= RepositoryCache.new(path_with_namespace) end + + def licensee_project + @licensee_project ||= Licensee.project(path) + end end |
