Commit 6d52088d authored by Nathan Friend's avatar Nathan Friend

Add "Allow merge trains" setting

This commit adds the "Allow merge trains" options to the project merge
request settings page.  This option is only visible in EE.  This option
is also hidden behind the "merge_trains" feature flag.
parent 14114791
......@@ -7,6 +7,7 @@ import groupsSelect from '~/groups_select';
import ApproversSelect from 'ee/approvers_select';
import mountApprovals from 'ee/approvals/mount_project_settings';
import initServiceDesk from 'ee/projects/settings_service_desk';
import initMergeOptionsCheckboxSync from './init_merge_options_checkbox_sync';
document.addEventListener('DOMContentLoaded', () => {
new UsersSelect();
......@@ -17,4 +18,6 @@ document.addEventListener('DOMContentLoaded', () => {
new ApproversSelect();
initServiceDesk();
mountApprovals(document.getElementById('js-mr-approvals-settings'));
initMergeOptionsCheckboxSync();
});
export default () => {
const mergePipelinesCheckbox = document.querySelector('.js-merge-options-merge-pipelines');
const mergeTrainsCheckbox = document.querySelector('.js-merge-options-merge-trains');
if (mergePipelinesCheckbox && mergeTrainsCheckbox) {
mergePipelinesCheckbox.addEventListener('change', event => {
if (!event.target.checked && mergeTrainsCheckbox.checked) {
mergeTrainsCheckbox.click();
}
});
mergeTrainsCheckbox.addEventListener('change', event => {
if (event.target.checked && !mergePipelinesCheckbox.checked) {
mergePipelinesCheckbox.click();
}
});
}
};
- return unless merge_pipelines_available?
.form-check.builds-feature
= form.check_box :merge_pipelines_enabled, class: 'form-check-input'
= form.check_box :merge_pipelines_enabled, class: 'form-check-input js-merge-options-merge-pipelines'
= form.label :merge_pipelines_enabled, class: 'form-check-label' do
= s_('ProjectSettings|Merge pipelines will try to validate the post-merge result prior to merging')
.descr.text-secondary.mb-2
......@@ -10,3 +10,8 @@
help_page_path('ci/merge_request_pipelines/index.md',
anchor: 'pipelines-for-merge-requests'),
target: '_blank'
- if merge_trains_available?
.form-check.mb-2
= form.check_box :merge_trains_enabled, class: 'form-check-input js-merge-options-merge-trains'
= form.label :merge_trains_enabled, class: 'form-check-label' do
= s_('ProjectSettings|Allow merge trains')
---
title: Add "Allow merge trains" option to project settings page
merge_request: 10803
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
describe 'Project settings > [EE] Merge Requests', :js do
......@@ -109,4 +110,79 @@ describe 'Project settings > [EE] Merge Requests', :js do
expect(page).to have_selector('#project_merge_requests_template')
end
end
shared_examples 'the merge train feature is not available' do
it 'does not render the merge trains checkbox' do
visit edit_project_path(project)
expect(page).not_to have_selector('#project_merge_trains_enabled')
end
end
context 'when merge_pipelines and merge_trains are disabled' do
before do
stub_licensed_features(merge_pipelines: false, merge_trains: false)
end
it_behaves_like 'the merge train feature is not available'
end
context 'when merge_pipelines is disabled and merge_trains is enabled' do
before do
stub_licensed_features(merge_pipelines: false, merge_trains: true)
end
it_behaves_like 'the merge train feature is not available'
end
context 'when merge_trains is disabled and merge_pipelines is enabled' do
before do
stub_licensed_features(merge_pipelines: true, merge_trains: false)
end
it_behaves_like 'the merge train feature is not available'
end
context 'when merge_pipelines and merge_trains are enabled' do
before do
stub_licensed_features(merge_pipelines: true, merge_trains: true)
end
context 'when both the merge pipelines and merge trains checkboxes are unchecked' do
before do
visit edit_project_path(project)
end
it 'automatically checks the merge pipelines checkbox when the merge trains checkbox is checked' do
expect(page.find('#project_merge_trains_enabled').checked?).to be false
expect(page.find('#project_merge_pipelines_enabled').checked?).to be false
check('project_merge_trains_enabled')
expect(page.find('#project_merge_trains_enabled').checked?).to be true
expect(page.find('#project_merge_pipelines_enabled').checked?).to be true
end
end
context 'when both the merge pipelines and merge trains checkboxes are checked' do
before do
project.update(merge_pipelines_enabled: true, merge_trains_enabled: true)
visit edit_project_path(project)
end
it 'automatically unchecks the merge trains checkbox when the merge pipelines checkbox is unchecked' do
expect(page.find('#project_merge_trains_enabled').checked?).to be true
expect(page.find('#project_merge_pipelines_enabled').checked?).to be true
uncheck('project_merge_pipelines_enabled')
expect(page.find('#project_merge_trains_enabled').checked?).to be false
expect(page.find('#project_merge_pipelines_enabled').checked?).to be false
end
end
end
end
......@@ -9828,6 +9828,9 @@ msgstr ""
msgid "ProjectSettings|All discussions must be resolved"
msgstr ""
msgid "ProjectSettings|Allow merge trains"
msgstr ""
msgid "ProjectSettings|Automatically resolve merge request diff discussions when they become outdated"
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