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