Commit 151f9e40 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'add-project-level-config-for-merge-train' into 'master'

Add project level config for merge train

See merge request gitlab-org/gitlab-ee!11065
parents ea5a6622 7e461df6
......@@ -16,3 +16,5 @@ class ProjectCiCdSetting < ApplicationRecord
super
end
end
ProjectCiCdSetting.prepend(EE::ProjectCiCdSetting)
# frozen_string_literal: true
class AddMergeTrainEnabledToCiCdSettings < ActiveRecord::Migration[5.1]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_column_with_default :project_ci_cd_settings, :merge_trains_enabled, :boolean, default: false, allow_null: false
end
def down
remove_column :project_ci_cd_settings, :merge_trains_enabled
end
end
......@@ -2315,6 +2315,7 @@ ActiveRecord::Schema.define(version: 20190426180107) do
t.integer "project_id", null: false
t.boolean "group_runners_enabled", default: true, null: false
t.boolean "merge_pipelines_enabled"
t.boolean "merge_trains_enabled", default: false, null: false
t.index ["project_id"], name: "index_project_ci_cd_settings_on_project_id", unique: true, using: :btree
end
......
......@@ -50,6 +50,8 @@ module EE
attrs << %i[merge_pipelines_enabled]
end
attrs << %i[merge_trains_enabled] if allow_merge_trains_params?
if allow_mirror_params?
attrs + mirror_params
else
......@@ -76,5 +78,9 @@ module EE
def allow_merge_pipelines_params?
project&.feature_available?(:merge_pipelines)
end
def allow_merge_trains_params?
project&.feature_available?(:merge_trains)
end
end
end
......@@ -121,6 +121,12 @@ module EE
@project.feature_available?(:merge_pipelines)
end
def merge_trains_available?
return false unless @project.builds_enabled?
@project.feature_available?(:merge_trains)
end
def size_limit_message(project)
show_lfs = project.lfs_enabled? ? 'including files in LFS' : ''
......
......@@ -107,6 +107,7 @@ module EE
delegate :log_jira_dvcs_integration_usage, :jira_dvcs_server_last_sync_at, :jira_dvcs_cloud_last_sync_at, to: :feature_usage
delegate :merge_pipelines_enabled, :merge_pipelines_enabled=, :merge_pipelines_enabled?, to: :ci_cd_settings
delegate :merge_trains_enabled, :merge_trains_enabled=, :merge_trains_enabled?, to: :ci_cd_settings
validates :repository_size_limit,
numericality: { only_integer: true, greater_than_or_equal_to: 0, allow_nil: true }
......@@ -524,10 +525,6 @@ 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.
......
# frozen_string_literal: true
module EE
module ProjectCiCdSetting
extend ActiveSupport::Concern
def merge_pipelines_enabled?
project.feature_available?(:merge_pipelines) && super
end
def merge_trains_enabled?
merge_pipelines_enabled? && project.feature_available?(:merge_trains) && super
end
end
end
......@@ -76,6 +76,7 @@ class License < ApplicationRecord
batch_comments
issues_analytics
merge_pipelines
merge_trains
design_management
operations_dashboard
dependency_proxy
......
......@@ -127,6 +127,10 @@ module EE
merge_request.target_project.merge_pipelines_enabled?
end
expose :merge_trains_enabled?, as: :merge_trains_enabled do |merge_request|
merge_request.target_project.merge_trains_enabled?
end
expose :can_push_to_source_branch do |merge_request|
presenter(merge_request).can_push_to_source_branch?
end
......
---
title: Add project level config for merge train
merge_request: 11065
author:
type: added
......@@ -224,6 +224,48 @@ describe ProjectsController do
end
end
context 'when merge_trains_enabled param is specified' do
let(:params) { { merge_trains_enabled: true } }
let(:request) do
put :update, params: { namespace_id: project.namespace, id: project, project: params }
end
before do
stub_licensed_features(merge_trains: true)
end
it 'updates the attribute' do
request
expect(project.reload.merge_trains_enabled).to be_truthy
end
context 'when feature flag is disabled' do
before do
stub_feature_flags(merge_trains: false)
end
it 'does not update the attribute' do
request
expect(project.reload.merge_trains_enabled).to be_falsy
end
end
context 'when license is not sufficient' do
before do
stub_licensed_features(merge_trains: false)
end
it 'does not update the attribute' do
request
expect(project.reload.merge_trains_enabled).to be_falsy
end
end
end
context 'repository mirrors' do
let(:params) do
{
......
# frozen_string_literal: true
require 'spec_helper'
describe ProjectCiCdSetting do
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 '#merge_trains_enabled?' do
subject { project.merge_trains_enabled? }
let(:project) { create(:project) }
let(:merge_trains_enabled) { true }
before do
project.merge_trains_enabled = merge_trains_enabled
end
context 'when Merge trains (EEP) is available' do
before do
stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.merge_pipelines_enabled = true
end
it { is_expected.to be_truthy }
context 'when project setting is disabled' do
let(:merge_trains_enabled) { false }
it { is_expected.to be_falsy }
end
end
context 'when Merge trains (EEP) is unavailable' do
before do
stub_licensed_features(merge_trains: false)
end
it { is_expected.to be_falsy }
context 'when project setting is disabled' do
let(:merge_trains_enabled) { false }
it { is_expected.to be_falsy }
end
end
end
end
......@@ -1745,45 +1745,6 @@ 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) }
......
......@@ -190,4 +190,8 @@ describe MergeRequestWidgetEntity do
expect(subject.as_json).to include(:pipeline_id)
end
it 'has merge trains flag' do
expect(subject.as_json).to include(:merge_trains_enabled)
end
end
......@@ -2123,7 +2123,7 @@ describe MergeRequest do
end
context 'when merges are not restricted to green builds' do
subject { build(:merge_request, target_project: build(:project, only_allow_merge_if_pipeline_succeeds: false)) }
subject { build(:merge_request, target_project: create(:project, only_allow_merge_if_pipeline_succeeds: false)) }
context 'and a failed pipeline is associated' do
before do
......
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