diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2017-09-06 15:14:21 +0200 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2017-09-06 15:14:21 +0200 |
commit | c288ca78b42986ea1cc315d46d58fc25f7ff8f85 (patch) | |
tree | 71f798f710562db6127ea4bb2b19bfca4a1b2ba7 /app | |
parent | 003bfac2931cfaffce0fb4ad5be84cb95d093490 (diff) | |
download | gitlab-ce-c288ca78b42986ea1cc315d46d58fc25f7ff8f85.tar.gz |
Use hook for setting Pipeline config_source
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/pipeline.rb | 21 | ||||
-rw-r--r-- | app/models/project.rb | 17 | ||||
-rw-r--r-- | app/models/project_auto_devops.rb | 2 | ||||
-rw-r--r-- | app/serializers/pipeline_entity.rb | 2 | ||||
-rw-r--r-- | app/services/ci/create_pipeline_service.rb | 8 |
5 files changed, 31 insertions, 19 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 7ceb1edc96a..90fce6576a5 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index bf670da11d2..1354c988a47 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/models/project_auto_devops.rb b/app/models/project_auto_devops.rb index 7bf6ef4c821..d39273216d6 100644 --- a/app/models/project_auto_devops.rb +++ b/app/models/project_auto_devops.rb @@ -1,5 +1,5 @@ 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 diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index 767f33e11e1..357fc71f877 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -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 diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index 821542dd8d2..67c0362917e 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -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 |