Skip to content

Commit f523372

Browse files
jolheisersapk
authored andcommitted
Add PR review webhook to Telegram (#9653) (#9655)
Signed-off-by: jolheiser <[email protected]> Co-authored-by: Antoine GIRARD <[email protected]> Co-authored-by: Antoine GIRARD <[email protected]>
1 parent e39c238 commit f523372

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

modules/webhook/telegram.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,25 @@ func getTelegramPullRequestPayload(p *api.PullRequestPayload) (*TelegramPayload,
148148
}, nil
149149
}
150150

151+
func getTelegramPullRequestApprovalPayload(p *api.PullRequestPayload, event models.HookEventType) (*TelegramPayload, error) {
152+
var text, attachmentText string
153+
switch p.Action {
154+
case api.HookIssueSynchronized:
155+
action, err := parseHookPullRequestEventType(event)
156+
if err != nil {
157+
return nil, err
158+
}
159+
160+
text = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
161+
attachmentText = p.Review.Content
162+
163+
}
164+
165+
return &TelegramPayload{
166+
Message: text + "\n" + attachmentText,
167+
}, nil
168+
}
169+
151170
func getTelegramRepositoryPayload(p *api.RepositoryPayload) (*TelegramPayload, error) {
152171
var title string
153172
switch p.Action {
@@ -192,6 +211,8 @@ func GetTelegramPayload(p api.Payloader, event models.HookEventType, meta string
192211
return getTelegramPushPayload(p.(*api.PushPayload))
193212
case models.HookEventPullRequest:
194213
return getTelegramPullRequestPayload(p.(*api.PullRequestPayload))
214+
case models.HookEventPullRequestRejected, models.HookEventPullRequestApproved, models.HookEventPullRequestComment:
215+
return getTelegramPullRequestApprovalPayload(p.(*api.PullRequestPayload), event)
195216
case models.HookEventRepository:
196217
return getTelegramRepositoryPayload(p.(*api.RepositoryPayload))
197218
case models.HookEventRelease:

0 commit comments

Comments
 (0)