diff options
Diffstat (limited to 'models/webhook.go')
-rw-r--r-- | models/webhook.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/models/webhook.go b/models/webhook.go index 3ee517cada..dbaac3e667 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -27,6 +27,16 @@ const ( FORM ) +var hookContentTypes = map[string]HookContentType{ + "json": JSON, + "form": FORM, +} + +// ToHookContentType returns HookContentType by given name. +func ToHookContentType(name string) HookContentType { + return hookContentTypes[name] +} + func (t HookContentType) Name() string { switch t { case JSON: @@ -37,6 +47,12 @@ func (t HookContentType) Name() string { return "" } +// IsValidHookContentType returns true if given name is a valid hook content type. +func IsValidHookContentType(name string) bool { + _, ok := hookContentTypes[name] + return ok +} + // HookEvent represents events that will delivery hook. type HookEvent struct { PushOnly bool `json:"push_only"` @@ -157,6 +173,16 @@ const ( SLACK ) +var hookTaskTypes = map[string]HookTaskType{ + "gogs": GOGS, + "slack": SLACK, +} + +// ToHookTaskType returns HookTaskType by given name. +func ToHookTaskType(name string) HookTaskType { + return hookTaskTypes[name] +} + func (t HookTaskType) Name() string { switch t { case GOGS: @@ -167,6 +193,12 @@ func (t HookTaskType) Name() string { return "" } +// IsValidHookTaskType returns true if given name is a valid hook task type. +func IsValidHookTaskType(name string) bool { + _, ok := hookTaskTypes[name] + return ok +} + type HookEventType string const ( |