diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2023-02-18 06:36:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-18 13:36:38 +0800 |
commit | 007d181bb51330c4c24e78c2f40a2e49cae45ed9 (patch) | |
tree | f648d425957f22d197c91c0deb07e1d10ae953ed | |
parent | 8bba7e30b2833d750af0345b75a3998785ef55ef (diff) | |
download | gitea-007d181bb51330c4c24e78c2f40a2e49cae45ed9.tar.gz gitea-007d181bb51330c4c24e78c2f40a2e49cae45ed9.zip |
Notify on container image create (#22806)
Fixes #22791
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r-- | routers/api/packages/container/manifest.go | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/routers/api/packages/container/manifest.go b/routers/api/packages/container/manifest.go index 6167d00f31..e36c6a851b 100644 --- a/routers/api/packages/container/manifest.go +++ b/routers/api/packages/container/manifest.go @@ -17,6 +17,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" packages_module "code.gitea.io/gitea/modules/packages" container_module "code.gitea.io/gitea/modules/packages/container" "code.gitea.io/gitea/modules/util" @@ -71,11 +72,9 @@ func processManifest(mci *manifestCreationInfo, buf *packages_module.HashedBuffe } if isImageManifestMediaType(mci.MediaType) { - d, err := processImageManifest(mci, buf) - return d, err + return processImageManifest(mci, buf) } else if isImageIndexMediaType(mci.MediaType) { - d, err := processImageManifestIndex(mci, buf) - return d, err + return processImageManifestIndex(mci, buf) } return "", errManifestInvalid } @@ -182,6 +181,10 @@ func processImageManifest(mci *manifestCreationInfo, buf *packages_module.Hashed return err } + if err := notifyPackageCreate(mci.Creator, pv); err != nil { + return err + } + manifestDigest = digest return nil @@ -271,6 +274,10 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H return err } + if err := notifyPackageCreate(mci.Creator, pv); err != nil { + return err + } + manifestDigest = digest return nil @@ -282,6 +289,17 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H 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(db.DefaultContext, doer, pd) + + return nil +} + func createPackageAndVersion(ctx context.Context, mci *manifestCreationInfo, metadata *container_module.Metadata) (*packages_model.PackageVersion, error) { created := true p := &packages_model.Package{ |