mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-17 14:00:01 +02:00
* Added properties for packages. * Fixed authenticate header format. * Added _catalog endpoint. * Check owner visibility. * Extracted condition. * Added test for _catalog. Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
d1e53bfd7f
commit
97a8c96c5b
22 changed files with 374 additions and 85 deletions
|
@ -131,6 +131,12 @@ func TryInsertPackage(ctx context.Context, p *Package) (*Package, error) {
|
|||
return p, nil
|
||||
}
|
||||
|
||||
// DeletePackageByID deletes a package by id
|
||||
func DeletePackageByID(ctx context.Context, packageID int64) error {
|
||||
_, err := db.GetEngine(ctx).ID(packageID).Delete(&Package{})
|
||||
return err
|
||||
}
|
||||
|
||||
// SetRepositoryLink sets the linked repository
|
||||
func SetRepositoryLink(ctx context.Context, packageID, repoID int64) error {
|
||||
_, err := db.GetEngine(ctx).ID(packageID).Cols("repo_id").Update(&Package{RepoID: repoID})
|
||||
|
@ -192,21 +198,20 @@ func GetPackagesByType(ctx context.Context, ownerID int64, packageType Type) ([]
|
|||
Find(&ps)
|
||||
}
|
||||
|
||||
// DeletePackagesIfUnreferenced deletes a package if there are no associated versions
|
||||
func DeletePackagesIfUnreferenced(ctx context.Context) error {
|
||||
// FindUnreferencedPackages gets all packages without associated versions
|
||||
func FindUnreferencedPackages(ctx context.Context) ([]*Package, error) {
|
||||
in := builder.
|
||||
Select("package.id").
|
||||
From("package").
|
||||
LeftJoin("package_version", "package_version.package_id = package.id").
|
||||
Where(builder.Expr("package_version.id IS NULL"))
|
||||
|
||||
_, err := db.GetEngine(ctx).
|
||||
ps := make([]*Package, 0, 10)
|
||||
return ps, db.GetEngine(ctx).
|
||||
// double select workaround for MySQL
|
||||
// https://stackoverflow.com/questions/4471277/mysql-delete-from-with-subquery-as-condition
|
||||
Where(builder.In("package.id", builder.Select("id").From(in, "temp"))).
|
||||
Delete(&Package{})
|
||||
|
||||
return err
|
||||
Find(&ps)
|
||||
}
|
||||
|
||||
// HasOwnerPackages tests if a user/org has packages
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue