summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <mail@zjvandeweg.nl>2015-11-12 17:00:39 +0100
committerZeger-Jan van de Weg <mail@zjvandeweg.nl>2015-12-10 16:26:25 +0100
commit5fd280f3d3264aec3656cb61cd8728f2ca4d61ce (patch)
tree34bc63a8a9692c1331f8c8c81aa274bc03450b33
parenta3f64b53ecb0b40c94eb0fe32b662239fff6961f (diff)
downloadgitlab-ce-5fd280f3d3264aec3656cb61cd8728f2ca4d61ce.tar.gz
Licence also accepted as license file
-rw-r--r--CHANGELOG2
-rw-r--r--app/models/repository.rb22
-rw-r--r--spec/models/repository_spec.rb11
3 files changed, 26 insertions, 9 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 69a293d70d6..891004f2ffb 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -32,7 +32,7 @@ v 8.2.0 (unreleased)
- Fix incoming email config defaults
- MR target branch is now visible on a list view when it is different from project's default one
- Improve Continuous Integration graphs page
- - Accept COPYING as licence file (Zeger-Jan van de Weg)
+ - Accept COPYING,COPYING.lesser, and licence as license file (Zeger-Jan van de Weg)
v 8.1.4
- Fix bug where manually merged branches in a MR would end up with an empty diff (Stan Hu)
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
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 04437d64fee..49af0229bb5 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -102,13 +102,22 @@ describe Repository do
end
describe "#license" do
- it 'test selection preference' do
+ before do
repository.send(:cache).expire(:license)
TestBlob = Struct.new(:name)
+ end
+
+ it 'test selection preference' do
files = [TestBlob.new('file'), TestBlob.new('license'), TestBlob.new('copying')]
expect(repository.tree).to receive(:blobs).and_return(files)
expect(repository.license.name).to eq('license')
end
+
+ it 'also accepts licence instead of license' do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('licence')])
+
+ expect(repository.license.name).to eq('licence')
+ end
end
end