From c0928c4128c7b5e8ecc98e121ac9fbcdaaa1761e Mon Sep 17 00:00:00 2001 From: Varakh Date: Sat, 27 Apr 2024 09:49:24 +0200 Subject: [PATCH] feat(actions): introduce an explicit event for changes of an update's version --- README.md | 13 +++++++------ _doc/api.yaml | 1 + api/constants.go | 9 +++++---- server/service_event.go | 16 ++++++++++++---- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9dac7e6..85380b4 100644 --- a/README.md +++ b/README.md @@ -239,12 +239,13 @@ 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` | An update's state changed | -| `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_updated_version` | An update's version 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 56d60d9..1922327 100644 --- a/_doc/api.yaml +++ b/_doc/api.yaml @@ -2331,6 +2331,7 @@ components: - update_created - update_updated - update_updated_state + - update_updated_version - update_deleted createdAt: type: string diff --git a/api/constants.go b/api/constants.go index 779a32e..baec016 100644 --- a/api/constants.go +++ b/api/constants.go @@ -39,10 +39,11 @@ func (e WebhookType) Value() string { type EventName string const ( - EventNameUpdateCreated EventName = "update_created" - EventNameUpdateUpdated EventName = "update_updated" - EventNameUpdateUpdatedState EventName = "update_updated_state" - EventNameUpdateDeleted EventName = "update_deleted" + EventNameUpdateCreated EventName = "update_created" + EventNameUpdateUpdated EventName = "update_updated" + EventNameUpdateUpdatedState EventName = "update_updated_state" + EventNameUpdateUpdatedVersion EventName = "update_updated_version" + EventNameUpdateDeleted EventName = "update_deleted" ) func (e *EventName) Scan(value interface{}) error { diff --git a/server/service_event.go b/server/service_event.go index c94802b..634ce5b 100644 --- a/server/service_event.go +++ b/server/service_event.go @@ -40,14 +40,16 @@ func (s *eventService) createUpdateUpdated(old *Update, new *Update) *Event { return nil } - var eventName api.EventName + eventName := api.EventNameUpdateUpdated - if old.State == new.State { - eventName = api.EventNameUpdateUpdated - } else { + if old.State != new.State { eventName = api.EventNameUpdateUpdatedState } + if old.Version != new.Version { + eventName = api.EventNameUpdateUpdatedVersion + } + s.createWithWarnOnly(eventName, &api.EventPayloadUpdateUpdatedDto{ ID: new.ID, Application: new.Application, @@ -214,6 +216,12 @@ 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.EventNameUpdateUpdatedVersion.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.EventNameUpdateUpdated.Value(): var p api.EventPayloadUpdateUpdatedDto if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil {