Commit b079a6b6 authored by Olivier Gonzalez's avatar Olivier Gonzalez Committed by Grzegorz Bizon

Base pipeline must be from target branch

parent ecb1411f
......@@ -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