diff options
author | Zeger-Jan van de Weg <mail@zjvandeweg.nl> | 2015-11-12 17:00:39 +0100 |
---|---|---|
committer | Zeger-Jan van de Weg <mail@zjvandeweg.nl> | 2015-12-10 16:26:25 +0100 |
commit | 5fd280f3d3264aec3656cb61cd8728f2ca4d61ce (patch) | |
tree | 34bc63a8a9692c1331f8c8c81aa274bc03450b33 /app | |
parent | a3f64b53ecb0b40c94eb0fe32b662239fff6961f (diff) | |
download | gitlab-ce-5fd280f3d3264aec3656cb61cd8728f2ca4d61ce.tar.gz |
Licence also accepted as license file
Diffstat (limited to 'app')
-rw-r--r-- | app/models/repository.rb | 22 |
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 |