[REFACTOR] webhook.Handler interface

This commit is contained in:
oliverpool 2024-03-20 15:44:01 +01:00
parent 142459bbe0
commit 702152bfde
35 changed files with 378 additions and 210 deletions

View file

@ -17,6 +17,10 @@ import (
webhook_module "code.gitea.io/gitea/modules/webhook"
)
type telegramHandler struct{}
func (telegramHandler) Type() webhook_module.HookType { return webhook_module.TELEGRAM }
type (
// TelegramPayload represents
TelegramPayload struct {
@ -33,11 +37,11 @@ type (
}
)
// GetTelegramHook returns telegram metadata
func GetTelegramHook(w *webhook_model.Webhook) *TelegramMeta {
// Metadata returns telegram metadata
func (telegramHandler) Metadata(w *webhook_model.Webhook) any {
s := &TelegramMeta{}
if err := json.Unmarshal([]byte(w.Meta), s); err != nil {
log.Error("webhook.GetTelegramHook(%d): %v", w.ID, err)
log.Error("telegramHandler.Metadata(%d): %v", w.ID, err)
}
return s
}
@ -189,6 +193,6 @@ type telegramConvertor struct{}
var _ payloadConvertor[TelegramPayload] = telegramConvertor{}
func newTelegramRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
func (telegramHandler) NewRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
return newJSONRequest(telegramConvertor{}, w, t, true)
}