2020-02-10 10:08:54 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2020-04-27 14:09:41 -04:00
|
|
|
class LsifData < Grape::API::Instance
|
2020-02-10 10:08:54 -05:00
|
|
|
MAX_FILE_SIZE = 10.megabytes
|
|
|
|
|
|
|
|
before do
|
|
|
|
not_found! if Feature.disabled?(:code_navigation, user_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
requires :commit_id, type: String, desc: 'The ID of a commit'
|
|
|
|
end
|
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
|
|
|
segment ':id/commits/:commit_id' do
|
|
|
|
params do
|
2020-03-02 16:08:01 -05:00
|
|
|
requires :paths, type: Array, desc: 'The paths of the files'
|
2020-02-10 10:08:54 -05:00
|
|
|
end
|
|
|
|
get 'lsif/info' do
|
|
|
|
authorize! :download_code, user_project
|
|
|
|
|
|
|
|
artifact =
|
2020-02-23 22:09:05 -05:00
|
|
|
Ci::JobArtifact
|
2020-02-10 10:08:54 -05:00
|
|
|
.with_file_types(['lsif'])
|
2020-02-23 22:09:05 -05:00
|
|
|
.for_sha(params[:commit_id], @project.id)
|
2020-02-10 10:08:54 -05:00
|
|
|
.last
|
|
|
|
|
|
|
|
not_found! unless artifact
|
|
|
|
authorize! :read_pipeline, artifact.job.pipeline
|
|
|
|
file_too_large! if artifact.file.cached_size > MAX_FILE_SIZE
|
|
|
|
|
2020-03-02 16:08:01 -05:00
|
|
|
service = ::Projects::LsifDataService.new(artifact.file, @project, params[:commit_id])
|
|
|
|
|
|
|
|
params[:paths].to_h { |path| [path, service.execute(path)] }
|
2020-02-10 10:08:54 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|