Merge branch '46452-nomethoderror-undefined-method-previous_changes-for-nil-nilclass' into 'master'

Resolve "NoMethodError: undefined method `previous_changes' for nil:NilClass"

Closes #46452

See merge request gitlab-org/gitlab-ce!19190
This commit is contained in:
Kamil Trzciński 2018-06-05 12:06:25 +00:00
commit 636d70381e
3 changed files with 10 additions and 1 deletions

View file

@ -38,7 +38,7 @@ module Projects
end end
def run_auto_devops_pipeline? def run_auto_devops_pipeline?
return false if project.repository.gitlab_ci_yml || !project.auto_devops.previous_changes.include?('enabled') return false if project.repository.gitlab_ci_yml || !project.auto_devops&.previous_changes&.include?('enabled')
project.auto_devops.enabled? || (project.auto_devops.enabled.nil? && Gitlab::CurrentSettings.auto_devops_enabled?) project.auto_devops.enabled? || (project.auto_devops.enabled.nil? && Gitlab::CurrentSettings.auto_devops_enabled?)
end end

View file

@ -0,0 +1,5 @@
---
title: Check for nil AutoDevOps when saving project CI/CD settings.
merge_request: 19190
author:
type: fixed

View file

@ -275,6 +275,10 @@ describe Projects::UpdateService do
it { is_expected.to eq(false) } it { is_expected.to eq(false) }
end end
context 'when auto devops is nil' do
it { is_expected.to eq(false) }
end
context 'when auto devops is explicitly enabled' do context 'when auto devops is explicitly enabled' do
before do before do
project.create_auto_devops!(enabled: true) project.create_auto_devops!(enabled: true)