summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/repository.rb22
1 files changed, 15 insertions, 7 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 622d6303bfe..cc70aa2b737 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -244,16 +244,24 @@ class Repository
def license
cache.fetch(:license) do
licenses = tree(:head).blobs.find_all do |file|
- file.name =~ /\A(copying|license)/i
+ file.name =~ /\A(copying|license|licence)/i
end
- # If `licence`, `copying` and `copying.lesser` are found, return in the
- # following order: licence, copying, copying.lesser
- regex = [/\Alicense(\..*)?\z/i, /\Acopying(\..{0,3})?\z/i, /\Acopying.lesser/i]
+ 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
+ ]
+
+ license = nil
+ preferences.each do |r|
+ license = licenses.find { |l| l.name =~ r }
+ break if license
+ end
- regex.map do |re|
- licenses.find { |l| l.name =~ re }
- end.compact.first
+ license
end
end