Commit 0b966fb0 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '57671-fix_merge_request_base_pipeline' into 'master'

Base pipeline must be from target branch

Closes #57671

See merge request gitlab-org/gitlab-ce!25226
parents ecb1411f b079a6b6
......@@ -1322,7 +1322,7 @@ class MergeRequest < ActiveRecord::Base
def base_pipeline
@base_pipeline ||= project.ci_pipelines
.order(id: :desc)
.find_by(sha: diff_base_sha)
.find_by(sha: diff_base_sha, ref: target_branch)
end
def discussions_rendered_on_frontend?
......
---
title: Ensure the base pipeline of a Merge Request belongs to its target branch
merge_request: 25226
author:
type: fixed
......@@ -2604,8 +2604,9 @@ describe MergeRequest do
let!(:first_pipeline) { create(:ci_pipeline_without_jobs, pipeline_arguments) }
let!(:last_pipeline) { create(:ci_pipeline_without_jobs, pipeline_arguments) }
let!(:last_pipeline_with_other_ref) { create(:ci_pipeline_without_jobs, pipeline_arguments.merge(ref: 'other')) }
it 'returns latest pipeline' do
it 'returns latest pipeline for the target branch' do
expect(merge_request.base_pipeline).to eq(last_pipeline)
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