gitlab-org--gitlab-foss/app/models/concerns/project_api_compatibility.rb
Nick Thomas a5a444906d Fix the project auto devops API
If `project_auto_devops.enabled` is nil for a project, when setting any
auto devops values via the API, we try to create a new row in the DB,
instead of re-using the existing one. This leads to the project_id
being set to nil, and the database `NOT NULL` constraint leading to a
500 response.

This commit resolves the issue by correctly detecting the presence of a
ProjectAutoDevops row and re-using it. Persistence is also moved away
from explicit `update!` calls and into relying on `autosave: true` on
the model.
2019-07-19 21:39:26 +00:00

18 lines
447 B
Ruby

# frozen_string_literal: true
# Add methods used by the projects API
module ProjectAPICompatibility
extend ActiveSupport::Concern
def build_git_strategy=(value)
write_attribute(:build_allow_git_fetch, value == 'fetch')
end
def auto_devops_enabled=(value)
(auto_devops || build_auto_devops).enabled = value
end
def auto_devops_deploy_strategy=(value)
(auto_devops || build_auto_devops).deploy_strategy = value
end
end