BigW Consortium Gitlab

Commit 5fd280f3 by Zeger-Jan van de Weg

Licence also accepted as license file

parent a3f64b53
......@@ -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)
......
......@@ -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
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment