aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/packages/alpine/search.go53
-rw-r--r--models/packages/debian/search.go62
-rw-r--r--models/packages/descriptor.go3
-rw-r--r--models/packages/package.go6
-rw-r--r--models/packages/package_property.go38
5 files changed, 130 insertions, 32 deletions
diff --git a/models/packages/alpine/search.go b/models/packages/alpine/search.go
new file mode 100644
index 0000000000..77eccb90ed
--- /dev/null
+++ b/models/packages/alpine/search.go
@@ -0,0 +1,53 @@
+// Copyright 2023 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package alpine
+
+import (
+ "context"
+
+ packages_model "code.gitea.io/gitea/models/packages"
+ alpine_module "code.gitea.io/gitea/modules/packages/alpine"
+)
+
+// GetBranches gets all available branches
+func GetBranches(ctx context.Context, ownerID int64) ([]string, error) {
+ return packages_model.GetDistinctPropertyValues(
+ ctx,
+ packages_model.TypeAlpine,
+ ownerID,
+ packages_model.PropertyTypeFile,
+ alpine_module.PropertyBranch,
+ nil,
+ )
+}
+
+// GetRepositories gets all available repositories for the given branch
+func GetRepositories(ctx context.Context, ownerID int64, branch string) ([]string, error) {
+ return packages_model.GetDistinctPropertyValues(
+ ctx,
+ packages_model.TypeAlpine,
+ ownerID,
+ packages_model.PropertyTypeFile,
+ alpine_module.PropertyRepository,
+ &packages_model.DistinctPropertyDependency{
+ Name: alpine_module.PropertyBranch,
+ Value: branch,
+ },
+ )
+}
+
+// GetArchitectures gets all available architectures for the given repository
+func GetArchitectures(ctx context.Context, ownerID int64, repository string) ([]string, error) {
+ return packages_model.GetDistinctPropertyValues(
+ ctx,
+ packages_model.TypeAlpine,
+ ownerID,
+ packages_model.PropertyTypeFile,
+ alpine_module.PropertyArchitecture,
+ &packages_model.DistinctPropertyDependency{
+ Name: alpine_module.PropertyRepository,
+ Value: repository,
+ },
+ )
+}
diff --git a/models/packages/debian/search.go b/models/packages/debian/search.go
index 332a4f7040..c63a319304 100644
--- a/models/packages/debian/search.go
+++ b/models/packages/debian/search.go
@@ -88,44 +88,42 @@ func SearchLatestPackages(ctx context.Context, opts *PackageSearchOptions) ([]*p
// GetDistributions gets all available distributions
func GetDistributions(ctx context.Context, ownerID int64) ([]string, error) {
- return getDistinctPropertyValues(ctx, ownerID, "", debian_module.PropertyDistribution)
+ return packages.GetDistinctPropertyValues(
+ ctx,
+ packages.TypeDebian,
+ ownerID,
+ packages.PropertyTypeFile,
+ debian_module.PropertyDistribution,
+ nil,
+ )
}
// GetComponents gets all available components for the given distribution
func GetComponents(ctx context.Context, ownerID int64, distribution string) ([]string, error) {
- return getDistinctPropertyValues(ctx, ownerID, distribution, debian_module.PropertyComponent)
+ return packages.GetDistinctPropertyValues(
+ ctx,
+ packages.TypeDebian,
+ ownerID,
+ packages.PropertyTypeFile,
+ debian_module.PropertyComponent,
+ &packages.DistinctPropertyDependency{
+ Name: debian_module.PropertyDistribution,
+ Value: distribution,
+ },
+ )
}
// GetArchitectures gets all available architectures for the given distribution
func GetArchitectures(ctx context.Context, ownerID int64, distribution string) ([]string, error) {
- return getDistinctPropertyValues(ctx, ownerID, distribution, debian_module.PropertyArchitecture)
-}
-
-func getDistinctPropertyValues(ctx context.Context, ownerID int64, distribution, propName string) ([]string, error) {
- var cond builder.Cond = builder.Eq{
- "package_property.ref_type": packages.PropertyTypeFile,
- "package_property.name": propName,
- "package.type": packages.TypeDebian,
- "package.owner_id": ownerID,
- }
- if distribution != "" {
- innerCond := builder.
- Expr("pp.ref_id = package_property.ref_id").
- And(builder.Eq{
- "pp.ref_type": packages.PropertyTypeFile,
- "pp.name": debian_module.PropertyDistribution,
- "pp.value": distribution,
- })
- cond = cond.And(builder.Exists(builder.Select("pp.ref_id").From("package_property pp").Where(innerCond)))
- }
-
- values := make([]string, 0, 5)
- return values, db.GetEngine(ctx).
- Table("package_property").
- Distinct("package_property.value").
- Join("INNER", "package_file", "package_file.id = package_property.ref_id").
- Join("INNER", "package_version", "package_version.id = package_file.version_id").
- Join("INNER", "package", "package.id = package_version.package_id").
- Where(cond).
- Find(&values)
+ return packages.GetDistinctPropertyValues(
+ ctx,
+ packages.TypeDebian,
+ ownerID,
+ packages.PropertyTypeFile,
+ debian_module.PropertyArchitecture,
+ &packages.DistinctPropertyDependency{
+ Name: debian_module.PropertyDistribution,
+ Value: distribution,
+ },
+ )
}
diff --git a/models/packages/descriptor.go b/models/packages/descriptor.go
index 1cac2eb022..a69f477115 100644
--- a/models/packages/descriptor.go
+++ b/models/packages/descriptor.go
@@ -12,6 +12,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/json"
+ "code.gitea.io/gitea/modules/packages/alpine"
"code.gitea.io/gitea/modules/packages/cargo"
"code.gitea.io/gitea/modules/packages/chef"
"code.gitea.io/gitea/modules/packages/composer"
@@ -136,6 +137,8 @@ func GetPackageDescriptor(ctx context.Context, pv *PackageVersion) (*PackageDesc
var metadata interface{}
switch p.Type {
+ case TypeAlpine:
+ metadata = &alpine.VersionMetadata{}
case TypeCargo:
metadata = &cargo.Metadata{}
case TypeChef:
diff --git a/models/packages/package.go b/models/packages/package.go
index a817ab6ff1..17d4d79f30 100644
--- a/models/packages/package.go
+++ b/models/packages/package.go
@@ -30,6 +30,7 @@ type Type string
// List of supported packages
const (
+ TypeAlpine Type = "alpine"
TypeCargo Type = "cargo"
TypeChef Type = "chef"
TypeComposer Type = "composer"
@@ -51,6 +52,7 @@ const (
)
var TypeList = []Type{
+ TypeAlpine,
TypeCargo,
TypeChef,
TypeComposer,
@@ -74,6 +76,8 @@ var TypeList = []Type{
// Name gets the name of the package type
func (pt Type) Name() string {
switch pt {
+ case TypeAlpine:
+ return "Alpine"
case TypeCargo:
return "Cargo"
case TypeChef:
@@ -117,6 +121,8 @@ func (pt Type) Name() string {
// SVGName gets the name of the package type svg image
func (pt Type) SVGName() string {
switch pt {
+ case TypeAlpine:
+ return "gitea-alpine"
case TypeCargo:
return "gitea-cargo"
case TypeChef:
diff --git a/models/packages/package_property.go b/models/packages/package_property.go
index e03b12c9df..e0170016cf 100644
--- a/models/packages/package_property.go
+++ b/models/packages/package_property.go
@@ -7,6 +7,8 @@ import (
"context"
"code.gitea.io/gitea/models/db"
+
+ "xorm.io/builder"
)
func init() {
@@ -81,3 +83,39 @@ func DeletePropertyByName(ctx context.Context, refType PropertyType, refID int64
_, err := db.GetEngine(ctx).Where("ref_type = ? AND ref_id = ? AND name = ?", refType, refID, name).Delete(&PackageProperty{})
return err
}
+
+type DistinctPropertyDependency struct {
+ Name string
+ Value string
+}
+
+// GetDistinctPropertyValues returns all distinct property values for a given type.
+// Optional: Search only in dependence of another property.
+func GetDistinctPropertyValues(ctx context.Context, packageType Type, ownerID int64, refType PropertyType, propertyName string, dep *DistinctPropertyDependency) ([]string, error) {
+ var cond builder.Cond = builder.Eq{
+ "package_property.ref_type": refType,
+ "package_property.name": propertyName,
+ "package.type": packageType,
+ "package.owner_id": ownerID,
+ }
+ if dep != nil {
+ innerCond := builder.
+ Expr("pp.ref_id = package_property.ref_id").
+ And(builder.Eq{
+ "pp.ref_type": refType,
+ "pp.name": dep.Name,
+ "pp.value": dep.Value,
+ })
+ cond = cond.And(builder.Exists(builder.Select("pp.ref_id").From("package_property pp").Where(innerCond)))
+ }
+
+ values := make([]string, 0, 5)
+ return values, db.GetEngine(ctx).
+ Table("package_property").
+ Distinct("package_property.value").
+ Join("INNER", "package_file", "package_file.id = package_property.ref_id").
+ Join("INNER", "package_version", "package_version.id = package_file.version_id").
+ Join("INNER", "package", "package.id = package_version.package_id").
+ Where(cond).
+ Find(&values)
+}