Commit ac1d83c5 authored by Clement Ho's avatar Clement Ho

Merge branch '47156-improve-auto-devops-settings' into 'master'

Resolve "Improve Auto DevOps settings flow for admin and project"

Closes #47156

See merge request gitlab-org/gitlab-ce!20946
parents d737abc5 e3127132
...@@ -23,17 +23,12 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -23,17 +23,12 @@ document.addEventListener('DOMContentLoaded', () => {
saveEndpoint: variableListEl.dataset.saveEndpoint, saveEndpoint: variableListEl.dataset.saveEndpoint,
}); });
// hide extra auto devops settings based on data-attributes // hide extra auto devops settings based checkbox state
const autoDevOpsSettings = document.querySelector('.js-auto-devops-settings');
const autoDevOpsExtraSettings = document.querySelector('.js-extra-settings'); const autoDevOpsExtraSettings = document.querySelector('.js-extra-settings');
const instanceDefaultBadge = document.querySelector('.js-instance-default-badge');
autoDevOpsSettings.addEventListener('click', event => { document.querySelector('.js-toggle-extra-settings').addEventListener('click', event => {
const { target } = event; const { target } = event;
if (target.classList.contains('js-toggle-extra-settings')) { if (instanceDefaultBadge) instanceDefaultBadge.style.display = 'none';
autoDevOpsExtraSettings.classList.toggle( autoDevOpsExtraSettings.classList.toggle('hidden', !target.checked);
'hidden',
!!(target.dataset && target.dataset.hideExtraSettings),
);
}
}); });
}); });
...@@ -19,9 +19,4 @@ ...@@ -19,9 +19,4 @@
.auto-devops-card { .auto-devops-card {
margin-bottom: $gl-vert-padding; margin-bottom: $gl-vert-padding;
> .card-body {
border-radius: $card-border-radius;
padding: $gl-padding $gl-padding-24;
}
} }
...@@ -507,6 +507,10 @@ class Project < ActiveRecord::Base ...@@ -507,6 +507,10 @@ class Project < ActiveRecord::Base
end end
end end
def has_auto_devops_implicitly_enabled?
auto_devops&.enabled.nil? && Gitlab::CurrentSettings.auto_devops_enabled?
end
def has_auto_devops_implicitly_disabled? def has_auto_devops_implicitly_disabled?
auto_devops&.enabled.nil? && !Gitlab::CurrentSettings.auto_devops_enabled? auto_devops&.enabled.nil? && !Gitlab::CurrentSettings.auto_devops_enabled?
end end
......
...@@ -3,13 +3,15 @@ ...@@ -3,13 +3,15 @@
%fieldset %fieldset
.form-group .form-group
.form-check .card.auto-devops-card
= f.check_box :auto_devops_enabled, class: 'form-check-input' .card-body
= f.label :auto_devops_enabled, class: 'form-check-label' do .form-check
Enabled Auto DevOps for projects by default = f.check_box :auto_devops_enabled, class: 'form-check-input'
.form-text.text-muted = f.label :auto_devops_enabled, class: 'form-check-label' do
It will automatically build, test, and deploy applications based on a predefined CI/CD configuration Default to Auto DevOps pipeline for all projects
= link_to icon('question-circle'), help_page_path('topics/autodevops/index.md') .form-text.text-muted
= s_('CICD|The Auto DevOps pipeline will run if no alternative CI configuration file is found.')
= link_to _('More information'), help_page_path('topics/autodevops/index.md'), target: '_blank'
.form-group .form-group
= f.label :auto_devops_domain, class: 'label-bold' = f.label :auto_devops_domain, class: 'label-bold'
= f.text_field :auto_devops_domain, class: 'form-control', placeholder: 'domain.com' = f.text_field :auto_devops_domain, class: 'form-control', placeholder: 'domain.com'
......
...@@ -13,23 +13,15 @@ ...@@ -13,23 +13,15 @@
.card.auto-devops-card .card.auto-devops-card
.card-body .card-body
.form-check .form-check
= form.radio_button :enabled, 'true', class: 'form-check-input js-toggle-extra-settings' = form.check_box :enabled, class: 'form-check-input js-toggle-extra-settings', checked: @project.auto_devops_enabled?
= form.label :enabled_true, class: 'form-check-label' do = form.label :enabled, class: 'form-check-label' do
%strong= s_('CICD|Enable Auto DevOps') %strong= s_('CICD|Default to Auto DevOps pipeline')
- if @project.has_auto_devops_implicitly_enabled?
%span.badge.badge-info.js-instance-default-badge= s_('CICD|instance enabled')
.form-text.text-muted .form-text.text-muted
= s_('CICD|The Auto DevOps pipeline configuration will be used when there is no %{ci_file} in the project.').html_safe % { ci_file: ci_file_formatted } = s_('CICD|The Auto DevOps pipeline will run if no alternative CI configuration file is found.')
= link_to _('More information'), help_page_path('topics/autodevops/index.md'), target: '_blank'
.card.auto-devops-card .card-footer.js-extra-settings{ class: @project.auto_devops_enabled? || 'hidden' }
.card-body
.form-check
= form.radio_button :enabled, '', class: 'form-check-input js-toggle-extra-settings'
= form.label :enabled_, class: 'form-check-label' do
%strong= s_('CICD|Instance default (%{state})') % { state: "#{Gitlab::CurrentSettings.auto_devops_enabled? ? _('enabled') : _('disabled')}" }
.form-text.text-muted
= s_('CICD|Follow the instance default to either have Auto DevOps enabled or disabled when there is no project specific %{ci_file}.').html_safe % { ci_file: ci_file_formatted }
.card.auto-devops-card.js-extra-settings{ class: form.object&.enabled == false ? 'hidden' : nil }
.card-body.bg-light
= form.label :domain do = form.label :domain do
%strong= _('Domain') %strong= _('Domain')
= form.text_field :domain, class: 'form-control', placeholder: 'domain.com' = form.text_field :domain, class: 'form-control', placeholder: 'domain.com'
...@@ -46,21 +38,12 @@ ...@@ -46,21 +38,12 @@
.form-check .form-check
= form.radio_button :deploy_strategy, 'continuous', class: 'form-check-input' = form.radio_button :deploy_strategy, 'continuous', class: 'form-check-input'
= form.label :deploy_strategy_continuous, class: 'form-check-label' do = form.label :deploy_strategy_continuous, class: 'form-check-label' do
%strong= s_('CICD|Continuous deployment to production') = s_('CICD|Continuous deployment to production')
= link_to icon('question-circle'), help_page_path('topics/autodevops/index.md', anchor: 'auto-deploy'), target: '_blank' = link_to icon('question-circle'), help_page_path('topics/autodevops/index.md', anchor: 'auto-deploy'), target: '_blank'
.form-check .form-check
= form.radio_button :deploy_strategy, 'manual', class: 'form-check-input' = form.radio_button :deploy_strategy, 'manual', class: 'form-check-input'
= form.label :deploy_strategy_manual, class: 'form-check-label' do = form.label :deploy_strategy_manual, class: 'form-check-label' do
%strong= s_('CICD|Automatic deployment to staging, manual deployment to production') = s_('CICD|Automatic deployment to staging, manual deployment to production')
= link_to icon('question-circle'), help_page_path('ci/environments.md', anchor: 'manually-deploying-to-environments'), target: '_blank' = link_to icon('question-circle'), help_page_path('ci/environments.md', anchor: 'manually-deploying-to-environments'), target: '_blank'
.card.auto-devops-card
.card-body
.form-check
= form.radio_button :enabled, 'false', class: 'form-check-input js-toggle-extra-settings', data: { hide_extra_settings: true }
= form.label :enabled_false, class: 'form-check-label' do
%strong= s_('CICD|Disable Auto DevOps')
.form-text.text-muted
= s_('CICD|An explicit %{ci_file} needs to be specified before you can begin using Continuous Integration and Delivery.').html_safe % { ci_file: ci_file_formatted }
= f.submit _('Save changes'), class: "btn btn-success prepend-top-15" = f.submit _('Save changes'), class: "btn btn-success prepend-top-15"
---
title: Improve and simplify Auto DevOps settings flow
merge_request: 20946
author:
type: other
...@@ -990,9 +990,6 @@ msgstr "" ...@@ -990,9 +990,6 @@ msgstr ""
msgid "CI/CD settings" msgid "CI/CD settings"
msgstr "" msgstr ""
msgid "CICD|An explicit %{ci_file} needs to be specified before you can begin using Continuous Integration and Delivery."
msgstr ""
msgid "CICD|Auto DevOps" msgid "CICD|Auto DevOps"
msgstr "" msgstr ""
...@@ -1005,22 +1002,13 @@ msgstr "" ...@@ -1005,22 +1002,13 @@ msgstr ""
msgid "CICD|Continuous deployment to production" msgid "CICD|Continuous deployment to production"
msgstr "" msgstr ""
msgid "CICD|Deployment strategy" msgid "CICD|Default to Auto DevOps pipeline"
msgstr ""
msgid "CICD|Deployment strategy needs a domain name to work correctly."
msgstr ""
msgid "CICD|Disable Auto DevOps"
msgstr ""
msgid "CICD|Enable Auto DevOps"
msgstr "" msgstr ""
msgid "CICD|Follow the instance default to either have Auto DevOps enabled or disabled when there is no project specific %{ci_file}." msgid "CICD|Deployment strategy"
msgstr "" msgstr ""
msgid "CICD|Instance default (%{state})" msgid "CICD|Deployment strategy needs a domain name to work correctly."
msgstr "" msgstr ""
msgid "CICD|Jobs" msgid "CICD|Jobs"
...@@ -1029,12 +1017,15 @@ msgstr "" ...@@ -1029,12 +1017,15 @@ msgstr ""
msgid "CICD|Learn more about Auto DevOps" msgid "CICD|Learn more about Auto DevOps"
msgstr "" msgstr ""
msgid "CICD|The Auto DevOps pipeline configuration will be used when there is no %{ci_file} in the project." msgid "CICD|The Auto DevOps pipeline will run if no alternative CI configuration file is found."
msgstr "" msgstr ""
msgid "CICD|You need to specify a domain if you want to use Auto Review Apps and Auto Deploy stages." msgid "CICD|You need to specify a domain if you want to use Auto Review Apps and Auto Deploy stages."
msgstr "" msgstr ""
msgid "CICD|instance enabled"
msgstr ""
msgid "Callback URL" msgid "Callback URL"
msgstr "" msgstr ""
......
...@@ -12,9 +12,9 @@ module QA # rubocop:disable Naming/FileName ...@@ -12,9 +12,9 @@ module QA # rubocop:disable Naming/FileName
end end
view 'app/views/projects/settings/ci_cd/_autodevops_form.html.haml' do view 'app/views/projects/settings/ci_cd/_autodevops_form.html.haml' do
element :enable_auto_devops_field, 'radio_button :enabled' element :enable_auto_devops_field, 'check_box :enabled'
element :domain_field, 'text_field :domain' element :domain_field, 'text_field :domain'
element :enable_auto_devops_button, "%strong= s_('CICD|Enable Auto DevOps')" element :enable_auto_devops_button, "%strong= s_('CICD|Default to Auto DevOps pipeline')"
element :domain_input, "%strong= _('Domain')" element :domain_input, "%strong= _('Domain')"
element :save_changes_button, "submit _('Save changes')" element :save_changes_button, "submit _('Save changes')"
end end
...@@ -33,7 +33,7 @@ module QA # rubocop:disable Naming/FileName ...@@ -33,7 +33,7 @@ module QA # rubocop:disable Naming/FileName
def enable_auto_devops_with_domain(domain) def enable_auto_devops_with_domain(domain)
expand_section(:autodevops_settings) do expand_section(:autodevops_settings) do
choose 'Enable Auto DevOps' check 'Default to Auto DevOps pipeline'
fill_in 'Domain', with: domain fill_in 'Domain', with: domain
click_on 'Save changes' click_on 'Save changes'
end end
......
...@@ -175,7 +175,7 @@ describe 'Admin updates settings' do ...@@ -175,7 +175,7 @@ describe 'Admin updates settings' do
it 'Change CI/CD settings' do it 'Change CI/CD settings' do
page.within('.as-ci-cd') do page.within('.as-ci-cd') do
check 'Enabled Auto DevOps for projects by default' check 'Default to Auto DevOps pipeline for all projects'
fill_in 'Auto devops domain', with: 'domain.com' fill_in 'Auto devops domain', with: 'domain.com'
click_button 'Save changes' click_button 'Save changes'
end end
......
...@@ -8,7 +8,6 @@ describe "Projects > Settings > Pipelines settings" do ...@@ -8,7 +8,6 @@ describe "Projects > Settings > Pipelines settings" do
before do before do
sign_in(user) sign_in(user)
project.add_role(user, role) project.add_role(user, role)
create(:project_auto_devops, project: project)
end end
context 'for developer' do context 'for developer' do
...@@ -61,19 +60,58 @@ describe "Projects > Settings > Pipelines settings" do ...@@ -61,19 +60,58 @@ describe "Projects > Settings > Pipelines settings" do
end end
describe 'Auto DevOps' do describe 'Auto DevOps' do
it 'update auto devops settings' do context 'when auto devops is turned on instance-wide' do
visit project_settings_ci_cd_path(project) before do
stub_application_setting(auto_devops_enabled: true)
end
it 'auto devops is on by default and can be manually turned off' do
visit project_settings_ci_cd_path(project)
page.within '#autodevops-settings' do page.within '#autodevops-settings' do
fill_in('project_auto_devops_attributes_domain', with: 'test.com') expect(find_field('project_auto_devops_attributes_enabled')).to be_checked
page.choose('project_auto_devops_attributes_enabled_false') expect(page).to have_content('instance enabled')
click_on 'Save changes' uncheck 'Default to Auto DevOps pipeline'
click_on 'Save changes'
end
expect(page.status_code).to eq(200)
expect(project.auto_devops).to be_present
expect(project.auto_devops).not_to be_enabled
page.within '#autodevops-settings' do
expect(find_field('project_auto_devops_attributes_enabled')).not_to be_checked
expect(page).not_to have_content('instance enabled')
end
end end
end
expect(page.status_code).to eq(200) context 'when auto devops is not turned on instance-wide' do
expect(project.auto_devops).to be_present before do
expect(project.auto_devops).not_to be_enabled stub_application_setting(auto_devops_enabled: false)
expect(project.auto_devops.domain).to eq('test.com') end
it 'auto devops is off by default and can be manually turned on' do
visit project_settings_ci_cd_path(project)
page.within '#autodevops-settings' do
expect(page).not_to have_content('instance enabled')
expect(find_field('project_auto_devops_attributes_enabled')).not_to be_checked
check 'Default to Auto DevOps pipeline'
fill_in('project_auto_devops_attributes_domain', with: 'test.com')
click_on 'Save changes'
end
expect(page.status_code).to eq(200)
expect(project.auto_devops).to be_present
expect(project.auto_devops).to be_enabled
expect(project.auto_devops.domain).to eq('test.com')
page.within '#autodevops-settings' do
expect(find_field('project_auto_devops_attributes_enabled')).to be_checked
expect(page).not_to have_content('instance enabled')
end
end
end end
context 'when there is a cluster with ingress and external_ip' do context 'when there is a cluster with ingress and external_ip' do
......
...@@ -3307,6 +3307,50 @@ describe Project do ...@@ -3307,6 +3307,50 @@ describe Project do
end end
end end
describe '#has_auto_devops_implicitly_enabled?' do
set(:project) { create(:project) }
context 'when disabled in settings' do
before do
stub_application_setting(auto_devops_enabled: false)
end
it 'does not have auto devops implicitly disabled' do
expect(project).not_to have_auto_devops_implicitly_enabled
end
end
context 'when enabled in settings' do
before do
stub_application_setting(auto_devops_enabled: true)
end
it 'auto devops is implicitly disabled' do
expect(project).to have_auto_devops_implicitly_enabled
end
context 'when explicitly disabled' do
before do
create(:project_auto_devops, project: project, enabled: false)
end
it 'does not have auto devops implicitly disabled' do
expect(project).not_to have_auto_devops_implicitly_enabled
end
end
context 'when explicitly enabled' do
before do
create(:project_auto_devops, project: project, enabled: true)
end
it 'does not have auto devops implicitly disabled' do
expect(project).not_to have_auto_devops_implicitly_enabled
end
end
end
end
describe '#has_auto_devops_implicitly_disabled?' do describe '#has_auto_devops_implicitly_disabled?' do
set(:project) { create(:project) } set(:project) { create(:project) }
...@@ -3341,7 +3385,7 @@ describe Project do ...@@ -3341,7 +3385,7 @@ describe Project do
context 'when explicitly enabled' do context 'when explicitly enabled' do
before do before do
create(:project_auto_devops, project: project) create(:project_auto_devops, project: project, enabled: true)
end end
it 'does not have auto devops implicitly disabled' do it 'does not have auto devops implicitly disabled' 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