summaryrefslogtreecommitdiff
path: root/app/models/ci/catalog
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-03-03 18:10:18 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-03 18:10:18 +0000
commit3413ab248287b19b1d2cd1f78d957096546e8c37 (patch)
treeb59d4bddbee10eceebbe7a085c3d660307d03ca5 /app/models/ci/catalog
parentdbe0e5676267eb142dd8d81e4c881c997cb96962 (diff)
downloadgitlab-ce-3413ab248287b19b1d2cd1f78d957096546e8c37.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/ci/catalog')
-rw-r--r--app/models/ci/catalog/listing.rb27
-rw-r--r--app/models/ci/catalog/resource.rb16
2 files changed, 43 insertions, 0 deletions
diff --git a/app/models/ci/catalog/listing.rb b/app/models/ci/catalog/listing.rb
new file mode 100644
index 00000000000..99a5230b64e
--- /dev/null
+++ b/app/models/ci/catalog/listing.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module Ci
+ module Catalog
+ class Listing
+ # This class is the SSoT to displaying the list of resources in the
+ # CI/CD Catalog given a namespace as a scope.
+ # This model is not directly backed by a table and joins catalog resources
+ # with projects to return relevant data.
+ def initialize(namespace)
+ raise ArgumentError, 'Namespace is not a root namespace' unless namespace.root?
+
+ @namespace = namespace
+ end
+
+ def resources
+ Ci::Catalog::Resource
+ .joins(:project).includes(:project)
+ .merge(Project.in_namespace(namespace.self_and_descendant_ids))
+ end
+
+ private
+
+ attr_reader :namespace
+ end
+ end
+end
diff --git a/app/models/ci/catalog/resource.rb b/app/models/ci/catalog/resource.rb
new file mode 100644
index 00000000000..1b3dec5f54d
--- /dev/null
+++ b/app/models/ci/catalog/resource.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+module Ci
+ module Catalog
+ # This class represents a CI/CD Catalog resource.
+ # A Catalog resource is normally associated to a project.
+ # This model connects to the `main` database because of its
+ # dependency on the Project model and its need to join with that table
+ # in order to generate the CI/CD catalog.
+ class Resource < ::ApplicationRecord
+ self.table_name = 'catalog_resources'
+
+ belongs_to :project
+ end
+ end
+end