2020-09-05 04:57:13 +02:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-09-05 04:57:13 +02:00
|
|
|
|
|
|
|
package webhook
|
|
|
|
|
|
|
|
import (
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2023-01-01 16:23:15 +01:00
|
|
|
webhook_module "code.gitea.io/gitea/modules/webhook"
|
2020-09-05 04:57:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// PayloadConvertor defines the interface to convert system webhook payload to external payload
|
|
|
|
type PayloadConvertor interface {
|
|
|
|
api.Payloader
|
|
|
|
Create(*api.CreatePayload) (api.Payloader, error)
|
|
|
|
Delete(*api.DeletePayload) (api.Payloader, error)
|
|
|
|
Fork(*api.ForkPayload) (api.Payloader, error)
|
|
|
|
Issue(*api.IssuePayload) (api.Payloader, error)
|
|
|
|
IssueComment(*api.IssueCommentPayload) (api.Payloader, error)
|
|
|
|
Push(*api.PushPayload) (api.Payloader, error)
|
|
|
|
PullRequest(*api.PullRequestPayload) (api.Payloader, error)
|
2023-01-01 16:23:15 +01:00
|
|
|
Review(*api.PullRequestPayload, webhook_module.HookEventType) (api.Payloader, error)
|
2020-09-05 04:57:13 +02:00
|
|
|
Repository(*api.RepositoryPayload) (api.Payloader, error)
|
|
|
|
Release(*api.ReleasePayload) (api.Payloader, error)
|
2022-09-04 21:54:23 +02:00
|
|
|
Wiki(*api.WikiPayload) (api.Payloader, error)
|
2023-10-31 05:43:38 +01:00
|
|
|
Package(*api.PackagePayload) (api.Payloader, error)
|
2020-09-05 04:57:13 +02:00
|
|
|
}
|
|
|
|
|
2023-01-01 16:23:15 +01:00
|
|
|
func convertPayloader(s PayloadConvertor, p api.Payloader, event webhook_module.HookEventType) (api.Payloader, error) {
|
2020-09-05 04:57:13 +02:00
|
|
|
switch event {
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventCreate:
|
2020-09-05 04:57:13 +02:00
|
|
|
return s.Create(p.(*api.CreatePayload))
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventDelete:
|
2020-09-05 04:57:13 +02:00
|
|
|
return s.Delete(p.(*api.DeletePayload))
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventFork:
|
2020-09-05 04:57:13 +02:00
|
|
|
return s.Fork(p.(*api.ForkPayload))
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventIssues, webhook_module.HookEventIssueAssign, webhook_module.HookEventIssueLabel, webhook_module.HookEventIssueMilestone:
|
2020-09-05 04:57:13 +02:00
|
|
|
return s.Issue(p.(*api.IssuePayload))
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventIssueComment, webhook_module.HookEventPullRequestComment:
|
2020-09-05 04:57:13 +02:00
|
|
|
pl, ok := p.(*api.IssueCommentPayload)
|
|
|
|
if ok {
|
|
|
|
return s.IssueComment(pl)
|
|
|
|
}
|
|
|
|
return s.PullRequest(p.(*api.PullRequestPayload))
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventPush:
|
2020-09-05 04:57:13 +02:00
|
|
|
return s.Push(p.(*api.PushPayload))
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventPullRequest, webhook_module.HookEventPullRequestAssign, webhook_module.HookEventPullRequestLabel,
|
2023-05-25 04:06:27 +02:00
|
|
|
webhook_module.HookEventPullRequestMilestone, webhook_module.HookEventPullRequestSync, webhook_module.HookEventPullRequestReviewRequest:
|
2020-09-05 04:57:13 +02:00
|
|
|
return s.PullRequest(p.(*api.PullRequestPayload))
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventPullRequestReviewApproved, webhook_module.HookEventPullRequestReviewRejected, webhook_module.HookEventPullRequestReviewComment:
|
2020-09-05 04:57:13 +02:00
|
|
|
return s.Review(p.(*api.PullRequestPayload), event)
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventRepository:
|
2020-09-05 04:57:13 +02:00
|
|
|
return s.Repository(p.(*api.RepositoryPayload))
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventRelease:
|
2020-09-05 04:57:13 +02:00
|
|
|
return s.Release(p.(*api.ReleasePayload))
|
2023-01-01 16:23:15 +01:00
|
|
|
case webhook_module.HookEventWiki:
|
2022-09-04 21:54:23 +02:00
|
|
|
return s.Wiki(p.(*api.WikiPayload))
|
2023-10-31 05:43:38 +01:00
|
|
|
case webhook_module.HookEventPackage:
|
|
|
|
return s.Package(p.(*api.PackagePayload))
|
2020-09-05 04:57:13 +02:00
|
|
|
}
|
|
|
|
return s, nil
|
|
|
|
}
|