debian-mirror-gitlab/lib/gitlab/code_navigation_path.rb

42 lines
933 B
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
module Gitlab
class CodeNavigationPath
include Gitlab::Utils::StrongMemoize
include Gitlab::Routing
2020-05-24 23:13:21 +05:30
LATEST_COMMITS_LIMIT = 10
2020-04-22 19:07:51 +05:30
def initialize(project, commit_sha)
@project = project
@commit_sha = commit_sha
end
def full_json_path_for(path)
return if Feature.disabled?(:code_navigation, project)
return unless build
2020-05-24 23:13:21 +05:30
raw_project_job_artifacts_path(project, build, path: "lsif/#{path}.json", file_type: :lsif)
2020-04-22 19:07:51 +05:30
end
private
attr_reader :project, :commit_sha
def build
strong_memoize(:build) do
2020-05-24 23:13:21 +05:30
latest_commits_shas =
project.repository.commits(commit_sha, limit: LATEST_COMMITS_LIMIT).map(&:sha)
artifact =
::Ci::JobArtifact
.with_file_types(['lsif'])
.for_sha(latest_commits_shas, project.id)
.last
2020-04-22 19:07:51 +05:30
artifact&.job
end
end
end
end