From 10bc3a59bb425461ee8ba1654f73b0fbecc47c1e Mon Sep 17 00:00:00 2001 From: Varakh Date: Fri, 26 Apr 2024 19:45:51 +0000 Subject: [PATCH] feat(updates,events): Streamline update state changes into one event type only (#27) Reviewed-on: https://git.myservermanager.com/varakh/upda/pulls/27 Co-authored-by: Varakh Co-committed-by: Varakh --- README.md | 14 ++++++-------- _doc/api.yaml | 4 +--- api/constants.go | 10 ++++------ server/service_event.go | 26 ++------------------------ 4 files changed, 13 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 5692f61..9dac7e6 100644 --- a/README.md +++ b/README.md @@ -239,14 +239,12 @@ action type, which can send notifications to a variety of services like Gotify, Supported events are the following: -| Event name | Description | -|:--------------------------------|:--------------------------------------------------------------------| -| `update_created` | An update has been created | -| `update_updated` | An update has been updated (not necessarily its version attribute!) | -| `update_updated_state_pending` | An update's state changed to pending | -| `update_updated_state_approved` | An update's state changed to approved | -| `update_updated_state_ignored` | An update's state changed to ignored | -| `update_deleted` | An update has been removed | +| Event name | Description | +|:-----------------------|:--------------------------------------------------------------------| +| `update_created` | An update has been created | +| `update_updated` | An update has been updated (not necessarily its version attribute!) | +| `update_updated_state` | An update's state changed | +| `update_deleted` | An update has been removed | For privacy, an action's configuration supports upda's **secrets** vault, which means that before an action is triggered, any occurrence of `SECRET_KEY` is properly replaced by the value of the `SECRET_KEY` defined diff --git a/_doc/api.yaml b/_doc/api.yaml index 04b5803..56d60d9 100644 --- a/_doc/api.yaml +++ b/_doc/api.yaml @@ -2330,9 +2330,7 @@ components: enum: - update_created - update_updated - - update_updated_state_pending - - update_updated_state_approved - - update_updated_state_ignored + - update_updated_state - update_deleted createdAt: type: string diff --git a/api/constants.go b/api/constants.go index d3ce264..779a32e 100644 --- a/api/constants.go +++ b/api/constants.go @@ -39,12 +39,10 @@ func (e WebhookType) Value() string { type EventName string const ( - EventNameUpdateCreated EventName = "update_created" - EventNameUpdateUpdated EventName = "update_updated" - EventNameUpdateUpdatedPending EventName = "update_updated_state_pending" - EventNameUpdateUpdatedApproved EventName = "update_updated_state_approved" - EventNameUpdateUpdatedIgnored EventName = "update_updated_state_ignored" - EventNameUpdateDeleted EventName = "update_deleted" + EventNameUpdateCreated EventName = "update_created" + EventNameUpdateUpdated EventName = "update_updated" + EventNameUpdateUpdatedState EventName = "update_updated_state" + EventNameUpdateDeleted EventName = "update_deleted" ) func (e *EventName) Scan(value interface{}) error { diff --git a/server/service_event.go b/server/service_event.go index 92bd38a..c94802b 100644 --- a/server/service_event.go +++ b/server/service_event.go @@ -45,17 +45,7 @@ func (s *eventService) createUpdateUpdated(old *Update, new *Update) *Event { if old.State == new.State { eventName = api.EventNameUpdateUpdated } else { - switch new.State { - case api.UpdateStatePending.Value(): - eventName = api.EventNameUpdateUpdatedPending - break - case api.UpdateStateApproved.Value(): - eventName = api.EventNameUpdateUpdatedApproved - break - case api.UpdateStateIgnored.Value(): - eventName = api.EventNameUpdateUpdatedIgnored - break - } + eventName = api.EventNameUpdateUpdatedState } s.createWithWarnOnly(eventName, &api.EventPayloadUpdateUpdatedDto{ @@ -218,19 +208,7 @@ func (s *eventService) extractPayloadInfo(event *Event) (*eventPayloadInformatio return nil, newServiceError(General, err) } return &eventPayloadInformationDto{Host: p.Host, Application: p.Application, Provider: p.Provider, Version: p.Version, State: p.State}, nil - case api.EventNameUpdateUpdatedApproved.Value(): - var p api.EventPayloadUpdateUpdatedDto - if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil { - return nil, newServiceError(General, err) - } - return &eventPayloadInformationDto{Host: p.Host, Application: p.Application, Provider: p.Provider, Version: p.Version, State: p.State}, nil - case api.EventNameUpdateUpdatedPending.Value(): - var p api.EventPayloadUpdateUpdatedDto - if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil { - return nil, newServiceError(General, err) - } - return &eventPayloadInformationDto{Host: p.Host, Application: p.Application, Provider: p.Provider, Version: p.Version, State: p.State}, nil - case api.EventNameUpdateUpdatedIgnored.Value(): + case api.EventNameUpdateUpdatedState.Value(): var p api.EventPayloadUpdateUpdatedDto if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil { return nil, newServiceError(General, err)