Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-30 22:06:11 +01:00

Notify on container image create (#22806) (#22965)

Backport #22806

Fixes #22791

---------

Signed-off-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Yarden Shoham 2023-02-18 15:54:22 +02:00 committed by GitHub
parent 98b7714c3b
commit b2e58edd74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,7 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
container_module "code.gitea.io/gitea/modules/packages/container" container_module "code.gitea.io/gitea/modules/packages/container"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -72,11 +73,9 @@ func processManifest(mci *manifestCreationInfo, buf *packages_module.HashedBuffe
} }
if isImageManifestMediaType(mci.MediaType) { if isImageManifestMediaType(mci.MediaType) {
d, err := processImageManifest(mci, buf) return processImageManifest(mci, buf)
return d, err
} else if isImageIndexMediaType(mci.MediaType) { } else if isImageIndexMediaType(mci.MediaType) {
d, err := processImageManifestIndex(mci, buf) return processImageManifestIndex(mci, buf)
return d, err
} }
return "", errManifestInvalid return "", errManifestInvalid
} }
@ -183,6 +182,10 @@ func processImageManifest(mci *manifestCreationInfo, buf *packages_module.Hashed
return err return err
} }
if err := notifyPackageCreate(mci.Creator, pv); err != nil {
return err
}
manifestDigest = digest manifestDigest = digest
return nil return nil
@ -272,6 +275,10 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H
return err return err
} }
if err := notifyPackageCreate(mci.Creator, pv); err != nil {
return err
}
manifestDigest = digest manifestDigest = digest
return nil return nil
@ -283,6 +290,17 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H
return manifestDigest, nil return manifestDigest, nil
} }
func notifyPackageCreate(doer *user_model.User, pv *packages_model.PackageVersion) error {
pd, err := packages_model.GetPackageDescriptor(db.DefaultContext, pv)
if err != nil {
return err
}
notification.NotifyPackageCreate(doer, pd)
return nil
}
func createPackageAndVersion(ctx context.Context, mci *manifestCreationInfo, metadata *container_module.Metadata) (*packages_model.PackageVersion, error) { func createPackageAndVersion(ctx context.Context, mci *manifestCreationInfo, metadata *container_module.Metadata) (*packages_model.PackageVersion, error) {
created := true created := true
p := &packages_model.Package{ p := &packages_model.Package{