Commit d7b3f6e8 authored by drew cimino's avatar drew cimino

Add #merge_base_pipeline to MergeRequest

Refers to the pipeline run on target_sha of actual_head_pipeline,
allowing us to compare the head_pipeline for the merged result of
an MR to the commit immediately prior to merging of new code.
parent a7248d86
......@@ -1599,6 +1599,12 @@ class MergeRequest < ApplicationRecord
.find_by(sha: diff_base_sha, ref: target_branch)
end
def merge_base_pipeline
@merge_target_pipeline ||= project.ci_pipelines
.order(id: :desc)
.find_by(sha: actual_head_pipeline.target_sha, ref: target_branch)
end
def discussions_rendered_on_frontend?
true
end
......
......@@ -3520,6 +3520,23 @@ RSpec.describe MergeRequest, factory_default: :keep do
end
end
describe '#merge_base_pipeline' do
let(:merge_request) do
create(:merge_request, :with_merge_request_pipeline)
end
let(:pre_merge_target_pipeline) do
create(:ci_pipeline, ref: merge_request.target_branch, sha: merge_request.target_branch_sha)
end
it 'returns a pipeline pointing to a commit on the target ref' do
pre_merge_target_pipeline
merge_request.update_head_pipeline
expect(merge_request.merge_base_pipeline).to eq(pre_merge_target_pipeline)
end
end
describe '#has_commits?' do
it 'returns true when merge request diff has commits' do
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