feat(actions): Add support for <VAR>STATE</VAR> (#24)

Reviewed-on: #24
Co-authored-by: Varakh <varakh@varakh.de>
Co-committed-by: Varakh <varakh@varakh.de>
This commit is contained in:
Varakh 2024-04-26 17:40:00 +00:00
parent 5d9fe621d8
commit f231e66e7c
6 changed files with 17 additions and 6 deletions

View file

@ -258,6 +258,7 @@ occurrence is replaced before invocation as well.
| `<VAR>PROVIDER</VAR>` | The update's provider name invoking the action | | `<VAR>PROVIDER</VAR>` | The update's provider name invoking the action |
| `<VAR>HOST</VAR>` | The update's host invoking the action | | `<VAR>HOST</VAR>` | The update's host invoking the action |
| `<VAR>VERSION</VAR>` | The update's version (latest) invoking the action | | `<VAR>VERSION</VAR>` | The update's version (latest) invoking the action |
| `<VAR>STATE</VAR>` | The update's state invoking the action |
#### shoutrrr #### shoutrrr

View file

@ -2403,6 +2403,12 @@ components:
type: string type: string
version: version:
type: string type: string
state:
type: string
enum:
- pending
- approved
- ignored
ActionResponse: ActionResponse:
type: object type: object
properties: properties:

View file

@ -339,6 +339,7 @@ type EventPayloadUpdateDeletedDto struct {
Provider string `json:"provider,omitempty"` Provider string `json:"provider,omitempty"`
Host string `json:"host,omitempty"` Host string `json:"host,omitempty"`
Version string `json:"version,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 { func NewEventWindowResponse(content []*EventResponse, size int, skip int, orderBy string, order string, hasNext bool) *EventWindowResponse {

View file

@ -12,4 +12,5 @@ type eventPayloadInformationDto struct {
Application string Application string
Provider string Provider string
Version string Version string
State string
} }

View file

@ -256,6 +256,7 @@ func (s *actionInvocationService) replaceVars(str string, eventPayloadInfo *even
str = strings.ReplaceAll(str, "<VAR>PROVIDER</VAR>", eventPayloadInfo.Provider) str = strings.ReplaceAll(str, "<VAR>PROVIDER</VAR>", eventPayloadInfo.Provider)
str = strings.ReplaceAll(str, "<VAR>HOST</VAR>", eventPayloadInfo.Host) str = strings.ReplaceAll(str, "<VAR>HOST</VAR>", eventPayloadInfo.Host)
str = strings.ReplaceAll(str, "<VAR>VERSION</VAR>", eventPayloadInfo.Version) str = strings.ReplaceAll(str, "<VAR>VERSION</VAR>", eventPayloadInfo.Version)
str = strings.ReplaceAll(str, "<VAR>STATE</VAR>", eventPayloadInfo.State)
return str return str
} }

View file

@ -82,6 +82,7 @@ func (s *eventService) createUpdateDeleted(e *Update) *Event {
Provider: e.Provider, Provider: e.Provider,
Host: e.Host, Host: e.Host,
Version: e.Version, Version: e.Version,
State: e.State,
}) })
return nil return nil
@ -210,37 +211,37 @@ func (s *eventService) extractPayloadInfo(event *Event) (*eventPayloadInformatio
if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateCreatedDto](bytes); err != nil { if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateCreatedDto](bytes); err != nil {
return nil, newServiceError(General, err) 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(): case api.EventNameUpdateDeleted.Value():
var p api.EventPayloadUpdateDeletedDto var p api.EventPayloadUpdateDeletedDto
if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateDeletedDto](bytes); err != nil { if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateDeletedDto](bytes); err != nil {
return nil, newServiceError(General, err) 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(): case api.EventNameUpdateUpdatedApproved.Value():
var p api.EventPayloadUpdateUpdatedDto var p api.EventPayloadUpdateUpdatedDto
if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil { if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil {
return nil, newServiceError(General, err) 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(): case api.EventNameUpdateUpdatedPending.Value():
var p api.EventPayloadUpdateUpdatedDto var p api.EventPayloadUpdateUpdatedDto
if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil { if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil {
return nil, newServiceError(General, err) 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(): case api.EventNameUpdateUpdatedIgnored.Value():
var p api.EventPayloadUpdateUpdatedDto var p api.EventPayloadUpdateUpdatedDto
if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil { if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil {
return nil, newServiceError(General, err) 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(): case api.EventNameUpdateUpdated.Value():
var p api.EventPayloadUpdateUpdatedDto var p api.EventPayloadUpdateUpdatedDto
if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil { if p, err = util.UnmarshalGenericJSON[api.EventPayloadUpdateUpdatedDto](bytes); err != nil {
return nil, newServiceError(General, err) 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")) return nil, newServiceError(General, errors.New("no matching event found"))