mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-15 14:32:42 +00:00
Webhook for Pull Request approval/rejection (#5027)
This commit is contained in:
parent
8bb0a6f425
commit
945804f800
6 changed files with 168 additions and 20 deletions
|
@ -11,7 +11,6 @@ import (
|
|||
|
||||
"code.gitea.io/git"
|
||||
api "code.gitea.io/sdk/gitea"
|
||||
|
||||
dingtalk "github.com/lunny/dingtalk_webhook"
|
||||
)
|
||||
|
||||
|
@ -271,6 +270,32 @@ func getDingtalkPullRequestPayload(p *api.PullRequestPayload) (*DingtalkPayload,
|
|||
}, nil
|
||||
}
|
||||
|
||||
func getDingtalkPullRequestApprovalPayload(p *api.PullRequestPayload, event HookEventType) (*DingtalkPayload, error) {
|
||||
var text, title string
|
||||
switch p.Action {
|
||||
case api.HookIssueSynchronized:
|
||||
action, err := parseHookPullRequestEventType(event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
title = fmt.Sprintf("[%s] Pull request review %s : #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
|
||||
text = p.PullRequest.Body
|
||||
|
||||
}
|
||||
|
||||
return &DingtalkPayload{
|
||||
MsgType: "actionCard",
|
||||
ActionCard: dingtalk.ActionCard{
|
||||
Text: title + "\r\n\r\n" + text,
|
||||
Title: title,
|
||||
HideAvatar: "0",
|
||||
SingleTitle: "view pull request",
|
||||
SingleURL: p.PullRequest.HTMLURL,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getDingtalkRepositoryPayload(p *api.RepositoryPayload) (*DingtalkPayload, error) {
|
||||
var title, url string
|
||||
switch p.Action {
|
||||
|
@ -369,6 +394,8 @@ func GetDingtalkPayload(p api.Payloader, event HookEventType, meta string) (*Din
|
|||
return getDingtalkPushPayload(p.(*api.PushPayload))
|
||||
case HookEventPullRequest:
|
||||
return getDingtalkPullRequestPayload(p.(*api.PullRequestPayload))
|
||||
case HookEventPullRequestApproved, HookEventPullRequestRejected, HookEventPullRequestComment:
|
||||
return getDingtalkPullRequestApprovalPayload(p.(*api.PullRequestPayload), event)
|
||||
case HookEventRepository:
|
||||
return getDingtalkRepositoryPayload(p.(*api.RepositoryPayload))
|
||||
case HookEventRelease:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue