Commit cd7fb46f authored by Sean McGivern's avatar Sean McGivern
Browse files

Merge branch 'zj-licensee-key' into 'master'

Client implementation for Licensee#key

See merge request gitlab-org/gitlab-ce!17449
...@@ -590,15 +590,7 @@ def license_blob ...@@ -590,15 +590,7 @@ def license_blob
def license_key def license_key
return unless exists? return unless exists?
# The licensee gem creates a Rugged object from the path: raw_repository.license_short_name
# 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
end end
cache_method :license_key cache_method :license_key
......
...@@ -1038,6 +1038,21 @@ def languages(ref = nil) ...@@ -1038,6 +1038,21 @@ def languages(ref = nil)
end end
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) def with_repo_branch_commit(start_repository, start_branch_name)
Gitlab::Git.check_namespace!(start_repository) Gitlab::Git.check_namespace!(start_repository)
start_repository = RemoteRepository.new(start_repository) unless start_repository.is_a?(RemoteRepository) start_repository = RemoteRepository.new(start_repository) unless start_repository.is_a?(RemoteRepository)
......
...@@ -249,6 +249,14 @@ def write_config(full_path:) ...@@ -249,6 +249,14 @@ def write_config(full_path:)
raise Gitlab::Git::OSError.new(response.error) unless response.error.empty? raise Gitlab::Git::OSError.new(response.error) unless response.error.empty?
end 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 end
end end
...@@ -1689,6 +1689,35 @@ def commit_files(commit) ...@@ -1689,6 +1689,35 @@ def commit_files(commit)
end end
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 describe '#with_repo_branch_commit' do
context 'when comparing with the same repository' do context 'when comparing with the same repository' do
let(:start_repository) { repository } let(:start_repository) { repository }
......
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