Commit baf217e8 authored by Igor Drozdov's avatar Igor Drozdov

Look for code nav data in the latest commits

If the data doesn't exist for the requested commit, the data
from the latest commits may work as well
parent 745293e9
......@@ -6,6 +6,7 @@ module Gitlab
include Gitlab::Routing
CODE_NAVIGATION_JOB_NAME = 'code_navigation'
LATEST_COMMITS_LIMIT = 10
def initialize(project, commit_sha)
@project = project
......@@ -25,8 +26,11 @@ module Gitlab
def build
strong_memoize(:build) do
latest_commits_shas =
project.repository.commits(commit_sha, limit: LATEST_COMMITS_LIMIT).map(&:sha)
artifact = ::Ci::JobArtifact
.for_sha(commit_sha, project.id)
.for_sha(latest_commits_shas, project.id)
.for_job_name(CODE_NAVIGATION_JOB_NAME)
.last
......
......@@ -4,26 +4,38 @@ require 'spec_helper'
describe Gitlab::CodeNavigationPath do
context 'when there is an artifact with code navigation data' do
let(:project) { create(:project, :repository) }
let(:sha) { project.commit.id }
let(:build_name) { Gitlab::CodeNavigationPath::CODE_NAVIGATION_JOB_NAME }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:sha) { project.repository.commits('master', limit: 5).last.id }
let_it_be(:build_name) { Gitlab::CodeNavigationPath::CODE_NAVIGATION_JOB_NAME }
let_it_be(:pipeline) { create(:ci_pipeline, project: project, sha: sha) }
let_it_be(:job) { create(:ci_build, pipeline: pipeline, name: build_name) }
let_it_be(:artifact) { create(:ci_job_artifact, :lsif, job: job) }
let(:commit_sha) { sha }
let(:path) { 'lib/app.rb' }
let!(:pipeline) { create(:ci_pipeline, project: project, sha: sha) }
let!(:job) { create(:ci_build, pipeline: pipeline, name: build_name) }
let!(:artifact) { create(:ci_job_artifact, :lsif, job: job) }
subject { described_class.new(project, sha).full_json_path_for(path) }
subject { described_class.new(project, commit_sha).full_json_path_for(path) }
it 'assigns code_navigation_build variable' do
context 'when a pipeline exist for a sha' do
it 'returns path to a file in the artifact' do
expect(subject).to eq("/#{project.full_path}/-/jobs/#{job.id}/artifacts/raw/lsif/#{path}.json")
end
end
context 'when a pipeline exist for the latest commits' do
let(:commit_sha) { project.commit.id }
it 'returns path to a file in the artifact' do
expect(subject).to eq("/#{project.full_path}/-/jobs/#{job.id}/artifacts/raw/lsif/#{path}.json")
end
end
context 'when code_navigation feature is disabled' do
before do
stub_feature_flags(code_navigation: false)
end
it 'does not assign code_navigation_build variable' do
it 'returns nil' do
expect(subject).to be_nil
end
end
......
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