Licence also accepted as license file
This commit is contained in:
parent
a3f64b53ec
commit
5fd280f3d3
|
@ -32,7 +32,7 @@ v 8.2.0 (unreleased)
|
||||||
- Fix incoming email config defaults
|
- Fix incoming email config defaults
|
||||||
- MR target branch is now visible on a list view when it is different from project's default one
|
- MR target branch is now visible on a list view when it is different from project's default one
|
||||||
- Improve Continuous Integration graphs page
|
- 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
|
v 8.1.4
|
||||||
- Fix bug where manually merged branches in a MR would end up with an empty diff (Stan Hu)
|
- 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
|
def license
|
||||||
cache.fetch(:license) do
|
cache.fetch(:license) do
|
||||||
licenses = tree(:head).blobs.find_all do |file|
|
licenses = tree(:head).blobs.find_all do |file|
|
||||||
file.name =~ /\A(copying|license)/i
|
file.name =~ /\A(copying|license|licence)/i
|
||||||
end
|
end
|
||||||
|
|
||||||
# If `licence`, `copying` and `copying.lesser` are found, return in the
|
preferences = [
|
||||||
# following order: licence, copying, copying.lesser
|
/\Alicen[sc]e\z/i, # LICENSE, LICENCE
|
||||||
regex = [/\Alicense(\..*)?\z/i, /\Acopying(\..{0,3})?\z/i, /\Acopying.lesser/i]
|
/\Alicen[sc]e\./i, # LICENSE.md, LICENSE.txt
|
||||||
|
/\Acopying\z/i, # COPYING
|
||||||
|
/\Acopying\.(?!lesser)/i, # COPYING.txt
|
||||||
|
/Acopying.lesser/i # COPYING.LESSER
|
||||||
|
]
|
||||||
|
|
||||||
regex.map do |re|
|
license = nil
|
||||||
licenses.find { |l| l.name =~ re }
|
preferences.each do |r|
|
||||||
end.compact.first
|
license = licenses.find { |l| l.name =~ r }
|
||||||
|
break if license
|
||||||
|
end
|
||||||
|
|
||||||
|
license
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -102,13 +102,22 @@ describe Repository do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#license" do
|
describe "#license" do
|
||||||
it 'test selection preference' do
|
before do
|
||||||
repository.send(:cache).expire(:license)
|
repository.send(:cache).expire(:license)
|
||||||
TestBlob = Struct.new(:name)
|
TestBlob = Struct.new(:name)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'test selection preference' do
|
||||||
files = [TestBlob.new('file'), TestBlob.new('license'), TestBlob.new('copying')]
|
files = [TestBlob.new('file'), TestBlob.new('license'), TestBlob.new('copying')]
|
||||||
expect(repository.tree).to receive(:blobs).and_return(files)
|
expect(repository.tree).to receive(:blobs).and_return(files)
|
||||||
|
|
||||||
expect(repository.license.name).to eq('license')
|
expect(repository.license.name).to eq('license')
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue