Commit 1cc3f5c3 authored by Olivier Gonzalez's avatar Olivier Gonzalez Committed by Dmitriy Zaporozhets

Make #base_pipeline returning the latest available pipeline for MR's base commit

parent d5e8beb2
...@@ -1107,7 +1107,9 @@ class MergeRequest < ActiveRecord::Base ...@@ -1107,7 +1107,9 @@ class MergeRequest < ActiveRecord::Base
end end
def base_pipeline def base_pipeline
@base_pipeline ||= project.pipelines.find_by(sha: merge_request_diff&.base_commit_sha) @base_pipeline ||= project.pipelines
.order(id: :desc)
.find_by(sha: diff_base_sha)
end end
def update_project_counter_caches def update_project_counter_caches
......
...@@ -2404,6 +2404,26 @@ describe MergeRequest do ...@@ -2404,6 +2404,26 @@ describe MergeRequest do
end end
end end
describe '#base_pipeline' do
let(:pipeline_arguments) do
{
project: project,
ref: merge_request.target_branch,
sha: merge_request.diff_base_sha
}
end
let(:project) { create(:project, :public, :repository) }
let(:merge_request) { create(:merge_request, source_project: project) }
let!(:first_pipeline) { create(:ci_pipeline_without_jobs, pipeline_arguments) }
let!(:last_pipeline) { create(:ci_pipeline_without_jobs, pipeline_arguments) }
it 'returns latest pipeline' do
expect(merge_request.base_pipeline).to eq(last_pipeline)
end
end
describe '#has_commits?' do describe '#has_commits?' do
before do before do
allow(subject.merge_request_diff).to receive(:commits_count) allow(subject.merge_request_diff).to receive(:commits_count)
......
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