From 6104b31396cea65727421225787df98660a10fa2 Mon Sep 17 00:00:00 2001 From: Ada Luong Date: Fri, 10 Feb 2023 01:07:38 +0000 Subject: [PATCH] Add function to parse analysis complete notification JSON Signed-off-by: Ada Luong --- pkg/notification/notification.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/notification/notification.go b/pkg/notification/notification.go index b6f3a807..5361e068 100644 --- a/pkg/notification/notification.go +++ b/pkg/notification/notification.go @@ -1,6 +1,10 @@ package notification import ( + "encoding/json" + "fmt" + "gocloud.dev/pubsub" + "github.com/ossf/package-analysis/pkg/pkgidentifier" ) @@ -9,3 +13,12 @@ import ( type AnalysisCompletion struct { Package pkgidentifier.PkgIdentifier } + +// ParseJSON takes in a notification JSON and returns an AnalysisCompletion struct. +func ParseJSON(msg *pubsub.Message) (AnalysisCompletion, error) { + notification := AnalysisCompletion{} + if err := json.Unmarshal(msg.Body, ¬ification); err != nil { + return notification, fmt.Errorf("error unmarshalling json: %w", err) + } + return notification, nil +}