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

Merged
Varakh merged 1 commit from feature/state-in-all-event-payloads into master 2024-04-26 17:40:00 +00:00
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>HOST</VAR>` | The update's host 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

View file

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

View file

@ -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 {

View file

@ -12,4 +12,5 @@ type eventPayloadInformationDto struct {
Application string
Provider 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>HOST</VAR>", eventPayloadInfo.Host)
str = strings.ReplaceAll(str, "<VAR>VERSION</VAR>", eventPayloadInfo.Version)
str = strings.ReplaceAll(str, "<VAR>STATE</VAR>", eventPayloadInfo.State)
return str
}

View file

@ -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"))