diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 15:09:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 15:09:03 +0300 |
commit | 5366964a10484c2783a646b35a6da9eece01b242 (patch) | |
tree | 4a5a7a289d44e63d96a50a6a64db6e16b871f19c /app/models | |
parent | 733befe96ad19f5a02e442c4a9cc8059d3aabbda (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/build.rb | 2 | ||||
-rw-r--r-- | app/models/ci/processable.rb | 29 | ||||
-rw-r--r-- | app/models/commit_status.rb | 12 | ||||
-rw-r--r-- | app/models/project_services/youtrack_service.rb | 4 |
4 files changed, 32 insertions, 15 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index b0502f7a26e..27a394e4ab8 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -818,7 +818,7 @@ module Ci depended_jobs = depends_on_builds # find all jobs that are needed - if Feature.enabled?(:ci_dag_support, project, default_enabled: true) && needs.exists? + if Feature.enabled?(:ci_dag_support, project, default_enabled: true) && scheduling_type_dag? depended_jobs = depended_jobs.where(name: needs.artifacts.select(:name)) end diff --git a/app/models/ci/processable.rb b/app/models/ci/processable.rb index 95fb75688a9..6c080582cae 100644 --- a/app/models/ci/processable.rb +++ b/app/models/ci/processable.rb @@ -12,6 +12,18 @@ module Ci scope :preload_needs, -> { preload(:needs) } + scope :with_needs, -> (names = nil) do + needs = Ci::BuildNeed.scoped_build.select(1) + needs = needs.where(name: names) if names + where('EXISTS (?)', needs).preload(:needs) + end + + scope :without_needs, -> (names = nil) do + needs = Ci::BuildNeed.scoped_build.select(1) + needs = needs.where(name: names) if names + where('NOT EXISTS (?)', needs) + end + def self.select_with_aggregated_needs(project) return all unless Feature.enabled?(:ci_dag_support, project, default_enabled: true) @@ -26,6 +38,18 @@ module Ci ) end + # Old processables may have scheduling_type as nil, + # so we need to ensure the data exists before using it. + def self.populate_scheduling_type! + needs = Ci::BuildNeed.scoped_build.select(1) + where(scheduling_type: nil).update_all( + "scheduling_type = CASE WHEN (EXISTS (#{needs.to_sql})) + THEN #{scheduling_types[:dag]} + ELSE #{scheduling_types[:stage]} + END" + ) + end + validates :type, presence: true validates :scheduling_type, presence: true, on: :create, if: :validate_scheduling_type? @@ -53,6 +77,11 @@ module Ci raise NotImplementedError end + # Overriding scheduling_type enum's method for nil `scheduling_type`s + def scheduling_type_dag? + super || find_legacy_scheduling_type == :dag + end + # scheduling_type column of previous builds/bridges have not been populated, # so we calculate this value on runtime when we need it. def find_legacy_scheduling_type diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 5a917588a33..35b727720ba 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -62,18 +62,6 @@ class CommitStatus < ApplicationRecord preload(project: :namespace) end - scope :with_needs, -> (names = nil) do - needs = Ci::BuildNeed.scoped_build.select(1) - needs = needs.where(name: names) if names - where('EXISTS (?)', needs).preload(:needs) - end - - scope :without_needs, -> (names = nil) do - needs = Ci::BuildNeed.scoped_build.select(1) - needs = needs.where(name: names) if names - where('NOT EXISTS (?)', needs) - end - scope :match_id_and_lock_version, -> (slice) do # it expects that items are an array of attributes to match # each hash needs to have `id` and `lock_version` diff --git a/app/models/project_services/youtrack_service.rb b/app/models/project_services/youtrack_service.rb index 0416eaa5be0..02d06eeb405 100644 --- a/app/models/project_services/youtrack_service.rb +++ b/app/models/project_services/youtrack_service.rb @@ -6,9 +6,9 @@ class YoutrackService < IssueTrackerService # {PROJECT-KEY}-{NUMBER} Examples: YT-1, PRJ-1, gl-030 def self.reference_pattern(only_long: false) if only_long - /(?<issue>\b[A-Za-z][A-Za-z0-9_]*-\d+)/ + /(?<issue>\b[A-Za-z][A-Za-z0-9_]*-\d+\b)/ else - /(?<issue>\b[A-Za-z][A-Za-z0-9_]*-\d+)|(#{Issue.reference_prefix}(?<issue>\d+))/ + /(?<issue>\b[A-Za-z][A-Za-z0-9_]*-\d+\b)|(#{Issue.reference_prefix}(?<issue>\d+))/ end end |