From 9bd4255d00e565203181b4eb96e7bb8c45b307b9 Mon Sep 17 00:00:00 2001 From: Varakh Date: Fri, 26 Apr 2024 19:34:07 +0200 Subject: [PATCH] feat(actions): Add support for STATE --- README.md | 1 + _doc/api.yaml | 6 ++++++ api/dto.go | 1 + server/dto.go | 1 + server/service_action_invocation.go | 1 + server/service_event.go | 13 +++++++------ 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5753ae8..790a1ff 100644 --- a/README.md +++ b/README.md @@ -258,6 +258,7 @@ occurrence is replaced before invocation as well. | `PROVIDER` | The update's provider name invoking the action | | `HOST` | The update's host invoking the action | | `VERSION` | The update's version (latest) invoking the action | +| `STATE` | The update's state invoking the action | #### shoutrrr diff --git a/_doc/api.yaml b/_doc/api.yaml index 2bddf52..b741a93 100644 --- a/_doc/api.yaml +++ b/_doc/api.yaml @@ -2403,6 +2403,12 @@ components: type: string version: type: string + state: + type: string + enum: + - pending + - approved + - ignored ActionResponse: type: object properties: diff --git a/api/dto.go b/api/dto.go index f7cfd2b..0a7c9dc 100644 --- a/api/dto.go +++ b/api/dto.go @@ -339,6 +339,7 @@ type EventPayloadUpdateDeletedDto struct { Provider string `json:"provider,omitempty"` Host string `json:"host,omitempty"` Version string `json:"version,omitempty"` + State string `json:"state,omitempty"` } func NewEventWindowResponse(content []*EventResponse, size int, skip int, orderBy string, order string, hasNext bool) *EventWindowResponse { diff --git a/server/dto.go b/server/dto.go index 1922886..4e3384a 100644 --- a/server/dto.go +++ b/server/dto.go @@ -12,4 +12,5 @@ type eventPayloadInformationDto struct { Application string Provider string Version string + State string } diff --git a/server/service_action_invocation.go b/server/service_action_invocation.go index bc53a07..5d53268 100644 --- a/server/service_action_invocation.go +++ b/server/service_action_invocation.go @@ -256,6 +256,7 @@ func (s *actionInvocationService) replaceVars(str string, eventPayloadInfo *even str = strings.ReplaceAll(str, "PROVIDER", eventPayloadInfo.Provider) str = strings.ReplaceAll(str, "HOST", eventPayloadInfo.Host) str = strings.ReplaceAll(str, "VERSION", eventPayloadInfo.Version) + str = strings.ReplaceAll(str, "STATE", eventPayloadInfo.State) return str } diff --git a/server/service_event.go b/server/service_event.go index 0af848e..92bd38a 100644 --- a/server/service_event.go +++ b/server/service_event.go @@ -82,6 +82,7 @@ func (s *eventService) createUpdateDeleted(e *Update) *Event { Provider: e.Provider, Host: e.Host, Version: e.Version, + State: e.State, }) return nil @@ -210,37 +211,37 @@ func (s *eventService) extractPayloadInfo(event *Event) (*eventPayloadInformatio if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateCreatedDto](bytes); err != nil { return nil, newServiceError(General, err) } - return &eventPayloadInformationDto{Host: p.Host, Application: p.Application, Provider: p.Provider, Version: p.Version}, nil + return &eventPayloadInformationDto{Host: p.Host, Application: p.Application, Provider: p.Provider, Version: p.Version, State: p.State}, nil case api.EventNameUpdateDeleted.Value(): var p api.EventPayloadUpdateDeletedDto if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateDeletedDto](bytes); err != nil { return nil, newServiceError(General, err) } - return &eventPayloadInformationDto{Host: p.Host, Application: p.Application, Provider: p.Provider, Version: p.Version}, nil + 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}, nil + 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}, nil + return &eventPayloadInformationDto{Host: p.Host, Application: p.Application, Provider: p.Provider, Version: p.Version, State: p.State}, nil case api.EventNameUpdateUpdatedIgnored.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}, nil + 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 { return nil, newServiceError(General, err) } - return &eventPayloadInformationDto{Host: p.Host, Application: p.Application, Provider: p.Provider, Version: p.Version}, nil + return &eventPayloadInformationDto{Host: p.Host, Application: p.Application, Provider: p.Provider, Version: p.Version, State: p.State}, nil } return nil, newServiceError(General, errors.New("no matching event found"))