From 56da256853001cf3538b8d4ae99798e084935a90 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 18 Apr 2019 22:45:02 -0400 Subject: [PATCH] Telegram webhook (#4227) --- models/webhook.go | 18 + models/webhook_telegram.go | 322 ++++++++++++++++++ models/webhook_test.go | 3 + modules/auth/repo_form.go | 12 + modules/setting/webhook.go | 2 +- options/locale/locale_en-US.ini | 3 + public/img/telegram.png | Bin 0 -> 12399 bytes routers/repo/webhook.go | 91 +++++ routers/routes/routes.go | 4 + templates/org/settings/hook_new.tmpl | 3 + templates/repo/settings/webhook/list.tmpl | 3 + templates/repo/settings/webhook/new.tmpl | 3 + templates/repo/settings/webhook/telegram.tmpl | 15 + 13 files changed, 478 insertions(+), 1 deletion(-) create mode 100644 models/webhook_telegram.go create mode 100644 public/img/telegram.png create mode 100644 templates/repo/settings/webhook/telegram.tmpl diff --git a/models/webhook.go b/models/webhook.go index eb22e95975..8db281a15c 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -145,6 +145,15 @@ func (w *Webhook) GetDiscordHook() *DiscordMeta { return s } +// GetTelegramHook returns telegram metadata +func (w *Webhook) GetTelegramHook() *TelegramMeta { + s := &TelegramMeta{} + if err := json.Unmarshal([]byte(w.Meta), s); err != nil { + log.Error("webhook.GetTelegramHook(%d): %v", w.ID, err) + } + return s +} + // History returns history of webhook by given conditions. func (w *Webhook) History(page int) ([]*HookTask, error) { return HookTasks(w.ID, page) @@ -456,6 +465,7 @@ const ( GITEA DISCORD DINGTALK + TELEGRAM ) var hookTaskTypes = map[string]HookTaskType{ @@ -464,6 +474,7 @@ var hookTaskTypes = map[string]HookTaskType{ "slack": SLACK, "discord": DISCORD, "dingtalk": DINGTALK, + "telegram": TELEGRAM, } // ToHookTaskType returns HookTaskType by given name. @@ -484,6 +495,8 @@ func (t HookTaskType) Name() string { return "discord" case DINGTALK: return "dingtalk" + case TELEGRAM: + return "telegram" } return "" } @@ -657,6 +670,11 @@ func prepareWebhook(e Engine, w *Webhook, repo *Repository, event HookEventType, if err != nil { return fmt.Errorf("GetDingtalkPayload: %v", err) } + case TELEGRAM: + payloader, err = GetTelegramPayload(p, event, w.Meta) + if err != nil { + return fmt.Errorf("GetTelegramPayload: %v", err) + } default: p.SetSecret(w.Secret) payloader = p diff --git a/models/webhook_telegram.go b/models/webhook_telegram.go new file mode 100644 index 0000000000..5680c48b85 --- /dev/null +++ b/models/webhook_telegram.go @@ -0,0 +1,322 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package models + +import ( + "encoding/json" + "fmt" + "strings" + + "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/markup" + api "code.gitea.io/sdk/gitea" +) + +type ( + // TelegramPayload represents + TelegramPayload struct { + Message string `json:"text"` + ParseMode string `json:"parse_mode"` + } + + // TelegramMeta contains the telegram metadata + TelegramMeta struct { + BotToken string `json:"bot_token"` + ChatID string `json:"chat_id"` + } +) + +// SetSecret sets the telegram secret +func (p *TelegramPayload) SetSecret(_ string) {} + +// JSONPayload Marshals the TelegramPayload to json +func (p *TelegramPayload) JSONPayload() ([]byte, error) { + p.ParseMode = "HTML" + p.Message = markup.Sanitize(p.Message) + data, err := json.MarshalIndent(p, "", " ") + if err != nil { + return []byte{}, err + } + return data, nil +} + +func getTelegramCreatePayload(p *api.CreatePayload) (*TelegramPayload, error) { + // created tag/branch + refName := git.RefEndName(p.Ref) + title := fmt.Sprintf(`[%s] %s %s created`, p.Repo.HTMLURL, p.Repo.FullName, p.RefType, + p.Repo.HTMLURL+"/src/"+refName, refName) + + return &TelegramPayload{ + Message: title, + }, nil +} + +func getTelegramDeletePayload(p *api.DeletePayload) (*TelegramPayload, error) { + // created tag/branch + refName := git.RefEndName(p.Ref) + title := fmt.Sprintf(`[%s] %s %s deleted`, p.Repo.HTMLURL, p.Repo.FullName, p.RefType, + p.Repo.HTMLURL+"/src/"+refName, refName) + + return &TelegramPayload{ + Message: title, + }, nil +} + +func getTelegramForkPayload(p *api.ForkPayload) (*TelegramPayload, error) { + title := fmt.Sprintf(`%s is forked to %s`, p.Forkee.FullName, p.Repo.HTMLURL, p.Repo.FullName) + + return &TelegramPayload{ + Message: title, + }, nil +} + +func getTelegramPushPayload(p *api.PushPayload) (*TelegramPayload, error) { + var ( + branchName = git.RefEndName(p.Ref) + commitDesc string + ) + + var titleLink string + if len(p.Commits) == 1 { + commitDesc = "1 new commit" + titleLink = p.Commits[0].URL + } else { + commitDesc = fmt.Sprintf("%d new commits", len(p.Commits)) + titleLink = p.CompareURL + } + if titleLink == "" { + titleLink = p.Repo.HTMLURL + "/src/" + branchName + } + title := fmt.Sprintf(`[%s:%s] %s`, p.Repo.HTMLURL, p.Repo.FullName, titleLink, branchName, commitDesc) + + var text string + // for each commit, generate attachment text + for i, commit := range p.Commits { + var authorName string + if commit.Author != nil { + authorName = " - " + commit.Author.Name + } + text += fmt.Sprintf(`[%s] %s`, commit.URL, commit.ID[:7], + strings.TrimRight(commit.Message, "\r\n")) + authorName + // add linebreak to each commit but the last + if i < len(p.Commits)-1 { + text += "\n" + } + } + + return &TelegramPayload{ + Message: title + "\n" + text, + }, nil +} + +func getTelegramIssuesPayload(p *api.IssuePayload) (*TelegramPayload, error) { + var text, title string + switch p.Action { + case api.HookIssueOpened: + title = fmt.Sprintf(`[%s] Issue opened: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueClosed: + title = fmt.Sprintf(`[%s] Issue closed: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueReOpened: + title = fmt.Sprintf(`[%s] Issue re-opened: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueEdited: + title = fmt.Sprintf(`[%s] Issue edited: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueAssigned: + title = fmt.Sprintf(`[%s] Issue assigned to %s: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.Assignee.UserName, p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueUnassigned: + title = fmt.Sprintf(`[%s] Issue unassigned: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueLabelUpdated: + title = fmt.Sprintf(`[%s] Issue labels updated: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueLabelCleared: + title = fmt.Sprintf(`[%s] Issue labels cleared: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueSynchronized: + title = fmt.Sprintf(`[%s] Issue synchronized: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueMilestoned: + title = fmt.Sprintf(`[%s] Issue milestone: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueDemilestoned: + title = fmt.Sprintf(`[%s] Issue clear milestone: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + } + + return &TelegramPayload{ + Message: title + "\n\n" + text, + }, nil +} + +func getTelegramIssueCommentPayload(p *api.IssueCommentPayload) (*TelegramPayload, error) { + url := fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID)) + title := fmt.Sprintf(`#%d %s`, url, p.Issue.Index, p.Issue.Title) + var text string + switch p.Action { + case api.HookIssueCommentCreated: + text = "New comment: " + title + text += p.Comment.Body + case api.HookIssueCommentEdited: + text = "Comment edited: " + title + text += p.Comment.Body + case api.HookIssueCommentDeleted: + text = "Comment deleted: " + title + text += p.Comment.Body + } + + return &TelegramPayload{ + Message: title + "\n" + text, + }, nil +} + +func getTelegramPullRequestPayload(p *api.PullRequestPayload) (*TelegramPayload, error) { + var text, title string + switch p.Action { + case api.HookIssueOpened: + title = fmt.Sprintf(`[%s] Pull request opened: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueClosed: + if p.PullRequest.HasMerged { + title = fmt.Sprintf(`[%s] Pull request merged: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + } else { + title = fmt.Sprintf(`[%s] Pull request closed: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + } + text = p.PullRequest.Body + case api.HookIssueReOpened: + title = fmt.Sprintf(`[%s] Pull request re-opened: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueEdited: + title = fmt.Sprintf(`[%s] Pull request edited: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueAssigned: + list, err := MakeAssigneeList(&Issue{ID: p.PullRequest.ID}) + if err != nil { + return &TelegramPayload{}, err + } + title = fmt.Sprintf(`[%s] Pull request assigned to %s: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + list, p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueUnassigned: + title = fmt.Sprintf(`[%s] Pull request unassigned: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueLabelUpdated: + title = fmt.Sprintf(`[%s] Pull request labels updated: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueLabelCleared: + title = fmt.Sprintf(`[%s] Pull request labels cleared: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueSynchronized: + title = fmt.Sprintf(`[%s] Pull request synchronized: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueMilestoned: + title = fmt.Sprintf(`[%s] Pull request milestone: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueDemilestoned: + title = fmt.Sprintf(`[%s] Pull request clear milestone: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + } + + return &TelegramPayload{ + Message: title + "\n" + text, + }, nil +} + +func getTelegramRepositoryPayload(p *api.RepositoryPayload) (*TelegramPayload, error) { + var title string + switch p.Action { + case api.HookRepoCreated: + title = fmt.Sprintf(`[%s] Repository created`, p.Repository.HTMLURL, p.Repository.FullName) + return &TelegramPayload{ + Message: title, + }, nil + case api.HookRepoDeleted: + title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName) + return &TelegramPayload{ + Message: title, + }, nil + } + return nil, nil +} + +func getTelegramReleasePayload(p *api.ReleasePayload) (*TelegramPayload, error) { + var title, url string + switch p.Action { + case api.HookReleasePublished: + title = fmt.Sprintf("[%s] Release created", p.Release.TagName) + url = p.Release.URL + return &TelegramPayload{ + Message: title + "\n" + url, + }, nil + case api.HookReleaseUpdated: + title = fmt.Sprintf("[%s] Release updated", p.Release.TagName) + url = p.Release.URL + return &TelegramPayload{ + Message: title + "\n" + url, + }, nil + + case api.HookReleaseDeleted: + title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName) + url = p.Release.URL + return &TelegramPayload{ + Message: title + "\n" + url, + }, nil + } + + return nil, nil +} + +// GetTelegramPayload converts a telegram webhook into a TelegramPayload +func GetTelegramPayload(p api.Payloader, event HookEventType, meta string) (*TelegramPayload, error) { + s := new(TelegramPayload) + + switch event { + case HookEventCreate: + return getTelegramCreatePayload(p.(*api.CreatePayload)) + case HookEventDelete: + return getTelegramDeletePayload(p.(*api.DeletePayload)) + case HookEventFork: + return getTelegramForkPayload(p.(*api.ForkPayload)) + case HookEventIssues: + return getTelegramIssuesPayload(p.(*api.IssuePayload)) + case HookEventIssueComment: + return getTelegramIssueCommentPayload(p.(*api.IssueCommentPayload)) + case HookEventPush: + return getTelegramPushPayload(p.(*api.PushPayload)) + case HookEventPullRequest: + return getTelegramPullRequestPayload(p.(*api.PullRequestPayload)) + case HookEventRepository: + return getTelegramRepositoryPayload(p.(*api.RepositoryPayload)) + case HookEventRelease: + return getTelegramReleasePayload(p.(*api.ReleasePayload)) + } + + return s, nil +} diff --git a/models/webhook_test.go b/models/webhook_test.go index 50106a3792..518be8be8a 100644 --- a/models/webhook_test.go +++ b/models/webhook_test.go @@ -197,18 +197,21 @@ func TestToHookTaskType(t *testing.T) { assert.Equal(t, GOGS, ToHookTaskType("gogs")) assert.Equal(t, SLACK, ToHookTaskType("slack")) assert.Equal(t, GITEA, ToHookTaskType("gitea")) + assert.Equal(t, TELEGRAM, ToHookTaskType("telegram")) } func TestHookTaskType_Name(t *testing.T) { assert.Equal(t, "gogs", GOGS.Name()) assert.Equal(t, "slack", SLACK.Name()) assert.Equal(t, "gitea", GITEA.Name()) + assert.Equal(t, "telegram", TELEGRAM.Name()) } func TestIsValidHookTaskType(t *testing.T) { assert.True(t, IsValidHookTaskType("gogs")) assert.True(t, IsValidHookTaskType("slack")) assert.True(t, IsValidHookTaskType("gitea")) + assert.True(t, IsValidHookTaskType("telegram")) assert.False(t, IsValidHookTaskType("invalid")) } diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 990a94dd63..d37a5b94d8 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -263,6 +263,18 @@ func (f *NewDingtalkHookForm) Validate(ctx *macaron.Context, errs binding.Errors return validate(errs, ctx.Data, f, ctx.Locale) } +// NewTelegramHookForm form for creating telegram hook +type NewTelegramHookForm struct { + BotToken string `binding:"Required"` + ChatID string `binding:"Required"` + WebhookForm +} + +// Validate validates the fields +func (f *NewTelegramHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { + return validate(errs, ctx.Data, f, ctx.Locale) +} + // .___ // | | ______ ________ __ ____ // | |/ ___// ___/ | \_/ __ \ diff --git a/modules/setting/webhook.go b/modules/setting/webhook.go index 741963e545..0d91e7d9e7 100644 --- a/modules/setting/webhook.go +++ b/modules/setting/webhook.go @@ -25,6 +25,6 @@ func newWebhookService() { Webhook.QueueLength = sec.Key("QUEUE_LENGTH").MustInt(1000) Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5) Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool() - Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk"} + Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram"} Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10) } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b53a72da9b..5c391cf566 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1211,6 +1211,7 @@ settings.slack_domain = Domain settings.slack_channel = Channel settings.add_discord_hook_desc = Integrate Discord into your repository. settings.add_dingtalk_hook_desc = Integrate Dingtalk into your repository. +settings.add_telegram_hook_desc = Integrate Telegram into your repository. settings.deploy_keys = Deploy Keys settings.add_deploy_key = Add Deploy Key settings.deploy_key_desc = Deploy keys have read-only pull access to the repository. @@ -1258,6 +1259,8 @@ settings.choose_branch = Choose a branch… settings.no_protected_branch = There are no protected branches. settings.edit_protected_branch = Edit settings.protected_branch_required_approvals_min = Required approvals cannot be negative. +settings.bot_token = Bot Token +settings.chat_id = Chat ID settings.archive.button = Archive Repo settings.archive.header = Archive This Repo settings.archive.text = Archiving the repo will make it entirely read-only. It is hidden from the dashboard, cannot be committed to and no issues or pull-requests can be created. diff --git a/public/img/telegram.png b/public/img/telegram.png new file mode 100644 index 0000000000000000000000000000000000000000..ee0756db5e5f4ab4742c125e3e72bf41e2c246b3 GIT binary patch literal 12399 zcmaKTcQhPc*Dle!=$#Nm@4ffvy^T5;W{ehHbb=ruh~9f=Fe5}8J&5RSqSt6qql>$K z@B6*qcmMeAJ!_q{&N=IOp8f27_B#Kacmq8RB78c0G&D3K&DW|%XlQ6h|4dwLG&Hn; z87&GlG&EXYH49&3PiNl%pf?Cj$;s0J#G>gAbO9NGfKEYgMnJM?Xc(*z6ANDpT^(sh zPj`OcKN$W%cQ3SmhO9!M7tj$3@?~)Vxj;PRSWh~7SXm%Wa;)ZJx`Mi1Dj+cA^;>U{ z@moC;$G1>NDJND1c^26~=|FcccaSfTCD7f?!$&$$j`d%<(jGq2{~Qajviu9;3zcL2 zwA~`kBGAFp&sUC>^*<@Nd;PbphtGeN$1_x}%dcmHp+kFOEvfBgQh!agQJULXM@kdLRIwPl;R`1k@n96_3@a;$;w zUi=V)bJxaxnns-BL1?jR4}|8SlD zhb#8~o732-^2RW&Gd%CmyD`jcO|KdemR82xuO$yu7yEx*^nZ?wRMr1k{&(BTv;0rvgFKw%SiM;lw0T$i+ahp4HjIJr83o*s*mW3k9hdU0anUVHlJhtw3lmsS~d!>>yh zK2%IRKFw6_J^m`#rybvVvKbbkLzHFzzWDPb`}DlaE`N7^pF96mdUc|*uFfe2+dDtZZMaFPXSFzq^s1P3CobmOLt?p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5e+6=Hc{0d764 zMA!(R*vn_kW4|89eZuYN}WNAm1NF||L zFCDd$&Wsj0q7jI}pd47O7bGF?IWSx+io`srp;Pdo*a;=7WA_lKjQ)(^!mx4*EEoF% zpEqsrAY84M4BY?qN3x;632WGy;iH&WEHPB_y6Oe!rT=Ow3&?#GnPGeA{4VpmbHZEy zP4ZyJMxIS{9(mRR!`67-ri2xXly-hD5 zbpkW`OO*(h2T3q=f`YH6Tl|l4>}N4IcCal1A?t)qQ$)|)(Q8`^RXXZ#GQ96GVQtq` zXqXnHo~h%&tu|K4WQx8Mdz;*k=fwe?475*6ay&Ep+k=LIM*M2vw?F@Hhkw2RXsYR{ JHYnRi{U2%vj>rH2 literal 0 HcmV?d00001 diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go index 8510cb7ba2..bad109cd53 100644 --- a/routers/repo/webhook.go +++ b/routers/repo/webhook.go @@ -331,6 +331,55 @@ func DingtalkHooksNewPost(ctx *context.Context, form auth.NewDingtalkHookForm) { ctx.Redirect(orCtx.Link) } +// TelegramHooksNewPost response for creating telegram hook +func TelegramHooksNewPost(ctx *context.Context, form auth.NewTelegramHookForm) { + ctx.Data["Title"] = ctx.Tr("repo.settings") + ctx.Data["PageIsSettingsHooks"] = true + ctx.Data["PageIsSettingsHooksNew"] = true + ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}} + + orCtx, err := getOrgRepoCtx(ctx) + if err != nil { + ctx.ServerError("getOrgRepoCtx", err) + return + } + + if ctx.HasError() { + ctx.HTML(200, orCtx.NewTemplate) + return + } + + meta, err := json.Marshal(&models.TelegramMeta{ + BotToken: form.BotToken, + ChatID: form.ChatID, + }) + if err != nil { + ctx.ServerError("Marshal", err) + return + } + + w := &models.Webhook{ + RepoID: orCtx.RepoID, + URL: fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s", form.BotToken, form.ChatID), + ContentType: models.ContentTypeJSON, + HookEvent: ParseHookEvent(form.WebhookForm), + IsActive: form.Active, + HookTaskType: models.TELEGRAM, + Meta: string(meta), + OrgID: orCtx.OrgID, + } + if err := w.UpdateEvent(); err != nil { + ctx.ServerError("UpdateEvent", err) + return + } else if err := models.CreateWebhook(w); err != nil { + ctx.ServerError("CreateWebhook", err) + return + } + + ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) + ctx.Redirect(orCtx.Link) +} + // SlackHooksNewPost response for creating slack hook func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) { ctx.Data["Title"] = ctx.Tr("repo.settings") @@ -421,6 +470,8 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) { ctx.Data["SlackHook"] = w.GetSlackHook() case models.DISCORD: ctx.Data["DiscordHook"] = w.GetDiscordHook() + case models.TELEGRAM: + ctx.Data["TelegramHook"] = w.GetTelegramHook() } ctx.Data["History"], err = w.History(1) @@ -647,6 +698,46 @@ func DingtalkHooksEditPost(ctx *context.Context, form auth.NewDingtalkHookForm) ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) } +// TelegramHooksEditPost response for editing discord hook +func TelegramHooksEditPost(ctx *context.Context, form auth.NewTelegramHookForm) { + ctx.Data["Title"] = ctx.Tr("repo.settings") + ctx.Data["PageIsSettingsHooks"] = true + ctx.Data["PageIsSettingsHooksEdit"] = true + + orCtx, w := checkWebhook(ctx) + if ctx.Written() { + return + } + ctx.Data["Webhook"] = w + + if ctx.HasError() { + ctx.HTML(200, orCtx.NewTemplate) + return + } + meta, err := json.Marshal(&models.TelegramMeta{ + BotToken: form.BotToken, + ChatID: form.ChatID, + }) + if err != nil { + ctx.ServerError("Marshal", err) + return + } + w.Meta = string(meta) + w.URL = fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s", form.BotToken, form.ChatID) + w.HookEvent = ParseHookEvent(form.WebhookForm) + w.IsActive = form.Active + if err := w.UpdateEvent(); err != nil { + ctx.ServerError("UpdateEvent", err) + return + } else if err := models.UpdateWebhook(w); err != nil { + ctx.ServerError("UpdateWebhook", err) + return + } + + ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) + ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) +} + // TestWebhook test if web hook is work fine func TestWebhook(ctx *context.Context) { hookID := ctx.ParamsInt64(":id") diff --git a/routers/routes/routes.go b/routers/routes/routes.go index e42222be88..874d6494cb 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -559,12 +559,14 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost) m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost) m.Post("/dingtalk/new", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost) + m.Post("/telegram/new", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksNewPost) m.Get("/:id", repo.WebHooksEdit) m.Post("/gitea/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost) m.Post("/gogs/:id", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost) m.Post("/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost) m.Post("/discord/:id", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksEditPost) m.Post("/dingtalk/:id", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost) + m.Post("/telegram/:id", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksEditPost) }) m.Route("/delete", "GET,POST", org.SettingsDelete) @@ -612,6 +614,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost) m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost) m.Post("/dingtalk/new", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost) + m.Post("/telegram/new", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksNewPost) m.Get("/:id", repo.WebHooksEdit) m.Post("/:id/test", repo.TestWebhook) m.Post("/gitea/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost) @@ -619,6 +622,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost) m.Post("/discord/:id", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksEditPost) m.Post("/dingtalk/:id", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost) + m.Post("/telegram/:id", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksEditPost) m.Group("/git", func() { m.Get("", repo.GitHooks) diff --git a/templates/org/settings/hook_new.tmpl b/templates/org/settings/hook_new.tmpl index 809009b66b..5b216c466b 100644 --- a/templates/org/settings/hook_new.tmpl +++ b/templates/org/settings/hook_new.tmpl @@ -19,6 +19,8 @@ {{else if eq .HookType "dingtalk"}} + {{else if eq .HookType "telegram"}} + {{end}} @@ -28,6 +30,7 @@ {{template "repo/settings/webhook/slack" .}} {{template "repo/settings/webhook/discord" .}} {{template "repo/settings/webhook/dingtalk" .}} + {{template "repo/settings/webhook/telegram" .}} {{template "repo/settings/webhook/history" .}} diff --git a/templates/repo/settings/webhook/list.tmpl b/templates/repo/settings/webhook/list.tmpl index d2985c3676..ddba0f863c 100644 --- a/templates/repo/settings/webhook/list.tmpl +++ b/templates/repo/settings/webhook/list.tmpl @@ -20,6 +20,9 @@ Dingtalk + + Telegram + diff --git a/templates/repo/settings/webhook/new.tmpl b/templates/repo/settings/webhook/new.tmpl index 1b3d114577..8c8b3280e5 100644 --- a/templates/repo/settings/webhook/new.tmpl +++ b/templates/repo/settings/webhook/new.tmpl @@ -17,6 +17,8 @@ {{else if eq .HookType "dingtalk"}} + {{else if eq .HookType "telegram"}} + {{end}} @@ -26,6 +28,7 @@ {{template "repo/settings/webhook/slack" .}} {{template "repo/settings/webhook/discord" .}} {{template "repo/settings/webhook/dingtalk" .}} + {{template "repo/settings/webhook/telegram" .}} {{template "repo/settings/webhook/history" .}} diff --git a/templates/repo/settings/webhook/telegram.tmpl b/templates/repo/settings/webhook/telegram.tmpl new file mode 100644 index 0000000000..598ac44822 --- /dev/null +++ b/templates/repo/settings/webhook/telegram.tmpl @@ -0,0 +1,15 @@ +{{if eq .HookType "telegram"}} +

{{.i18n.Tr "repo.settings.add_telegram_hook_desc" "https://core.telegram.org/bots" | Str2html}}

+
+ {{.CsrfTokenHtml}} +
+ + +
+
+ + +
+ {{template "repo/settings/webhook/settings" .}} +
+{{end}}