Merge branch 'zj-licensee-key' into 'master'
Client implementation for Licensee#key See merge request gitlab-org/gitlab-ce!17449
This commit is contained in:
commit
52e133d176
|
@ -590,15 +590,7 @@ class Repository
|
|||
def license_key
|
||||
return unless exists?
|
||||
|
||||
# The licensee gem creates a Rugged object from the path:
|
||||
# https://github.com/benbalter/licensee/blob/v8.7.0/lib/licensee/projects/git_project.rb
|
||||
begin
|
||||
Licensee.license(path).try(:key)
|
||||
# Normally we would rescue Rugged::Error, but that is banned by lint-rugged
|
||||
# and we need to migrate this endpoint to Gitaly:
|
||||
# https://gitlab.com/gitlab-org/gitaly/issues/1026
|
||||
rescue
|
||||
end
|
||||
raw_repository.license_short_name
|
||||
end
|
||||
cache_method :license_key
|
||||
|
||||
|
|
|
@ -1038,6 +1038,21 @@ module Gitlab
|
|||
end
|
||||
end
|
||||
|
||||
def license_short_name
|
||||
gitaly_migrate(:license_short_name) do |is_enabled|
|
||||
if is_enabled
|
||||
gitaly_repository_client.license_short_name
|
||||
else
|
||||
begin
|
||||
# The licensee gem creates a Rugged object from the path:
|
||||
# https://github.com/benbalter/licensee/blob/v8.7.0/lib/licensee/projects/git_project.rb
|
||||
Licensee.license(path).try(:key)
|
||||
rescue Rugged::Error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def with_repo_branch_commit(start_repository, start_branch_name)
|
||||
Gitlab::Git.check_namespace!(start_repository)
|
||||
start_repository = RemoteRepository.new(start_repository) unless start_repository.is_a?(RemoteRepository)
|
||||
|
|
|
@ -249,6 +249,14 @@ module Gitlab
|
|||
|
||||
raise Gitlab::Git::OSError.new(response.error) unless response.error.empty?
|
||||
end
|
||||
|
||||
def license_short_name
|
||||
request = Gitaly::FindLicenseRequest.new(repository: @gitaly_repo)
|
||||
|
||||
response = GitalyClient.call(@storage, :repository_service, :find_license, request, timeout: GitalyClient.fast_timeout)
|
||||
|
||||
response.license_short_name.presence
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1689,6 +1689,35 @@ describe Gitlab::Git::Repository, seed_helper: true do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#license_short_name' do
|
||||
shared_examples 'acquiring the Licensee license key' do
|
||||
subject { repository.license_short_name }
|
||||
|
||||
context 'when no license file can be found' do
|
||||
let(:project) { create(:project, :repository) }
|
||||
let(:repository) { project.repository.raw_repository }
|
||||
|
||||
before do
|
||||
project.repository.delete_file(project.owner, 'LICENSE', message: 'remove license', branch_name: 'master')
|
||||
end
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'when an mit license is found' do
|
||||
it { is_expected.to eq('mit') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when gitaly is enabled' do
|
||||
it_behaves_like 'acquiring the Licensee license key'
|
||||
end
|
||||
|
||||
context 'when gitaly is disabled', :disable_gitaly do
|
||||
it_behaves_like 'acquiring the Licensee license key'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#with_repo_branch_commit' do
|
||||
context 'when comparing with the same repository' do
|
||||
let(:start_repository) { repository }
|
||||
|
|
Loading…
Reference in New Issue