Webhook for Pull Request approval/rejection (#5027)

This commit is contained in:
Lanre Adelowo 2018-12-27 19:04:30 +01:00 committed by techknowlogick
parent 8bb0a6f425
commit 945804f800
6 changed files with 168 additions and 20 deletions

View file

@ -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: