0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-27 09:54:15 -05:00
forgejo/services/webhook/gogs.go

43 lines
1.2 KiB
Go
Raw Normal View History

2024-03-20 09:44:01 -05:00
// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
// SPDX-License-Identifier: MIT
package webhook
import (
"html/template"
2024-03-21 08:09:49 -05:00
"net/http"
webhook_model "code.gitea.io/gitea/models/webhook"
2024-03-20 09:44:01 -05:00
webhook_module "code.gitea.io/gitea/modules/webhook"
2024-03-21 08:09:49 -05:00
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/webhook/shared"
2024-03-20 09:44:01 -05:00
)
type gogsHandler struct{ defaultHandler }
func (gogsHandler) Type() webhook_module.HookType { return webhook_module.GOGS }
func (gogsHandler) Icon(size int) template.HTML { return shared.ImgIcon("gogs.ico", size) }
2024-03-21 08:09:49 -05:00
func (gogsHandler) UnmarshalForm(bind func(any)) forms.WebhookForm {
2024-03-21 08:09:49 -05:00
var form struct {
forms.WebhookCoreForm
2024-03-21 08:09:49 -05:00
PayloadURL string `binding:"Required;ValidUrl"`
ContentType int `binding:"Required"`
Secret string
}
bind(&form)
contentType := webhook_model.ContentTypeJSON
if webhook_model.HookContentType(form.ContentType) == webhook_model.ContentTypeForm {
contentType = webhook_model.ContentTypeForm
}
return forms.WebhookForm{
WebhookCoreForm: form.WebhookCoreForm,
URL: form.PayloadURL,
ContentType: contentType,
Secret: form.Secret,
HTTPMethod: http.MethodPost,
Metadata: nil,
2024-03-21 08:09:49 -05:00
}
}