From 1cb00ed5929a1e0184e9d12880887a1d7aa10571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Mon, 20 Mar 2023 15:13:46 +0100 Subject: [PATCH] api/webhooks: Deliver PATCHSET_RECEIVED user webhooks --- api/graph/schema.resolvers.go | 7 +++++++ api/webhooks/webhooks.go | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go index 3c24e4c..a70c613 100644 --- a/api/graph/schema.resolvers.go +++ b/api/graph/schema.resolvers.go @@ -1288,6 +1288,13 @@ func (r *mutationResolver) TriggerUserEmailWebhooks(ctx context.Context, emailID return nil, err } webhooks.DeliverUserEmailEvent(ctx, model.WebhookEventEmailReceived, email) + if email.PatchsetID != nil { + patchset, err := loaders.ForContext(ctx).PatchsetsByID.Load(*email.PatchsetID) + if err != nil { + return nil, err + } + webhooks.DeliverUserPatchsetEvent(ctx, model.WebhookEventPatchsetReceived, patchset) + } return email, nil } diff --git a/api/webhooks/webhooks.go b/api/webhooks/webhooks.go index 5b2b731..5f833bf 100644 --- a/api/webhooks/webhooks.go +++ b/api/webhooks/webhooks.go @@ -73,6 +73,18 @@ func DeliverUserEmailEvent(ctx context.Context, deliverUserWebhook(ctx, event, &payload, payloadUUID) } +func DeliverUserPatchsetEvent(ctx context.Context, + event model.WebhookEvent, patchset *model.Patchset) { + payloadUUID := uuid.New() + payload := model.PatchsetEvent{ + UUID: payloadUUID.String(), + Event: event, + Date: time.Now().UTC(), + Patchset: patchset, + } + deliverUserWebhook(ctx, event, &payload, payloadUUID) +} + func DeliverMailingListEvent(ctx context.Context, event model.WebhookEvent, list *model.MailingList) { payloadUUID := uuid.New() -- 2.45.2