mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 02:08:36 +00:00
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>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user