Commit caa2e239 authored by Filipa Lacerda's avatar Filipa Lacerda

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

Add project level config for merge pipelines

See merge request gitlab-org/gitlab-ee!9572
parents 7dae2c96 1787e969
......@@ -9,6 +9,7 @@
%span.descr
Pipelines need to be configured to enable this feature.
= link_to icon('question-circle'), help_page_path('user/project/merge_requests/merge_when_pipeline_succeeds', anchor: 'only-allow-merge-requests-to-be-merged-if-the-pipeline-succeeds'), target: '_blank'
= render_if_exists 'projects/merge_pipelines_settings', form: form
.form-check
= form.check_box :only_allow_merge_if_all_discussions_are_resolved, class: 'form-check-input'
= form.label :only_allow_merge_if_all_discussions_are_resolved, class: 'form-check-label' do
......
---
title: Add project level config for merge pipelines
merge_request: 25385
author:
type: added
# frozen_string_literal: true
class AddMergePipelinesEnabledToCiCdSettings < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :project_ci_cd_settings, :merge_pipelines_enabled, :boolean
end
end
......@@ -2203,6 +2203,7 @@ ActiveRecord::Schema.define(version: 20190220150130) do
create_table "project_ci_cd_settings", force: :cascade do |t|
t.integer "project_id", null: false
t.boolean "group_runners_enabled", default: true, null: false
t.boolean "merge_pipelines_enabled"
t.index ["project_id"], name: "index_project_ci_cd_settings_on_project_id", unique: true, using: :btree
end
......
......@@ -45,6 +45,10 @@ module EE
group_with_project_templates_id
]
if allow_merge_pipelines_params?
attrs << %i[merge_pipelines_enabled]
end
if allow_mirror_params?
attrs + mirror_params
else
......@@ -67,5 +71,9 @@ module EE
::Gitlab::CurrentSettings.current_application_settings.mirror_available || current_user&.admin?
end
end
def allow_merge_pipelines_params?
project&.feature_available?(:merge_pipelines)
end
end
end
......@@ -118,6 +118,12 @@ module EE
::License.feature_available?(:ci_cd_projects) && import_sources_enabled?
end
def merge_pipelines_available?
return false unless @project.builds_enabled?
@project.feature_available?(:merge_pipelines)
end
def size_limit_message(project)
show_lfs = project.lfs_enabled? ? 'including files in LFS' : ''
......
......@@ -104,6 +104,8 @@ 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
validates :repository_size_limit,
numericality: { only_integer: true, greater_than_or_equal_to: 0, allow_nil: true }
......
......@@ -74,6 +74,7 @@ class License < ActiveRecord::Base
feature_flags
batch_comments
issues_analytics
merge_pipelines
].freeze
EEU_FEATURES = EEP_FEATURES + %i[
......
- return unless merge_pipelines_available?
.form-check.builds-feature
= form.check_box :merge_pipelines_enabled, class: 'form-check-input'
= form.label :merge_pipelines_enabled, class: 'form-check-label' do
%strong
= _('Merge pipelines will try to validate the post-merge result prior to merging')
%br
%span.descr
= _('Pipelines need to be configured to enable this feature.')
= link_to icon('question-circle'), help_page_path('user/project/merge_requests/merge_when_pipeline_succeeds', anchor: 'only-allow-merge-requests-to-be-merged-if-the-pipeline-succeeds'), target: '_blank'
......@@ -184,6 +184,48 @@ describe ProjectsController do
expect(project.service_desk_enabled).to eq(true)
end
context 'when merge_pipelines_enabled param is specified' do
let(:params) { { merge_pipelines_enabled: true } }
let(:request) do
put :update, params: { namespace_id: project.namespace, id: project, project: params }
end
before do
stub_licensed_features(merge_pipelines: true)
end
it 'updates the attribute' do
request
expect(project.reload.merge_pipelines_enabled).to be_truthy
end
context 'when feature flag is disabled' do
before do
stub_feature_flags(merge_pipelines: false)
end
it 'does not update the attribute' do
request
expect(project.reload.merge_pipelines_enabled).to be_falsy
end
end
context 'when lisence is not sufficient' do
before do
stub_licensed_features(merge_pipelines: false)
end
it 'does not update the attribute' do
request
expect(project.reload.merge_pipelines_enabled).to be_falsy
end
end
end
context 'repository mirrors' do
let(:params) do
{
......
# frozen_string_literal: true
require 'spec_helper'
describe 'User manages merge pipelines option', :js do
let(:project) { create(:project) }
let(:user) { create(:user) }
before do
stub_licensed_features(merge_pipelines: true)
project.add_maintainer(user)
sign_in(user)
end
it 'sees unchecked merge pipeline checkbox' do
visit edit_project_path(project)
expect(page.find('#project_merge_pipelines_enabled')).not_to be_checked
end
context 'when user enabled the checkbox' do
before do
visit edit_project_path(project)
check('Merge pipelines will try to validate the post-merge result prior to merging')
end
it 'sees enabled merge pipeline checkbox' do
expect(page.find('#project_merge_pipelines_enabled')).to be_checked
end
end
context 'when license is insufficient' do
before do
stub_licensed_features(merge_pipelines: false)
end
it 'does not see the checkbox' do
expect(page).not_to have_css('#project_merge_pipelines_enabled')
end
end
context 'when feature flag is disabled' do
before do
stub_feature_flags(merge_pipelines: false)
end
it 'does not see the checkbox' do
expect(page).not_to have_css('#project_merge_pipelines_enabled')
end
end
end
......@@ -6069,6 +6069,9 @@ msgstr ""
msgid "Merge in progress"
msgstr ""
msgid "Merge pipelines will try to validate the post-merge result prior to merging"
msgstr ""
msgid "Merge request"
msgstr ""
......@@ -7078,6 +7081,9 @@ msgstr ""
msgid "Pipelines for last year"
msgstr ""
msgid "Pipelines need to be configured to enable this feature."
msgstr ""
msgid "Pipelines|Build with confidence"
msgstr ""
......
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