diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2021-06-21 04:12:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-20 22:12:19 -0400 |
commit | 4fcae3d06d1099ade682df96e41baf4f5ac56620 (patch) | |
tree | af3608da89c4765711d7d905773336a7ecbd68e1 /services/webhook/feishu.go | |
parent | 8601440e81e0e609ab8049fb6dae8307db78fd6c (diff) | |
download | gitea-4fcae3d06d1099ade682df96e41baf4f5ac56620.tar.gz gitea-4fcae3d06d1099ade682df96e41baf4f5ac56620.zip |
Add tests for all webhooks (#16214)
* Added tests for MS Teams.
* Added tests for Dingtalk.
* Added tests for Telegram.
* Added tests for Feishu.
* Added tests for Discord.
* Added tests for closed issue and pullrequest comment.
* Added tests for Matrix.
* Trim all spaces.
* Added tests for Slack.
* Added JSONPayload tests.
* Added general tests.
* Replaced duplicated code.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'services/webhook/feishu.go')
-rw-r--r-- | services/webhook/feishu.go | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index 847a991f36..5c80efb820 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -30,7 +30,7 @@ func newFeishuTextPayload(text string) *FeishuPayload { Content: struct { Text string `json:"text"` }{ - Text: text, + Text: strings.TrimSpace(text), }, } } @@ -84,7 +84,7 @@ func (f *FeishuPayload) Push(p *api.PushPayload) (api.Payloader, error) { commitDesc string ) - var text = fmt.Sprintf("[%s:%s] %s\n", p.Repo.FullName, branchName, commitDesc) + var 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 @@ -95,7 +95,7 @@ func (f *FeishuPayload) Push(p *api.PushPayload) (api.Payloader, error) { strings.TrimRight(commit.Message, "\r\n")) + authorName // add linebreak to each commit but the last if i < len(p.Commits)-1 { - text += "\n" + text += "\r\n" } } @@ -125,19 +125,14 @@ func (f *FeishuPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, e // Review implements PayloadConvertor Review method func (f *FeishuPayload) Review(p *api.PullRequestPayload, event models.HookEventType) (api.Payloader, 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.Review.Content - + 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.Review.Content + return newFeishuTextPayload(title + "\r\n\r\n" + text), nil } |