mirror of
https://github.com/harness/drone.git
synced 2025-04-27 13:13:07 +00:00
status checks: raw and markdown payload kinds
This commit is contained in:
parent
99f6e4334e
commit
b7c339c31e
@ -51,27 +51,29 @@ func (in *ReportInput) Validate() error {
|
||||
}
|
||||
in.Payload.Kind = payloadKind
|
||||
|
||||
//nolint:gocritic // more values to follow on the enum (we want linter warning in case it is missed)
|
||||
switch in.Payload.Kind {
|
||||
case enum.CheckPayloadKindExternal:
|
||||
// the default external type does not support payload: clear it here
|
||||
case enum.CheckPayloadKindEmpty:
|
||||
// the default payload kind (empty) does not support the payload data: clear it here
|
||||
in.Payload.Version = ""
|
||||
in.Payload.Data = []byte("{}")
|
||||
|
||||
var err error
|
||||
|
||||
if in.Link == "" { // the link is mandatory for the external
|
||||
if in.Link == "" { // the link is mandatory as there is nothing in the payload
|
||||
return usererror.BadRequest("Link is missing")
|
||||
}
|
||||
|
||||
case enum.CheckPayloadKindRaw, enum.CheckPayloadKindMarkdown:
|
||||
// the text payload kinds (raw and markdown) do not support the version
|
||||
if in.Payload.Version != "" {
|
||||
return usererror.BadRequest("Payload version must be empty")
|
||||
return usererror.BadRequestf("Payload version must be empty for the payload kind '%s'",
|
||||
in.Payload.Kind)
|
||||
}
|
||||
|
||||
in.Payload.Data, err = sanitizeJsonPayload(in.Payload.Data, &struct {
|
||||
Details string `json:"details"`
|
||||
}{})
|
||||
payloadDataJSON, err := sanitizeJsonPayload(in.Payload.Data, &types.CheckPayloadText{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
in.Payload.Data = payloadDataJSON
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -49,3 +49,7 @@ type ReqCheck struct {
|
||||
|
||||
AddedBy PrincipalInfo `json:"added_by"`
|
||||
}
|
||||
|
||||
type CheckPayloadText struct {
|
||||
Details string `json:"details"`
|
||||
}
|
||||
|
@ -36,14 +36,18 @@ func (s CheckPayloadKind) Sanitize() (CheckPayloadKind, bool) {
|
||||
return Sanitize(s, GetAllCheckPayloadTypes)
|
||||
}
|
||||
func GetAllCheckPayloadTypes() ([]CheckPayloadKind, CheckPayloadKind) {
|
||||
return checkPayloadTypes, CheckPayloadKindExternal
|
||||
return checkPayloadTypes, CheckPayloadKindEmpty
|
||||
}
|
||||
|
||||
// CheckPayloadKind enumeration.
|
||||
const (
|
||||
CheckPayloadKindExternal CheckPayloadKind = "external"
|
||||
CheckPayloadKindEmpty CheckPayloadKind = ""
|
||||
CheckPayloadKindRaw CheckPayloadKind = "raw"
|
||||
CheckPayloadKindMarkdown CheckPayloadKind = "markdown"
|
||||
)
|
||||
|
||||
var checkPayloadTypes = sortEnum([]CheckPayloadKind{
|
||||
CheckPayloadKindExternal,
|
||||
CheckPayloadKindEmpty,
|
||||
CheckPayloadKindRaw,
|
||||
CheckPayloadKindMarkdown,
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user