Commit 5d3c1ceb authored by drew cimino's avatar drew cimino

Use feature flag to toggle between MR base pipelines

This merge request allows a single backend feature flag to toggle the
base pipeline used for comparing CodeQuality artifacts in merge
requests between the MR diff base and the merge base from the target
branch.
parent e8eeee34
......@@ -1600,7 +1600,7 @@ class MergeRequest < ApplicationRecord
end
def merge_base_pipeline
@merge_target_pipeline ||= project.ci_pipelines
@merge_base_pipeline ||= project.ci_pipelines
.order(id: :desc)
.find_by(sha: actual_head_pipeline.target_sha, ref: target_branch)
end
......
......@@ -120,11 +120,11 @@ class MergeRequestWidgetEntity < Grape::Entity
end
expose :base_path do |merge_request|
base_pipeline_downloadable_path_for_report_type(:codequality)
end
expose :merge_base_path do |merge_request|
merge_target_pipeline_downloadable_path_for_report_type(:codequality)
if use_merge_base_with_merged_results?
merge_base_pipeline_downloadable_path_for_report_type(:codequality)
else
base_pipeline_downloadable_path_for_report_type(:codequality)
end
end
end
......@@ -161,7 +161,12 @@ class MergeRequestWidgetEntity < Grape::Entity
&.downloadable_path_for_report_type(file_type)
end
def merge_target_pipeline_downloadable_path_for_report_type(file_type)
def use_merge_base_with_merged_results?
Feature.enabled?(:merge_base_pipelines, object.target_project) &&
object.actual_head_pipeline&.merge_request_event_type == :merged_result
end
def merge_base_pipeline_downloadable_path_for_report_type(file_type)
object.merge_base_pipeline&.present(current_user: current_user)
&.downloadable_path_for_report_type(file_type)
end
......
---
name: merge_base_pipelines
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/44648
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/263724
type: development
group: group::testing
default_enabled: false
......@@ -3525,15 +3525,17 @@ RSpec.describe MergeRequest, factory_default: :keep do
create(:merge_request, :with_merge_request_pipeline)
end
let(:pre_merge_target_pipeline) do
let(:merge_base_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
before do
merge_base_pipeline
merge_request.update_head_pipeline
end
expect(merge_request.merge_base_pipeline).to eq(pre_merge_target_pipeline)
it 'returns a pipeline pointing to a commit on the target ref' do
expect(merge_request.merge_base_pipeline).to eq(merge_base_pipeline)
end
end
......
......@@ -88,11 +88,13 @@ RSpec.describe MergeRequestWidgetEntity do
end
describe 'codequality report artifacts', :request_store do
let(:merge_base_pipeline) { create(:ci_pipeline, :with_codequality_report, project: project) }
before do
project.add_developer(user)
allow(resource).to receive_messages(
merge_base_pipeline: pipeline,
merge_base_pipeline: merge_base_pipeline,
base_pipeline: pipeline,
head_pipeline: pipeline
)
......@@ -101,10 +103,29 @@ RSpec.describe MergeRequestWidgetEntity do
context 'with report artifacts' do
let(:pipeline) { create(:ci_pipeline, :with_codequality_report, project: project) }
it 'has entries for 3 reference artifacts' do
expect(subject[:codeclimate][:merge_base_path]).to be_present
expect(subject[:codeclimate][:base_path]).to be_present
it 'has head_path and base_path entries' do
expect(subject[:codeclimate][:head_path]).to be_present
expect(subject[:codeclimate][:base_path]).to be_present
end
context 'on pipelines for merged results' do
let(:pipeline) { create(:ci_pipeline, :merged_result_pipeline, :with_codequality_report, project: project) }
context 'with merge_base_pipelines enabled' do
it 'returns URLs from the head_pipeline and merge_base_pipeline' do
expect(subject[:codeclimate][:head_path]).not_to eq(subject[:codeclimate][:base_path])
end
end
context 'with merge_base_pipelines disabled' do
before do
stub_feature_flags(merge_base_pipelines: false)
end
it 'returns URLs from the head_pipeline and base_pipeline' do
expect(subject[:codeclimate][:head_path]).to eq(subject[:codeclimate][:base_path])
end
end
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