Commit 652a78c0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch '5384_use_latest_base_pipeline_for_mr' into 'master'

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

Closes #5384

See merge request gitlab-org/gitlab-ee!5114
parents d5e8beb2 1cc3f5c3
...@@ -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