aboutsummaryrefslogtreecommitdiffstats
path: root/models/webhook_slack.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_slack.go
parent8bb0a6f425f994addc2822a21e0dca60e8c5251a (diff)
downloadgitea-945804f800ac4e81c46bde848616e9d9392a9571.tar.gz
gitea-945804f800ac4e81c46bde848616e9d9392a9571.zip
Webhook for Pull Request approval/rejection (#5027)
Diffstat (limited to 'models/webhook_slack.go')
-rw-r--r--models/webhook_slack.go33
1 files changed, 31 insertions, 2 deletions
diff --git a/models/webhook_slack.go b/models/webhook_slack.go
index 23df17bf2c..3a21f98601 100644
--- a/models/webhook_slack.go
+++ b/models/webhook_slack.go
@@ -11,9 +11,8 @@ import (
"strings"
"code.gitea.io/git"
- api "code.gitea.io/sdk/gitea"
-
"code.gitea.io/gitea/modules/setting"
+ api "code.gitea.io/sdk/gitea"
)
// SlackMeta contains the slack metadata
@@ -328,6 +327,34 @@ func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*S
}, nil
}
+func getSlackPullRequestApprovalPayload(p *api.PullRequestPayload, slack *SlackMeta, event HookEventType) (*SlackPayload, error) {
+ senderLink := SlackLinkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName)
+ titleLink := SlackLinkFormatter(fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index),
+ fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title))
+ var text, title, attachmentText string
+ switch p.Action {
+ case api.HookIssueSynchronized:
+ action, err := parseHookPullRequestEventType(event)
+ if err != nil {
+ return nil, err
+ }
+
+ text = fmt.Sprintf("[%s] Pull request review %s : %s by %s", p.Repository.FullName, action, titleLink, senderLink)
+ }
+
+ return &SlackPayload{
+ Channel: slack.Channel,
+ Text: text,
+ Username: slack.Username,
+ IconURL: slack.IconURL,
+ Attachments: []SlackAttachment{{
+ Color: slack.Color,
+ Title: title,
+ Text: attachmentText,
+ }},
+ }, nil
+}
+
func getSlackRepositoryPayload(p *api.RepositoryPayload, slack *SlackMeta) (*SlackPayload, error) {
senderLink := SlackLinkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName)
var text, title, attachmentText string
@@ -376,6 +403,8 @@ func GetSlackPayload(p api.Payloader, event HookEventType, meta string) (*SlackP
return getSlackPushPayload(p.(*api.PushPayload), slack)
case HookEventPullRequest:
return getSlackPullRequestPayload(p.(*api.PullRequestPayload), slack)
+ case HookEventPullRequestRejected, HookEventPullRequestApproved, HookEventPullRequestComment:
+ return getSlackPullRequestApprovalPayload(p.(*api.PullRequestPayload), slack, event)
case HookEventRepository:
return getSlackRepositoryPayload(p.(*api.RepositoryPayload), slack)
case HookEventRelease: