Base pipeline must be from target branch

This commit is contained in:
Olivier Gonzalez 2019-02-15 10:47:13 +00:00 committed by Grzegorz Bizon
parent ecb1411fbb
commit b079a6b6bb
3 changed files with 8 additions and 2 deletions

View File

@ -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?

View File

@ -0,0 +1,5 @@
---
title: Ensure the base pipeline of a Merge Request belongs to its target branch
merge_request: 25226
author:
type: fixed

View File

@ -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