mirror of
https://github.com/harness/drone.git
synced 2025-05-10 07:30:33 +08: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
|
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 {
|
switch in.Payload.Kind {
|
||||||
case enum.CheckPayloadKindExternal:
|
case enum.CheckPayloadKindEmpty:
|
||||||
// the default external type does not support payload: clear it here
|
// 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 as there is nothing in the payload
|
||||||
|
|
||||||
if in.Link == "" { // the link is mandatory for the external
|
|
||||||
return usererror.BadRequest("Link is missing")
|
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 != "" {
|
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 {
|
payloadDataJSON, err := sanitizeJsonPayload(in.Payload.Data, &types.CheckPayloadText{})
|
||||||
Details string `json:"details"`
|
|
||||||
}{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
in.Payload.Data = payloadDataJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -49,3 +49,7 @@ type ReqCheck struct {
|
|||||||
|
|
||||||
AddedBy PrincipalInfo `json:"added_by"`
|
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)
|
return Sanitize(s, GetAllCheckPayloadTypes)
|
||||||
}
|
}
|
||||||
func GetAllCheckPayloadTypes() ([]CheckPayloadKind, CheckPayloadKind) {
|
func GetAllCheckPayloadTypes() ([]CheckPayloadKind, CheckPayloadKind) {
|
||||||
return checkPayloadTypes, CheckPayloadKindExternal
|
return checkPayloadTypes, CheckPayloadKindEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckPayloadKind enumeration.
|
// CheckPayloadKind enumeration.
|
||||||
const (
|
const (
|
||||||
CheckPayloadKindExternal CheckPayloadKind = "external"
|
CheckPayloadKindEmpty CheckPayloadKind = ""
|
||||||
|
CheckPayloadKindRaw CheckPayloadKind = "raw"
|
||||||
|
CheckPayloadKindMarkdown CheckPayloadKind = "markdown"
|
||||||
)
|
)
|
||||||
|
|
||||||
var checkPayloadTypes = sortEnum([]CheckPayloadKind{
|
var checkPayloadTypes = sortEnum([]CheckPayloadKind{
|
||||||
CheckPayloadKindExternal,
|
CheckPayloadKindEmpty,
|
||||||
|
CheckPayloadKindRaw,
|
||||||
|
CheckPayloadKindMarkdown,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user