summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/artifact_blob.rb2
-rw-r--r--app/models/clusters/cluster.rb31
-rw-r--r--app/models/clusters/concerns/application_core.rb4
-rw-r--r--app/models/commit.rb1
-rw-r--r--app/models/project.rb9
5 files changed, 29 insertions, 18 deletions
diff --git a/app/models/ci/artifact_blob.rb b/app/models/ci/artifact_blob.rb
index d87d6a5cb2f..ef00ad75683 100644
--- a/app/models/ci/artifact_blob.rb
+++ b/app/models/ci/artifact_blob.rb
@@ -4,7 +4,7 @@ module Ci
class ArtifactBlob
include BlobLike
- EXTENSIONS_SERVED_BY_PAGES = %w[.html .htm .txt .json .log].freeze
+ EXTENSIONS_SERVED_BY_PAGES = %w[.html .htm .txt .json .xml .log].freeze
attr_reader :entry
diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb
index 7855fb69bd6..7a61622b139 100644
--- a/app/models/clusters/cluster.rb
+++ b/app/models/clusters/cluster.rb
@@ -37,13 +37,18 @@ module Clusters
has_one :platform_kubernetes, class_name: 'Clusters::Platforms::Kubernetes', inverse_of: :cluster, autosave: true
- has_one :application_helm, class_name: 'Clusters::Applications::Helm'
- has_one :application_ingress, class_name: 'Clusters::Applications::Ingress'
- has_one :application_cert_manager, class_name: 'Clusters::Applications::CertManager'
- has_one :application_prometheus, class_name: 'Clusters::Applications::Prometheus'
- has_one :application_runner, class_name: 'Clusters::Applications::Runner'
- has_one :application_jupyter, class_name: 'Clusters::Applications::Jupyter'
- has_one :application_knative, class_name: 'Clusters::Applications::Knative'
+ def self.has_one_cluster_application(name) # rubocop:disable Naming/PredicateName
+ application = APPLICATIONS[name.to_s]
+ has_one application.association_name, class_name: application.to_s # rubocop:disable Rails/ReflectionClassName
+ end
+
+ has_one_cluster_application :helm
+ has_one_cluster_application :ingress
+ has_one_cluster_application :cert_manager
+ has_one_cluster_application :prometheus
+ has_one_cluster_application :runner
+ has_one_cluster_application :jupyter
+ has_one_cluster_application :knative
has_many :kubernetes_namespaces
@@ -127,15 +132,9 @@ module Clusters
end
def applications
- [
- application_helm || build_application_helm,
- application_ingress || build_application_ingress,
- application_cert_manager || build_application_cert_manager,
- application_prometheus || build_application_prometheus,
- application_runner || build_application_runner,
- application_jupyter || build_application_jupyter,
- application_knative || build_application_knative
- ]
+ APPLICATIONS.values.map do |application_class|
+ public_send(application_class.association_name) || public_send("build_#{application_class.association_name}") # rubocop:disable GitlabSecurity/PublicSend
+ end
end
def provider
diff --git a/app/models/clusters/concerns/application_core.rb b/app/models/clusters/concerns/application_core.rb
index 803a65726d3..d1b57a21a7d 100644
--- a/app/models/clusters/concerns/application_core.rb
+++ b/app/models/clusters/concerns/application_core.rb
@@ -32,6 +32,10 @@ module Clusters
self.to_s.demodulize.underscore
end
+ def self.association_name
+ :"application_#{application_name}"
+ end
+
def name
self.class.application_name
end
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 1470b50f396..a442f607fbf 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -1,4 +1,3 @@
-# coding: utf-8
# frozen_string_literal: true
class Commit
diff --git a/app/models/project.rb b/app/models/project.rb
index 59c187fac31..57f1ca98ee2 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -753,6 +753,15 @@ class Project < ApplicationRecord
latest_successful_build_for_ref(job_name, ref) || raise(ActiveRecord::RecordNotFound.new("Couldn't find job #{job_name}"))
end
+ def latest_pipeline_for_ref(ref = default_branch)
+ ref = ref.presence || default_branch
+ sha = commit(ref)&.sha
+
+ return unless sha
+
+ ci_pipelines.newest_first(ref: ref, sha: sha).first
+ end
+
def merge_base_commit(first_commit_id, second_commit_id)
sha = repository.merge_base(first_commit_id, second_commit_id)
commit_by(oid: sha) if sha