summaryrefslogtreecommitdiffstats
path: root/models/webhook_dingtalk.go
diff options
context:
space:
mode:
authorLanre Adelowo <adelowomailbox@gmail.com>2018-12-27 19:04:30 +0100
committertechknowlogick <hello@techknowlogick.com>2018-12-27 13:04:30 -0500
commit945804f800ac4e81c46bde848616e9d9392a9571 (patch)
treef137ad55d93b3f0a426e8f1e0340d786daee05c3 /models/webhook_dingtalk.go
parent8bb0a6f425f994addc2822a21e0dca60e8c5251a (diff)
downloadgitea-945804f800ac4e81c46bde848616e9d9392a9571.tar.gz
gitea-945804f800ac4e81c46bde848616e9d9392a9571.zip
Webhook for Pull Request approval/rejection (#5027)
Diffstat (limited to 'models/webhook_dingtalk.go')
-rw-r--r--models/webhook_dingtalk.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/models/webhook_dingtalk.go b/models/webhook_dingtalk.go
index 06388a6ba2..dbbbebcd9a 100644
--- a/models/webhook_dingtalk.go
+++ b/models/webhook_dingtalk.go
@@ -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: