2020-09-05 08:27:13 +05:30
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2020-09-05 08:27:13 +05:30
|
|
|
|
|
|
|
package webhook
|
|
|
|
|
|
|
|
import (
|
2021-11-10 10:43:16 +05:30
|
|
|
webhook_model "code.gitea.io/gitea/models/webhook"
|
2020-09-05 08:27:13 +05:30
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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)
|
2021-11-10 10:43:16 +05:30
|
|
|
Review(*api.PullRequestPayload, webhook_model.HookEventType) (api.Payloader, error)
|
2020-09-05 08:27:13 +05:30
|
|
|
Repository(*api.RepositoryPayload) (api.Payloader, error)
|
|
|
|
Release(*api.ReleasePayload) (api.Payloader, error)
|
2022-09-05 01:24:23 +05:30
|
|
|
Wiki(*api.WikiPayload) (api.Payloader, error)
|
2020-09-05 08:27:13 +05:30
|
|
|
}
|
|
|
|
|
2021-11-10 10:43:16 +05:30
|
|
|
func convertPayloader(s PayloadConvertor, p api.Payloader, event webhook_model.HookEventType) (api.Payloader, error) {
|
2020-09-05 08:27:13 +05:30
|
|
|
switch event {
|
2021-11-10 10:43:16 +05:30
|
|
|
case webhook_model.HookEventCreate:
|
2020-09-05 08:27:13 +05:30
|
|
|
return s.Create(p.(*api.CreatePayload))
|
2021-11-10 10:43:16 +05:30
|
|
|
case webhook_model.HookEventDelete:
|
2020-09-05 08:27:13 +05:30
|
|
|
return s.Delete(p.(*api.DeletePayload))
|
2021-11-10 10:43:16 +05:30
|
|
|
case webhook_model.HookEventFork:
|
2020-09-05 08:27:13 +05:30
|
|
|
return s.Fork(p.(*api.ForkPayload))
|
2021-11-10 10:43:16 +05:30
|
|
|
case webhook_model.HookEventIssues, webhook_model.HookEventIssueAssign, webhook_model.HookEventIssueLabel, webhook_model.HookEventIssueMilestone:
|
2020-09-05 08:27:13 +05:30
|
|
|
return s.Issue(p.(*api.IssuePayload))
|
2021-11-10 10:43:16 +05:30
|
|
|
case webhook_model.HookEventIssueComment, webhook_model.HookEventPullRequestComment:
|
2020-09-05 08:27:13 +05:30
|
|
|
pl, ok := p.(*api.IssueCommentPayload)
|
|
|
|
if ok {
|
|
|
|
return s.IssueComment(pl)
|
|
|
|
}
|
|
|
|
return s.PullRequest(p.(*api.PullRequestPayload))
|
2021-11-10 10:43:16 +05:30
|
|
|
case webhook_model.HookEventPush:
|
2020-09-05 08:27:13 +05:30
|
|
|
return s.Push(p.(*api.PushPayload))
|
2021-11-10 10:43:16 +05:30
|
|
|
case webhook_model.HookEventPullRequest, webhook_model.HookEventPullRequestAssign, webhook_model.HookEventPullRequestLabel,
|
|
|
|
webhook_model.HookEventPullRequestMilestone, webhook_model.HookEventPullRequestSync:
|
2020-09-05 08:27:13 +05:30
|
|
|
return s.PullRequest(p.(*api.PullRequestPayload))
|
2021-11-10 10:43:16 +05:30
|
|
|
case webhook_model.HookEventPullRequestReviewApproved, webhook_model.HookEventPullRequestReviewRejected, webhook_model.HookEventPullRequestReviewComment:
|
2020-09-05 08:27:13 +05:30
|
|
|
return s.Review(p.(*api.PullRequestPayload), event)
|
2021-11-10 10:43:16 +05:30
|
|
|
case webhook_model.HookEventRepository:
|
2020-09-05 08:27:13 +05:30
|
|
|
return s.Repository(p.(*api.RepositoryPayload))
|
2021-11-10 10:43:16 +05:30
|
|
|
case webhook_model.HookEventRelease:
|
2020-09-05 08:27:13 +05:30
|
|
|
return s.Release(p.(*api.ReleasePayload))
|
2022-09-05 01:24:23 +05:30
|
|
|
case webhook_model.HookEventWiki:
|
|
|
|
return s.Wiki(p.(*api.WikiPayload))
|
2020-09-05 08:27:13 +05:30
|
|
|
}
|
|
|
|
return s, nil
|
|
|
|
}
|