diff options
Diffstat (limited to 'services/webhook')
-rw-r--r-- | services/webhook/deliver.go | 3 | ||||
-rw-r--r-- | services/webhook/deliver_test.go | 2 | ||||
-rw-r--r-- | services/webhook/dingtalk.go | 5 | ||||
-rw-r--r-- | services/webhook/discord.go | 4 | ||||
-rw-r--r-- | services/webhook/feishu.go | 6 | ||||
-rw-r--r-- | services/webhook/matrix.go | 4 | ||||
-rw-r--r-- | services/webhook/msteams.go | 4 | ||||
-rw-r--r-- | services/webhook/slack.go | 4 | ||||
-rw-r--r-- | services/webhook/telegram.go | 4 | ||||
-rw-r--r-- | services/webhook/webhook.go | 70 | ||||
-rw-r--r-- | services/webhook/wechatwork.go | 11 |
11 files changed, 45 insertions, 72 deletions
diff --git a/services/webhook/deliver.go b/services/webhook/deliver.go index 36169baad4..88b709cb41 100644 --- a/services/webhook/deliver.go +++ b/services/webhook/deliver.go @@ -64,7 +64,7 @@ func Deliver(t *webhook_model.HookTask) error { req.Header.Set("Content-Type", "application/json") case webhook_model.ContentTypeForm: - var forms = url.Values{ + forms := url.Values{ "payload": []string{t.PayloadContent}, } @@ -255,7 +255,6 @@ func DeliverHooks(ctx context.Context) { } } } - } var ( diff --git a/services/webhook/deliver_test.go b/services/webhook/deliver_test.go index 551c957c8d..8d1d587c38 100644 --- a/services/webhook/deliver_test.go +++ b/services/webhook/deliver_test.go @@ -19,7 +19,7 @@ func TestWebhookProxy(t *testing.T) { setting.Webhook.ProxyURLFixed, _ = url.Parse(setting.Webhook.ProxyURL) setting.Webhook.ProxyHosts = []string{"*.discordapp.com", "discordapp.com"} - var kases = map[string]string{ + kases := map[string]string{ "https://discordapp.com/api/webhooks/xxxxxxxxx/xxxxxxxxxxxxxxxxxxx": "http://localhost:8080", "http://s.discordapp.com/assets/xxxxxx": "http://localhost:8080", "http://github.com/a/b": "", diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index a949b073a5..642cf6f2fd 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -23,9 +23,7 @@ type ( DingtalkPayload dingtalk.Payload ) -var ( - _ PayloadConvertor = &DingtalkPayload{} -) +var _ PayloadConvertor = &DingtalkPayload{} // JSONPayload Marshals the DingtalkPayload to json func (d *DingtalkPayload) JSONPayload() ([]byte, error) { @@ -135,7 +133,6 @@ func (d *DingtalkPayload) Review(p *api.PullRequestPayload, event webhook_model. title = fmt.Sprintf("[%s] Pull request review %s : #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title) text = p.Review.Content - } return createDingtalkPayload(title, title+"\r\n\r\n"+text, "view pull request", p.PullRequest.HTMLURL), nil diff --git a/services/webhook/discord.go b/services/webhook/discord.go index 587d2098eb..ae5460b9a7 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -106,9 +106,7 @@ func (d *DiscordPayload) JSONPayload() ([]byte, error) { return data, nil } -var ( - _ PayloadConvertor = &DiscordPayload{} -) +var _ PayloadConvertor = &DiscordPayload{} // Create implements PayloadConvertor Create method func (d *DiscordPayload) Create(p *api.CreatePayload) (api.Payloader, error) { diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index 18858c0994..5b20c7dda7 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -44,9 +44,7 @@ func (f *FeishuPayload) JSONPayload() ([]byte, error) { return data, nil } -var ( - _ PayloadConvertor = &FeishuPayload{} -) +var _ PayloadConvertor = &FeishuPayload{} // Create implements PayloadConvertor Create method func (f *FeishuPayload) Create(p *api.CreatePayload) (api.Payloader, error) { @@ -80,7 +78,7 @@ func (f *FeishuPayload) Push(p *api.PushPayload) (api.Payloader, error) { commitDesc string ) - var text = fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc) + text := fmt.Sprintf("[%s:%s] %s\r\n", p.Repo.FullName, branchName, commitDesc) // for each commit, generate attachment text for i, commit := range p.Commits { var authorName string diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index 72392debe9..a42ab2a93e 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -53,9 +53,7 @@ type MatrixPayloadUnsafe struct { AccessToken string `json:"access_token"` } -var ( - _ PayloadConvertor = &MatrixPayloadUnsafe{} -) +var _ PayloadConvertor = &MatrixPayloadUnsafe{} // safePayload "converts" a unsafe payload to a safe payload func (m *MatrixPayloadUnsafe) safePayload() *MatrixPayloadSafe { diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go index ae5af8d9b6..59e2e93493 100644 --- a/services/webhook/msteams.go +++ b/services/webhook/msteams.go @@ -65,9 +65,7 @@ func (m *MSTeamsPayload) JSONPayload() ([]byte, error) { return data, nil } -var ( - _ PayloadConvertor = &MSTeamsPayload{} -) +var _ PayloadConvertor = &MSTeamsPayload{} // Create implements PayloadConvertor Create method func (m *MSTeamsPayload) Create(p *api.CreatePayload) (api.Payloader, error) { diff --git a/services/webhook/slack.go b/services/webhook/slack.go index a67fe6a762..11e1d3c081 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -96,9 +96,7 @@ func SlackLinkToRef(repoURL, ref string) string { return SlackLinkFormatter(url, refName) } -var ( - _ PayloadConvertor = &SlackPayload{} -) +var _ PayloadConvertor = &SlackPayload{} // Create implements PayloadConvertor Create method func (s *SlackPayload) Create(p *api.CreatePayload) (api.Payloader, error) { diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index 93c464fe73..64211493ec 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -40,9 +40,7 @@ func GetTelegramHook(w *webhook_model.Webhook) *TelegramMeta { return s } -var ( - _ PayloadConvertor = &TelegramPayload{} -) +var _ PayloadConvertor = &TelegramPayload{} // JSONPayload Marshals the TelegramPayload to json func (t *TelegramPayload) JSONPayload() ([]byte, error) { diff --git a/services/webhook/webhook.go b/services/webhook/webhook.go index f284a20c30..bb7a9692d1 100644 --- a/services/webhook/webhook.go +++ b/services/webhook/webhook.go @@ -25,42 +25,40 @@ type webhook struct { payloadCreator func(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error) } -var ( - webhooks = map[webhook_model.HookType]*webhook{ - webhook_model.SLACK: { - name: webhook_model.SLACK, - payloadCreator: GetSlackPayload, - }, - webhook_model.DISCORD: { - name: webhook_model.DISCORD, - payloadCreator: GetDiscordPayload, - }, - webhook_model.DINGTALK: { - name: webhook_model.DINGTALK, - payloadCreator: GetDingtalkPayload, - }, - webhook_model.TELEGRAM: { - name: webhook_model.TELEGRAM, - payloadCreator: GetTelegramPayload, - }, - webhook_model.MSTEAMS: { - name: webhook_model.MSTEAMS, - payloadCreator: GetMSTeamsPayload, - }, - webhook_model.FEISHU: { - name: webhook_model.FEISHU, - payloadCreator: GetFeishuPayload, - }, - webhook_model.MATRIX: { - name: webhook_model.MATRIX, - payloadCreator: GetMatrixPayload, - }, - webhook_model.WECHATWORK: { - name: webhook_model.WECHATWORK, - payloadCreator: GetWechatworkPayload, - }, - } -) +var webhooks = map[webhook_model.HookType]*webhook{ + webhook_model.SLACK: { + name: webhook_model.SLACK, + payloadCreator: GetSlackPayload, + }, + webhook_model.DISCORD: { + name: webhook_model.DISCORD, + payloadCreator: GetDiscordPayload, + }, + webhook_model.DINGTALK: { + name: webhook_model.DINGTALK, + payloadCreator: GetDingtalkPayload, + }, + webhook_model.TELEGRAM: { + name: webhook_model.TELEGRAM, + payloadCreator: GetTelegramPayload, + }, + webhook_model.MSTEAMS: { + name: webhook_model.MSTEAMS, + payloadCreator: GetMSTeamsPayload, + }, + webhook_model.FEISHU: { + name: webhook_model.FEISHU, + payloadCreator: GetFeishuPayload, + }, + webhook_model.MATRIX: { + name: webhook_model.MATRIX, + payloadCreator: GetMatrixPayload, + }, + webhook_model.WECHATWORK: { + name: webhook_model.WECHATWORK, + payloadCreator: GetWechatworkPayload, + }, +} // RegisterWebhook registers a webhook func RegisterWebhook(name string, webhook *webhook) { diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go index e8ab07aaa0..de8b777066 100644 --- a/services/webhook/wechatwork.go +++ b/services/webhook/wechatwork.go @@ -52,9 +52,7 @@ func newWechatworkMarkdownPayload(title string) *WechatworkPayload { } } -var ( - _ PayloadConvertor = &WechatworkPayload{} -) +var _ PayloadConvertor = &WechatworkPayload{} // Create implements PayloadConvertor Create method func (f *WechatworkPayload) Create(p *api.CreatePayload) (api.Payloader, error) { @@ -72,12 +70,10 @@ func (f *WechatworkPayload) Delete(p *api.DeletePayload) (api.Payloader, error) title := fmt.Sprintf("[%s] %s %s deleted", p.Repo.FullName, p.RefType, refName) return newWechatworkMarkdownPayload(title), nil - } // Fork implements PayloadConvertor Fork method func (f *WechatworkPayload) Fork(p *api.ForkPayload) (api.Payloader, error) { - title := fmt.Sprintf("%s is forked to %s", p.Forkee.FullName, p.Repo.FullName) return newWechatworkMarkdownPayload(title), nil @@ -110,7 +106,6 @@ func (f *WechatworkPayload) Push(p *api.PushPayload) (api.Payloader, error) { } } return newWechatworkMarkdownPayload(title + "\r\n\r\n" + text), nil - } // Issue implements PayloadConvertor Issue method @@ -120,7 +115,6 @@ func (f *WechatworkPayload) Issue(p *api.IssuePayload) (api.Payloader, error) { content += fmt.Sprintf(" ><font color=\"info\">%s</font>\n >%s \n ><font color=\"warning\"> %s</font> \n [%s](%s)", text, attachmentText, issueTitle, p.Issue.HTMLURL, p.Issue.HTMLURL) return newWechatworkMarkdownPayload(content), nil - } // IssueComment implements PayloadConvertor IssueComment method @@ -130,7 +124,6 @@ func (f *WechatworkPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloa content += fmt.Sprintf(" ><font color=\"info\">%s</font>\n >%s \n ><font color=\"warning\">%s</font> \n [%s](%s)", text, p.Comment.Body, issueTitle, p.Comment.HTMLURL, p.Comment.HTMLURL) return newWechatworkMarkdownPayload(content), nil - } // PullRequest implements PayloadConvertor PullRequest method @@ -140,7 +133,6 @@ func (f *WechatworkPayload) PullRequest(p *api.PullRequestPayload) (api.Payloade text, issueTitle, attachmentText) return newWechatworkMarkdownPayload(pr), nil - } // Review implements PayloadConvertor Review method @@ -157,7 +149,6 @@ func (f *WechatworkPayload) Review(p *api.PullRequestPayload, event webhook_mode } return newWechatworkMarkdownPayload("# " + title + "\r\n\r\n >" + text), nil - } // Repository implements PayloadConvertor Repository method |