Commit 2b4e544f authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'expose-mr-pipeline-parameters-for-merge-widget' into 'master'

Expose merge request pipeline parameters for MR widget

See merge request gitlab-org/gitlab-ee!10502
parents 0e842644 e8959ec7
......@@ -206,10 +206,6 @@ module Ci
triggered_by_merge_request(merge_request).for_source_sha(source_sha)
end
scope :mergeable_merge_request_pipelines, -> (merge_request) do
triggered_by_merge_request(merge_request).where(target_sha: merge_request.target_branch_sha)
end
scope :triggered_for_branch, -> (ref) do
where(source: branch_pipeline_sources).where(ref: ref, tag: false)
end
......@@ -746,10 +742,6 @@ module Ci
triggered_by_merge_request? && target_sha.present?
end
def mergeable_merge_request_pipeline?
triggered_by_merge_request? && target_sha == merge_request.target_branch_sha
end
def merge_request_ref?
MergeRequest.merge_request_ref?(ref)
end
......
......@@ -22,6 +22,7 @@ class MergeRequestWidgetEntity < IssuableEntity
end
expose :squash
expose :target_branch
expose :target_branch_sha
expose :target_project_id
expose :target_project_full_path do |merge_request|
merge_request.project&.full_path
......
......@@ -59,6 +59,8 @@ class PipelineEntity < Grape::Entity
end
expose :commit, using: CommitEntity
expose :source_sha, if: -> (pipeline, _) { pipeline.merge_request_pipeline? }
expose :target_sha, if: -> (pipeline, _) { pipeline.merge_request_pipeline? }
expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? }
expose :failure_reason, if: -> (pipeline, _) { pipeline.failure_reason? } do |pipeline|
......
......@@ -531,6 +531,10 @@ module EE
feature_available?(:protected_environments)
end
def merge_pipelines_enabled?
feature_available?(:merge_pipelines) && super
end
# Because we use default_value_for we need to be sure
# packages_enabled= method does exist even if we rollback migration.
# Otherwise many tests from spec/migrations will fail.
......
......@@ -119,6 +119,10 @@ module EE
expose :rebase_commit_sha
expose :rebase_in_progress?, as: :rebase_in_progress
expose :merge_pipelines_enabled?, as: :merge_pipelines_enabled do |merge_request|
merge_request.target_project.merge_pipelines_enabled?
end
expose :can_push_to_source_branch do |merge_request|
presenter(merge_request).can_push_to_source_branch?
end
......
---
title: Expose merge request pipeline parameters for MR widget
merge_request: 10502
author:
type: added
......@@ -1735,6 +1735,45 @@ describe Project do
end
end
describe '#merge_pipelines_enabled?' do
subject { project.merge_pipelines_enabled? }
let(:project) { create(:project) }
let(:merge_pipelines_enabled) { true }
before do
project.merge_pipelines_enabled = merge_pipelines_enabled
end
context 'when Merge pipelines (EEP) is available' do
before do
stub_licensed_features(merge_pipelines: true)
end
it { is_expected.to be_truthy }
context 'when project setting is disabled' do
let(:merge_pipelines_enabled) { false }
it { is_expected.to be_falsy }
end
end
context 'when Merge pipelines (EEP) is unavailable' do
before do
stub_licensed_features(merge_pipelines: false)
end
it { is_expected.to be_falsy }
context 'when project setting is disabled' do
let(:merge_pipelines_enabled) { false }
it { is_expected.to be_falsy }
end
end
end
describe "#insights_config" do
context 'when project has no Insights config file' do
let(:project) { create(:project) }
......
......@@ -326,48 +326,6 @@ describe Ci::Pipeline, :mailer do
end
end
describe '.mergeable_merge_request_pipelines' do
subject { described_class.mergeable_merge_request_pipelines(merge_request) }
let!(:pipeline) do
create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, target_sha: target_sha)
end
let(:merge_request) { create(:merge_request) }
let(:target_sha) { merge_request.target_branch_sha }
it 'returns mergeable merge pipelines' do
is_expected.to eq([pipeline])
end
context 'when target sha does not point the head of the target branch' do
let(:target_sha) { merge_request.diff_head_sha }
it 'returns empty array' do
is_expected.to be_empty
end
end
end
describe '#mergeable_merge_request_pipeline?' do
subject { pipeline.mergeable_merge_request_pipeline? }
let!(:pipeline) do
create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, target_sha: target_sha)
end
let(:merge_request) { create(:merge_request) }
let(:target_sha) { merge_request.target_branch_sha }
it { is_expected.to be_truthy }
context 'when target sha does not point the head of the target branch' do
let(:target_sha) { merge_request.diff_head_sha }
it { is_expected.to be_falsy }
end
end
describe '#merge_request_ref?' do
subject { pipeline.merge_request_ref? }
......
......@@ -13,6 +13,10 @@ describe MergeRequestWidgetEntity do
described_class.new(resource, request: request).as_json
end
it 'has the latest sha of the target branch' do
is_expected.to include(:target_branch_sha)
end
describe 'source_project_full_path' do
it 'includes the full path of the source project' do
expect(subject[:source_project_full_path]).to be_present
......
......@@ -143,6 +143,11 @@ describe PipelineEntity do
expect(subject[:flags][:detached_merge_request_pipeline]).to be_truthy
end
it 'does not expose source sha and target sha' do
expect(subject[:source_sha]).to be_nil
expect(subject[:target_sha]).to be_nil
end
context 'when user is a developer' do
before do
project.add_developer(user)
......@@ -189,6 +194,11 @@ describe PipelineEntity do
it 'makes atached flag true' do
expect(subject[:flags][:merge_request_pipeline]).to be_truthy
end
it 'exposes source sha and target sha' do
expect(subject[:source_sha]).to be_present
expect(subject[:target_sha]).to be_present
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