summaryrefslogtreecommitdiff
path: root/lib/gitlab/code_navigation_path.rb
blob: 8dd2e9cb1bb5e4262990fc17b9af728ce9fe2b9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

module Gitlab
  class CodeNavigationPath
    include Gitlab::Utils::StrongMemoize
    include Gitlab::Routing

    CODE_NAVIGATION_JOB_NAME = 'code_navigation'

    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

      raw_project_job_artifacts_path(project, build, path: "lsif/#{path}.json")
    end

    private

    attr_reader :project, :commit_sha

    def build
      strong_memoize(:build) do
        artifact = ::Ci::JobArtifact
          .for_sha(commit_sha, project.id)
          .for_job_name(CODE_NAVIGATION_JOB_NAME)
          .last

        artifact&.job
      end
    end
  end
end