Commit c288ca78 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Use hook for setting Pipeline config_source

parent 003bfac2
...@@ -38,6 +38,7 @@ module Ci ...@@ -38,6 +38,7 @@ module Ci
validates :status, presence: { unless: :importing? } validates :status, presence: { unless: :importing? }
validate :valid_commit_sha, unless: :importing? validate :valid_commit_sha, unless: :importing?
after_initialize :set_config_source, if: :new_record?
after_create :keep_around_commits, unless: :importing? after_create :keep_around_commits, unless: :importing?
enum source: { enum source: {
...@@ -318,9 +319,16 @@ module Ci ...@@ -318,9 +319,16 @@ module Ci
builds.latest.failed_but_allowed.any? builds.latest.failed_but_allowed.any?
end end
def detect_ci_yaml_file def set_config_source
ci_yaml_from_repo&.tap { self.repository_source! } || self.config_source =
implied_ci_yaml_file&.tap { self.auto_devops_source! } if project
case
when ci_yaml_from_repo then :repository_source
when implied_ci_yaml_file then :auto_devops_source
end
else
:unknown_source
end
end end
def config_processor def config_processor
...@@ -350,11 +358,10 @@ module Ci ...@@ -350,11 +358,10 @@ module Ci
return @ci_yaml_file if defined?(@ci_yaml_file) return @ci_yaml_file if defined?(@ci_yaml_file)
@ci_yaml_file = @ci_yaml_file =
case config_source if auto_devops_source?
when "repository_source", "unknown_source"
ci_yaml_from_repo
when "auto_devops_source"
implied_ci_yaml_file implied_ci_yaml_file
else
ci_yaml_from_repo
end end
if @ci_yaml_file if @ci_yaml_file
......
...@@ -469,10 +469,10 @@ class Project < ActiveRecord::Base ...@@ -469,10 +469,10 @@ class Project < ActiveRecord::Base
end end
def auto_devops_enabled? def auto_devops_enabled?
if auto_devops && auto_devops.enabled.present? if auto_devops&.enabled.nil?
auto_devops.enabled?
else
current_application_settings.auto_devops_enabled? current_application_settings.auto_devops_enabled?
else
auto_devops.enabled?
end end
end end
...@@ -1389,15 +1389,20 @@ class Project < ActiveRecord::Base ...@@ -1389,15 +1389,20 @@ class Project < ActiveRecord::Base
end end
def predefined_variables def predefined_variables
[ variables = [
{ key: 'CI_PROJECT_ID', value: id.to_s, public: true }, { key: 'CI_PROJECT_ID', value: id.to_s, public: true },
{ key: 'CI_PROJECT_NAME', value: path, public: true }, { key: 'CI_PROJECT_NAME', value: path, public: true },
{ key: 'CI_PROJECT_PATH', value: full_path, public: true }, { key: 'CI_PROJECT_PATH', value: full_path, public: true },
{ key: 'CI_PROJECT_PATH_SLUG', value: full_path_slug, public: true }, { key: 'CI_PROJECT_PATH_SLUG', value: full_path_slug, public: true },
{ key: 'CI_PROJECT_NAMESPACE', value: namespace.full_path, public: true }, { key: 'CI_PROJECT_NAMESPACE', value: namespace.full_path, public: true },
{ key: 'CI_PROJECT_URL', value: web_url, public: true }, { key: 'CI_PROJECT_URL', value: web_url, public: true }
{ key: 'AUTO_DEVOPS_DOMAIN', value: auto_devops.domain, public: true }
] ]
if auto_devops_enabled? && auto_devops&.domain
variables << { key: 'AUTO_DEVOPS_DOMAIN', value: auto_devops.domain, public: true }
end
variables
end end
def container_registry_variables def container_registry_variables
......
class ProjectAutoDevops < ActiveRecord::Base class ProjectAutoDevops < ActiveRecord::Base
belongs_to :project belongs_to :project
validates :domain, presence: true, if: :enabled? validates :domain, presence: true, hostname: { allow_numeric_hostname: true }, if: :enabled?
end end
...@@ -16,7 +16,7 @@ class PipelineEntity < Grape::Entity ...@@ -16,7 +16,7 @@ class PipelineEntity < Grape::Entity
expose :flags do expose :flags do
expose :latest?, as: :latest expose :latest?, as: :latest
expose :stuck?, as: :stuck expose :stuck?, as: :stuck
expose :auto_devops?, as: :auto_devops expose :auto_devops_source?, as: :auto_devops
expose :has_yaml_errors?, as: :yaml_errors expose :has_yaml_errors?, as: :yaml_errors
expose :can_retry?, as: :retryable expose :can_retry?, as: :retryable
expose :can_cancel?, as: :cancelable expose :can_cancel?, as: :cancelable
......
...@@ -67,11 +67,11 @@ module Ci ...@@ -67,11 +67,11 @@ module Ci
return error('Commit not found') return error('Commit not found')
end end
unless pipeline.detect_ci_yaml_file unless pipeline.config_processor
unless pipeline.ci_yaml_file
return error("Missing #{pipeline.ci_yaml_file_path} file") return error("Missing #{pipeline.ci_yaml_file_path} file")
end end
unless pipeline.config_processor
return error(pipeline.yaml_errors, save: save_on_errors) return error(pipeline.yaml_errors, save: save_on_errors)
end end
......
require 'spec_helper' require 'spec_helper'
describe Ci::CreatePipelineService do describe Ci::CreatePipelineService do
let(:project) { create(:project, :repository) } set(:project) { create(:project, :repository) }
let(:user) { create(:admin) } let(:user) { create(:admin) }
let(:ref_name) { 'refs/heads/master' } let(:ref_name) { 'refs/heads/master' }
......
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