From 3017697701eaecd301edfbc2e4f7c865456f1b0f Mon Sep 17 00:00:00 2001 From: bokebilly Date: Sat, 16 Sep 2017 15:02:37 +0200 Subject: Add warning message if domain or cluster are not configured --- app/helpers/auto_devops_helper.rb | 21 ++++++++++++++++++++- app/models/project_auto_devops.rb | 4 ++++ .../projects/pipelines_settings/_show.html.haml | 19 ++++++++++--------- app/views/projects/settings/ci_cd/show.html.haml | 2 +- ...7894-handle-if-auto-devops-domain-is-not-set.yml | 5 +++++ spec/models/project_auto_devops_spec.rb | 8 +++++++- 6 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 changelogs/unreleased/37894-handle-if-auto-devops-domain-is-not-set.yml diff --git a/app/helpers/auto_devops_helper.rb b/app/helpers/auto_devops_helper.rb index c455d18cff8..5da68a2d03d 100644 --- a/app/helpers/auto_devops_helper.rb +++ b/app/helpers/auto_devops_helper.rb @@ -5,6 +5,25 @@ module AutoDevopsHelper can?(current_user, :admin_pipeline, project) && project.has_auto_devops_implicitly_disabled? && !project.repository.gitlab_ci_yml && - project.ci_services.active.none? + !project.ci_service + end + + def auto_devops_warning_message(project) + missing_domain = !project.auto_devops&.has_domain? + missing_service = !project.kubernetes_service&.active? + + if missing_service + params = { + kubernetes: link_to('Kubernetes service', edit_project_service_path(project, 'kubernetes')) + } + + if missing_domain + _('Auto Review Apps and Auto Deploy need a domain name and the %s to work correctly.') % params + else + _('Auto Review Apps and Auto Deploy need the %s to work correctly.') % params + end + elsif missing_domain + _('Auto Review Apps and Auto Deploy need a domain name to work correctly.') + end end end diff --git a/app/models/project_auto_devops.rb b/app/models/project_auto_devops.rb index 7af3b6870e2..9a52edbff8e 100644 --- a/app/models/project_auto_devops.rb +++ b/app/models/project_auto_devops.rb @@ -6,6 +6,10 @@ class ProjectAutoDevops < ActiveRecord::Base validates :domain, allow_blank: true, hostname: { allow_numeric_hostname: true } + def has_domain? + domain.present? + end + def variables variables = [] variables << { key: 'AUTO_DEVOPS_DOMAIN', value: domain, public: true } if domain.present? diff --git a/app/views/projects/pipelines_settings/_show.html.haml b/app/views/projects/pipelines_settings/_show.html.haml index 2aceb4b529c..1f116c93192 100644 --- a/app/views/projects/pipelines_settings/_show.html.haml +++ b/app/views/projects/pipelines_settings/_show.html.haml @@ -3,11 +3,14 @@ = form_for @project, url: project_pipelines_settings_path(@project) do |f| %fieldset.builds-feature .form-group - %p Pipelines need to have Auto DevOps enabled or have a .gitlab-ci.yml configured before you can begin using Continuous Integration and Delivery. %h5 Auto DevOps (Beta) %p - Auto DevOps will automatically build, test, and deploy your application based on a predefined Continious Integration and Delivery configuration. + Auto DevOps will automatically build, test, and deploy your application based on a predefined Continuous Integration and Delivery configuration. = link_to 'Learn more about Auto DevOps', help_page_path('topics/autodevops/index.md') + - message = auto_devops_warning_message(@project) + - if message + %p.settings-message.text-center + = message.html_safe = f.fields_for :auto_devops_attributes, @auto_devops do |form| .radio = form.label :enabled_true do @@ -15,26 +18,24 @@ %strong Enable Auto DevOps %br %span.descr - The Auto DevOps pipeline configuration will be used when there is no .gitlab-ci.yml - in the project. + The Auto DevOps pipeline configuration will be used when there is no .gitlab-ci.yml in the project. .radio = form.label :enabled_false do = form.radio_button :enabled, 'false' %strong Disable Auto DevOps %br %span.descr - A specific .gitlab-ci.yml file needs to be specified before you can begin using Continious Integration and Delivery. + An explicit .gitlab-ci.yml needs to be specified before you can begin using Continious Integration and Delivery. .radio = form.label :enabled_nil do = form.radio_button :enabled, '' - %strong - Instance default (status: #{current_application_settings.auto_devops_enabled?}) + %strong Instance default (#{current_application_settings.auto_devops_enabled? ? 'enabled' : 'disabled'}) %br %span.descr - Follow the instance default to either have Auto DevOps enabled or disabled when there is no project specific .gitlab-ci.yml file specified. + Follow the instance default to either have Auto DevOps enabled or disabled when there is no project specific .gitlab-ci.yml. %br %p - Define a domain used by Auto DevOps to deploy towards, this is required for deploys to succeed. + You need to specify a domain if you want to use Auto Review Apps and Auto Deploy stages. = form.text_field :domain, class: 'form-control', placeholder: 'domain.com' %hr diff --git a/app/views/projects/settings/ci_cd/show.html.haml b/app/views/projects/settings/ci_cd/show.html.haml index d4f71d023c6..4e682d196c4 100644 --- a/app/views/projects/settings/ci_cd/show.html.haml +++ b/app/views/projects/settings/ci_cd/show.html.haml @@ -13,7 +13,7 @@ %button.btn.js-settings-toggle = expanded ? 'Collapse' : 'Expand' %p - Update your CI/CD configuration, like job timeout. + Update your CI/CD configuration. You need a CI/CD configuration file or Auto DevOps enabled in order to use pipelines. .settings-content.no-animate{ class: ('expanded' if expanded) } = render 'projects/pipelines_settings/show' diff --git a/changelogs/unreleased/37894-handle-if-auto-devops-domain-is-not-set.yml b/changelogs/unreleased/37894-handle-if-auto-devops-domain-is-not-set.yml new file mode 100644 index 00000000000..bbb12ff41b1 --- /dev/null +++ b/changelogs/unreleased/37894-handle-if-auto-devops-domain-is-not-set.yml @@ -0,0 +1,5 @@ +--- +title: Handle if Auto DevOps domain is not set in project settings +merge_request: +author: +type: added diff --git a/spec/models/project_auto_devops_spec.rb b/spec/models/project_auto_devops_spec.rb index ca13af4d73e..f4bb4b3e7a3 100644 --- a/spec/models/project_auto_devops_spec.rb +++ b/spec/models/project_auto_devops_spec.rb @@ -8,7 +8,13 @@ describe ProjectAutoDevops do it { is_expected.to respond_to(:created_at) } it { is_expected.to respond_to(:updated_at) } - describe 'variables' do + describe '#has_domain?' do + let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: 'domain.com') } + + it { is_expected.to have_domain } + end + + describe '#variables' do let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: domain) } context 'when domain is defined' do -- cgit v1.2.1 From 9bed20d2ae4b37f735b2c6cacd09379022708300 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 19 Sep 2017 15:56:44 +0200 Subject: Add specs for warning message shown in Auto DevOps settings --- spec/models/project_auto_devops_spec.rb | 12 ++++- .../pipelines_settings/_show.html.haml_spec.rb | 62 ++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 spec/views/projects/pipelines_settings/_show.html.haml_spec.rb diff --git a/spec/models/project_auto_devops_spec.rb b/spec/models/project_auto_devops_spec.rb index f4bb4b3e7a3..12069575866 100644 --- a/spec/models/project_auto_devops_spec.rb +++ b/spec/models/project_auto_devops_spec.rb @@ -9,9 +9,17 @@ describe ProjectAutoDevops do it { is_expected.to respond_to(:updated_at) } describe '#has_domain?' do - let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: 'domain.com') } + context 'when domain is defined' do + let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: 'domain.com') } + + it { expect(auto_devops).to have_domain } + end - it { is_expected.to have_domain } + context 'when domain is empty' do + let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: '') } + + it { expect(auto_devops).not_to have_domain } + end end describe '#variables' do diff --git a/spec/views/projects/pipelines_settings/_show.html.haml_spec.rb b/spec/views/projects/pipelines_settings/_show.html.haml_spec.rb new file mode 100644 index 00000000000..c757ccf02d3 --- /dev/null +++ b/spec/views/projects/pipelines_settings/_show.html.haml_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +describe 'projects/pipelines_settings/_show' do + let(:project) { create(:project, :repository) } + + before do + assign :project, project + end + + context 'when kubernetes is not active' do + context 'when auto devops domain is not defined' do + it 'shows warning message' do + render + + expect(rendered).to have_css('.settings-message') + expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a domain name and the') + expect(rendered).to have_link('Kubernetes service') + end + end + + context 'when auto devops domain is defined' do + before do + project.build_auto_devops(domain: 'example.com') + end + + it 'shows warning message' do + render + + expect(rendered).to have_css('.settings-message') + expect(rendered).to have_text('Auto Review Apps and Auto Deploy need the') + expect(rendered).to have_link('Kubernetes service') + end + end + end + + context 'when kubernetes is active' do + before do + project.build_kubernetes_service(active: true) + end + + context 'when auto devops domain is not defined' do + it 'shows warning message' do + render + + expect(rendered).to have_css('.settings-message') + expect(rendered).to have_text('Auto Review Apps and Auto Deploy need a domain name to work correctly.') + end + end + + context 'when auto devops domain is defined' do + before do + project.build_auto_devops(domain: 'example.com') + end + + it 'does not show warning message' do + render + + expect(rendered).not_to have_css('.settings-message') + end + end + end +end -- cgit v1.2.1 From 95eba3aa8a035049a97ec059d3fe83c679641257 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 19 Sep 2017 19:43:23 +0200 Subject: Improve after code-review --- app/helpers/auto_devops_helper.rb | 4 ++-- app/views/projects/settings/ci_cd/show.html.haml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/auto_devops_helper.rb b/app/helpers/auto_devops_helper.rb index 5da68a2d03d..483b957decb 100644 --- a/app/helpers/auto_devops_helper.rb +++ b/app/helpers/auto_devops_helper.rb @@ -18,9 +18,9 @@ module AutoDevopsHelper } if missing_domain - _('Auto Review Apps and Auto Deploy need a domain name and the %s to work correctly.') % params + _('Auto Review Apps and Auto Deploy need a domain name and the %{kubernetes} to work correctly.') % params else - _('Auto Review Apps and Auto Deploy need the %s to work correctly.') % params + _('Auto Review Apps and Auto Deploy need the %{kubernetes} to work correctly.') % params end elsif missing_domain _('Auto Review Apps and Auto Deploy need a domain name to work correctly.') diff --git a/app/views/projects/settings/ci_cd/show.html.haml b/app/views/projects/settings/ci_cd/show.html.haml index 4e682d196c4..47c056d097a 100644 --- a/app/views/projects/settings/ci_cd/show.html.haml +++ b/app/views/projects/settings/ci_cd/show.html.haml @@ -13,7 +13,7 @@ %button.btn.js-settings-toggle = expanded ? 'Collapse' : 'Expand' %p - Update your CI/CD configuration. You need a CI/CD configuration file or Auto DevOps enabled in order to use pipelines. + Update your CI/CD configuration, like job timeout or Auto DevOps. .settings-content.no-animate{ class: ('expanded' if expanded) } = render 'projects/pipelines_settings/show' -- cgit v1.2.1 From 507d9e84d73618eb3793c4b82547874052fb7833 Mon Sep 17 00:00:00 2001 From: Fabio Busatto Date: Tue, 19 Sep 2017 18:14:46 +0000 Subject: Update _show.html.haml --- app/views/projects/pipelines_settings/_show.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/projects/pipelines_settings/_show.html.haml b/app/views/projects/pipelines_settings/_show.html.haml index 1f116c93192..21d01242c0e 100644 --- a/app/views/projects/pipelines_settings/_show.html.haml +++ b/app/views/projects/pipelines_settings/_show.html.haml @@ -6,6 +6,7 @@ %h5 Auto DevOps (Beta) %p Auto DevOps will automatically build, test, and deploy your application based on a predefined Continuous Integration and Delivery configuration. + This will happen starting with the next event (e.g.: push) that occurs to the project. = link_to 'Learn more about Auto DevOps', help_page_path('topics/autodevops/index.md') - message = auto_devops_warning_message(@project) - if message -- cgit v1.2.1