diff options
author | Lanre Adelowo <adelowomailbox@gmail.com> | 2018-12-27 19:04:30 +0100 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2018-12-27 13:04:30 -0500 |
commit | 945804f800ac4e81c46bde848616e9d9392a9571 (patch) | |
tree | f137ad55d93b3f0a426e8f1e0340d786daee05c3 /models/webhook_dingtalk.go | |
parent | 8bb0a6f425f994addc2822a21e0dca60e8c5251a (diff) | |
download | gitea-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.go | 29 |
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: |