mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +00:00
feat: place user names into inline code blocks for Slack (#10147)
Committer names in Slack/Mattermost messages trigger notifications to the corresponding users if they have configured notifications for messages containing their names. These notifications are intended to alert users when someone else mentions them. However, for Git-related messages, users may receive notifications triggered by their own actions. To prevent this, BitBucket, for example, places names in inline code blocks. This pull request adds a similar feature for the Forgejo Slack webhook. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10147 Reviewed-by: Lucas <sclu1034@noreply.codeberg.org> Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Erki Aring <erki@example.ee> Co-committed-by: Erki Aring <erki@example.ee>
This commit is contained in:
parent
ac9c4282bd
commit
6cae1b4bf3
11 changed files with 121 additions and 110 deletions
|
|
@ -130,14 +130,14 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) {
|
|||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
func (dc dingtalkConvertor) Issue(p *api.IssuePayload) (DingtalkPayload, error) {
|
||||
text, issueTitle, attachmentText, _ := getIssuesPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, issueTitle, attachmentText, _ := getIssuesPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createDingtalkPayload(issueTitle, text+"\r\n\r\n"+attachmentText, "view issue", p.Issue.HTMLURL), nil
|
||||
}
|
||||
|
||||
// Wiki implements PayloadConvertor Wiki method
|
||||
func (dc dingtalkConvertor) Wiki(p *api.WikiPayload) (DingtalkPayload, error) {
|
||||
text, _, _ := getWikiPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, _, _ := getWikiPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
url := p.Repository.HTMLURL + "/wiki/" + url.PathEscape(p.Page)
|
||||
|
||||
return createDingtalkPayload(text, text, "view wiki", url), nil
|
||||
|
|
@ -145,14 +145,14 @@ func (dc dingtalkConvertor) Wiki(p *api.WikiPayload) (DingtalkPayload, error) {
|
|||
|
||||
// IssueComment implements PayloadConvertor IssueComment method
|
||||
func (dc dingtalkConvertor) IssueComment(p *api.IssueCommentPayload) (DingtalkPayload, error) {
|
||||
text, issueTitle, _ := getIssueCommentPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, issueTitle, _ := getIssueCommentPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createDingtalkPayload(issueTitle, text+"\r\n\r\n"+p.Comment.Body, "view issue comment", p.Comment.HTMLURL), nil
|
||||
}
|
||||
|
||||
// PullRequest implements PayloadConvertor PullRequest method
|
||||
func (dc dingtalkConvertor) PullRequest(p *api.PullRequestPayload) (DingtalkPayload, error) {
|
||||
text, issueTitle, attachmentText, _ := getPullRequestPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, issueTitle, attachmentText, _ := getPullRequestPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createDingtalkPayload(issueTitle, text+"\r\n\r\n"+attachmentText, "view pull request", p.PullRequest.HTMLURL), nil
|
||||
}
|
||||
|
|
@ -196,13 +196,13 @@ func (dc dingtalkConvertor) Repository(p *api.RepositoryPayload) (DingtalkPayloa
|
|||
|
||||
// Release implements PayloadConvertor Release method
|
||||
func (dc dingtalkConvertor) Release(p *api.ReleasePayload) (DingtalkPayload, error) {
|
||||
text, _ := getReleasePayloadInfo(p, noneLinkFormatter, true)
|
||||
text, _ := getReleasePayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createDingtalkPayload(text, text, "view release", p.Release.HTMLURL), nil
|
||||
}
|
||||
|
||||
func (dc dingtalkConvertor) Package(p *api.PackagePayload) (DingtalkPayload, error) {
|
||||
text, _ := getPackagePayloadInfo(p, noneLinkFormatter, true)
|
||||
text, _ := getPackagePayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createDingtalkPayload(text, text, "view package", p.Package.HTMLURL), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -235,21 +235,21 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) {
|
|||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
func (d discordConvertor) Issue(p *api.IssuePayload) (DiscordPayload, error) {
|
||||
title, _, text, color := getIssuesPayloadInfo(p, noneLinkFormatter, false)
|
||||
title, _, text, color := getIssuesPayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return d.createPayload(p.Sender, title, text, p.Issue.HTMLURL, color), nil
|
||||
}
|
||||
|
||||
// IssueComment implements PayloadConvertor IssueComment method
|
||||
func (d discordConvertor) IssueComment(p *api.IssueCommentPayload) (DiscordPayload, error) {
|
||||
title, _, color := getIssueCommentPayloadInfo(p, noneLinkFormatter, false)
|
||||
title, _, color := getIssueCommentPayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return d.createPayload(p.Sender, title, p.Comment.Body, p.Comment.HTMLURL, color), nil
|
||||
}
|
||||
|
||||
// PullRequest implements PayloadConvertor PullRequest method
|
||||
func (d discordConvertor) PullRequest(p *api.PullRequestPayload) (DiscordPayload, error) {
|
||||
title, _, text, color := getPullRequestPayloadInfo(p, noneLinkFormatter, false)
|
||||
title, _, text, color := getPullRequestPayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return d.createPayload(p.Sender, title, text, p.PullRequest.HTMLURL, color), nil
|
||||
}
|
||||
|
|
@ -301,7 +301,7 @@ func (d discordConvertor) Repository(p *api.RepositoryPayload) (DiscordPayload,
|
|||
|
||||
// Wiki implements PayloadConvertor Wiki method
|
||||
func (d discordConvertor) Wiki(p *api.WikiPayload) (DiscordPayload, error) {
|
||||
text, color, _ := getWikiPayloadInfo(p, noneLinkFormatter, false)
|
||||
text, color, _ := getWikiPayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
htmlLink := p.Repository.HTMLURL + "/wiki/" + url.PathEscape(p.Page)
|
||||
|
||||
var description string
|
||||
|
|
@ -314,13 +314,13 @@ func (d discordConvertor) Wiki(p *api.WikiPayload) (DiscordPayload, error) {
|
|||
|
||||
// Release implements PayloadConvertor Release method
|
||||
func (d discordConvertor) Release(p *api.ReleasePayload) (DiscordPayload, error) {
|
||||
text, color := getReleasePayloadInfo(p, noneLinkFormatter, false)
|
||||
text, color := getReleasePayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return d.createPayload(p.Sender, text, p.Release.Note, p.Release.HTMLURL, color), nil
|
||||
}
|
||||
|
||||
func (d discordConvertor) Package(p *api.PackagePayload) (DiscordPayload, error) {
|
||||
text, color := getPackagePayloadInfo(p, noneLinkFormatter, false)
|
||||
text, color := getPackagePayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return d.createPayload(p.Sender, text, "", p.Package.HTMLURL, color), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ func (fc feishuConvertor) Push(p *api.PushPayload) (FeishuPayload, error) {
|
|||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
func (fc feishuConvertor) Issue(p *api.IssuePayload) (FeishuPayload, error) {
|
||||
title, link, by, operator, result, assignees := getIssuesInfo(p)
|
||||
title, link, by, operator, result, assignees := getIssuesInfo(p, noneNameFormatter)
|
||||
if assignees != "" {
|
||||
if p.Action == api.HookIssueAssigned || p.Action == api.HookIssueUnassigned || p.Action == api.HookIssueMilestoned {
|
||||
return newFeishuTextPayload(fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n%s\n\n%s", title, link, by, operator, result, assignees, p.Issue.Body)), nil
|
||||
|
|
@ -127,13 +127,13 @@ func (fc feishuConvertor) Issue(p *api.IssuePayload) (FeishuPayload, error) {
|
|||
|
||||
// IssueComment implements PayloadConvertor IssueComment method
|
||||
func (fc feishuConvertor) IssueComment(p *api.IssueCommentPayload) (FeishuPayload, error) {
|
||||
title, link, by, operator := getIssuesCommentInfo(p)
|
||||
title, link, by, operator := getIssuesCommentInfo(p, noneNameFormatter)
|
||||
return newFeishuTextPayload(fmt.Sprintf("%s\n%s\n%s\n%s\n\n%s", title, link, by, operator, p.Comment.Body)), nil
|
||||
}
|
||||
|
||||
// PullRequest implements PayloadConvertor PullRequest method
|
||||
func (fc feishuConvertor) PullRequest(p *api.PullRequestPayload) (FeishuPayload, error) {
|
||||
title, link, by, operator, result, assignees := getPullRequestInfo(p)
|
||||
title, link, by, operator, result, assignees := getPullRequestInfo(p, noneNameFormatter)
|
||||
if assignees != "" {
|
||||
if p.Action == api.HookIssueAssigned || p.Action == api.HookIssueUnassigned || p.Action == api.HookIssueMilestoned {
|
||||
return newFeishuTextPayload(fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n%s\n\n%s", title, link, by, operator, result, assignees, p.PullRequest.Body)), nil
|
||||
|
|
@ -173,20 +173,20 @@ func (fc feishuConvertor) Repository(p *api.RepositoryPayload) (FeishuPayload, e
|
|||
|
||||
// Wiki implements PayloadConvertor Wiki method
|
||||
func (fc feishuConvertor) Wiki(p *api.WikiPayload) (FeishuPayload, error) {
|
||||
text, _, _ := getWikiPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, _, _ := getWikiPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return newFeishuTextPayload(text), nil
|
||||
}
|
||||
|
||||
// Release implements PayloadConvertor Release method
|
||||
func (fc feishuConvertor) Release(p *api.ReleasePayload) (FeishuPayload, error) {
|
||||
text, _ := getReleasePayloadInfo(p, noneLinkFormatter, true)
|
||||
text, _ := getReleasePayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return newFeishuTextPayload(text), nil
|
||||
}
|
||||
|
||||
func (fc feishuConvertor) Package(p *api.PackagePayload) (FeishuPayload, error) {
|
||||
text, _ := getPackagePayloadInfo(p, noneLinkFormatter, true)
|
||||
text, _ := getPackagePayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return newFeishuTextPayload(text), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@ import (
|
|||
webhook_module "forgejo.org/modules/webhook"
|
||||
)
|
||||
|
||||
type linkFormatter = func(string, string) string
|
||||
type (
|
||||
linkFormatter = func(string, string) string
|
||||
nameFormatter = func(string) string
|
||||
)
|
||||
|
||||
// noneLinkFormatter does not create a link but just returns the text
|
||||
func noneLinkFormatter(url, text string) string {
|
||||
|
|
@ -28,72 +31,77 @@ func htmlLinkFormatter(url, text string) string {
|
|||
return fmt.Sprintf(`<a href="%s">%s</a>`, html.EscapeString(url), html.EscapeString(text))
|
||||
}
|
||||
|
||||
// noneNameFormatter just returns the name
|
||||
func noneNameFormatter(name string) string {
|
||||
return name
|
||||
}
|
||||
|
||||
// getPullRequestInfo gets the information for a pull request
|
||||
func getPullRequestInfo(p *api.PullRequestPayload) (title, link, by, operator, operateResult, assignees string) {
|
||||
func getPullRequestInfo(p *api.PullRequestPayload, nameFormatter nameFormatter) (title, link, by, operator, operateResult, assignees string) {
|
||||
title = fmt.Sprintf("[PullRequest-%s #%d]: %s\n%s", p.Repository.FullName, p.PullRequest.Index, p.Action, p.PullRequest.Title)
|
||||
assignList := p.PullRequest.Assignees
|
||||
assignStringList := make([]string, len(assignList))
|
||||
|
||||
for i, user := range assignList {
|
||||
assignStringList[i] = user.UserName
|
||||
assignStringList[i] = nameFormatter(user.UserName)
|
||||
}
|
||||
switch p.Action {
|
||||
case api.HookIssueAssigned:
|
||||
operateResult = fmt.Sprintf("%s assign this to %s", p.Sender.UserName, assignList[len(assignList)-1].UserName)
|
||||
operateResult = fmt.Sprintf("%s assign this to %s", nameFormatter(p.Sender.UserName), nameFormatter(assignList[len(assignList)-1].UserName))
|
||||
case api.HookIssueUnassigned:
|
||||
operateResult = fmt.Sprintf("%s unassigned this for someone", p.Sender.UserName)
|
||||
operateResult = fmt.Sprintf("%s unassigned this for someone", nameFormatter(p.Sender.UserName))
|
||||
case api.HookIssueMilestoned:
|
||||
operateResult = fmt.Sprintf("%s/milestone/%d", p.Repository.HTMLURL, p.PullRequest.Milestone.ID)
|
||||
}
|
||||
link = p.PullRequest.HTMLURL
|
||||
by = fmt.Sprintf("PullRequest by %s", p.PullRequest.Poster.UserName)
|
||||
by = fmt.Sprintf("PullRequest by %s", nameFormatter(p.PullRequest.Poster.UserName))
|
||||
if len(assignStringList) > 0 {
|
||||
assignees = fmt.Sprintf("Assignees: %s", strings.Join(assignStringList, ", "))
|
||||
}
|
||||
operator = fmt.Sprintf("Operator: %s", p.Sender.UserName)
|
||||
operator = fmt.Sprintf("Operator: %s", nameFormatter(p.Sender.UserName))
|
||||
return title, link, by, operator, operateResult, assignees
|
||||
}
|
||||
|
||||
// getIssuesInfo gets the information for an issue
|
||||
func getIssuesInfo(p *api.IssuePayload) (issueTitle, link, by, operator, operateResult, assignees string) {
|
||||
func getIssuesInfo(p *api.IssuePayload, nameFormatter nameFormatter) (issueTitle, link, by, operator, operateResult, assignees string) {
|
||||
issueTitle = fmt.Sprintf("[Issue-%s #%d]: %s\n%s", p.Repository.FullName, p.Issue.Index, p.Action, p.Issue.Title)
|
||||
assignList := p.Issue.Assignees
|
||||
assignStringList := make([]string, len(assignList))
|
||||
|
||||
for i, user := range assignList {
|
||||
assignStringList[i] = user.UserName
|
||||
assignStringList[i] = nameFormatter(user.UserName)
|
||||
}
|
||||
switch p.Action {
|
||||
case api.HookIssueAssigned:
|
||||
operateResult = fmt.Sprintf("%s assign this to %s", p.Sender.UserName, assignList[len(assignList)-1].UserName)
|
||||
operateResult = fmt.Sprintf("%s assign this to %s", nameFormatter(p.Sender.UserName), nameFormatter(assignList[len(assignList)-1].UserName))
|
||||
case api.HookIssueUnassigned:
|
||||
operateResult = fmt.Sprintf("%s unassigned this for someone", p.Sender.UserName)
|
||||
operateResult = fmt.Sprintf("%s unassigned this for someone", nameFormatter(p.Sender.UserName))
|
||||
case api.HookIssueMilestoned:
|
||||
operateResult = fmt.Sprintf("%s/milestone/%d", p.Repository.HTMLURL, p.Issue.Milestone.ID)
|
||||
}
|
||||
link = p.Issue.HTMLURL
|
||||
by = fmt.Sprintf("Issue by %s", p.Issue.Poster.UserName)
|
||||
by = fmt.Sprintf("Issue by %s", nameFormatter(p.Issue.Poster.UserName))
|
||||
if len(assignStringList) > 0 {
|
||||
assignees = fmt.Sprintf("Assignees: %s", strings.Join(assignStringList, ", "))
|
||||
}
|
||||
operator = fmt.Sprintf("Operator: %s", p.Sender.UserName)
|
||||
operator = fmt.Sprintf("Operator: %s", nameFormatter(p.Sender.UserName))
|
||||
return issueTitle, link, by, operator, operateResult, assignees
|
||||
}
|
||||
|
||||
// getIssuesCommentInfo gets the information for a comment
|
||||
func getIssuesCommentInfo(p *api.IssueCommentPayload) (title, link, by, operator string) {
|
||||
func getIssuesCommentInfo(p *api.IssueCommentPayload, nameFormatter nameFormatter) (title, link, by, operator string) {
|
||||
title = fmt.Sprintf("[Comment-%s #%d]: %s\n%s", p.Repository.FullName, p.Issue.Index, p.Action, p.Issue.Title)
|
||||
link = p.Issue.HTMLURL
|
||||
if p.IsPull {
|
||||
by = fmt.Sprintf("PullRequest by %s", p.Issue.Poster.UserName)
|
||||
by = fmt.Sprintf("PullRequest by %s", nameFormatter(p.Issue.Poster.UserName))
|
||||
} else {
|
||||
by = fmt.Sprintf("Issue by %s", p.Issue.Poster.UserName)
|
||||
by = fmt.Sprintf("Issue by %s", nameFormatter(p.Issue.Poster.UserName))
|
||||
}
|
||||
operator = fmt.Sprintf("Operator: %s", p.Sender.UserName)
|
||||
operator = fmt.Sprintf("Operator: %s", nameFormatter(p.Sender.UserName))
|
||||
return title, link, by, operator
|
||||
}
|
||||
|
||||
func getIssuesPayloadInfo(p *api.IssuePayload, linkFormatter linkFormatter, withSender bool) (string, string, string, int) {
|
||||
func getIssuesPayloadInfo(p *api.IssuePayload, linkFormatter linkFormatter, nameFormatter nameFormatter, withSender bool) (string, string, string, int) {
|
||||
issueTitle := fmt.Sprintf("#%d %s", p.Index, p.Issue.Title)
|
||||
titleLink := linkFormatter(fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Index), issueTitle)
|
||||
var text string
|
||||
|
|
@ -131,7 +139,7 @@ func getIssuesPayloadInfo(p *api.IssuePayload, linkFormatter linkFormatter, with
|
|||
text = fmt.Sprintf("[%s] Issue milestone cleared: %s", p.Repository.FullName, titleLink)
|
||||
}
|
||||
if withSender {
|
||||
text += fmt.Sprintf(" by %s", p.Sender.UserName)
|
||||
text += fmt.Sprintf(" by %s", nameFormatter(p.Sender.UserName))
|
||||
}
|
||||
|
||||
var attachmentText string
|
||||
|
|
@ -142,7 +150,7 @@ func getIssuesPayloadInfo(p *api.IssuePayload, linkFormatter linkFormatter, with
|
|||
return text, issueTitle, attachmentText, color
|
||||
}
|
||||
|
||||
func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkFormatter, withSender bool) (string, string, string, int) {
|
||||
func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkFormatter, nameFormatter nameFormatter, withSender bool) (string, string, string, int) {
|
||||
issueTitle := fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title)
|
||||
titleLink := linkFormatter(p.PullRequest.URL, issueTitle)
|
||||
var text string
|
||||
|
|
@ -196,13 +204,13 @@ func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkForm
|
|||
text = fmt.Sprintf("[%s] Pull request review request removed: %s", p.Repository.FullName, titleLink)
|
||||
}
|
||||
if withSender {
|
||||
text += fmt.Sprintf(" by %s", p.Sender.UserName)
|
||||
text += fmt.Sprintf(" by %s", nameFormatter(p.Sender.UserName))
|
||||
}
|
||||
|
||||
return text, issueTitle, attachmentText, color
|
||||
}
|
||||
|
||||
func getReleasePayloadInfo(p *api.ReleasePayload, linkFormatter linkFormatter, withSender bool) (text string, color int) {
|
||||
func getReleasePayloadInfo(p *api.ReleasePayload, linkFormatter linkFormatter, nameFormatter nameFormatter, withSender bool) (text string, color int) {
|
||||
refLink := linkFormatter(p.Repository.HTMLURL+"/releases/tag/"+util.PathEscapeSegments(p.Release.TagName), p.Release.TagName)
|
||||
|
||||
switch p.Action {
|
||||
|
|
@ -217,13 +225,13 @@ func getReleasePayloadInfo(p *api.ReleasePayload, linkFormatter linkFormatter, w
|
|||
color = redColor
|
||||
}
|
||||
if withSender {
|
||||
text += fmt.Sprintf(" by %s", p.Sender.UserName)
|
||||
text += fmt.Sprintf(" by %s", nameFormatter(p.Sender.UserName))
|
||||
}
|
||||
|
||||
return text, color
|
||||
}
|
||||
|
||||
func getWikiPayloadInfo(p *api.WikiPayload, linkFormatter linkFormatter, withSender bool) (string, int, string) {
|
||||
func getWikiPayloadInfo(p *api.WikiPayload, linkFormatter linkFormatter, nameFormatter nameFormatter, withSender bool) (string, int, string) {
|
||||
pageLink := linkFormatter(p.Repository.HTMLURL+"/wiki/"+url.PathEscape(p.Page), p.Page)
|
||||
|
||||
var text string
|
||||
|
|
@ -245,13 +253,13 @@ func getWikiPayloadInfo(p *api.WikiPayload, linkFormatter linkFormatter, withSen
|
|||
}
|
||||
|
||||
if withSender {
|
||||
text += fmt.Sprintf(" by %s", p.Sender.UserName)
|
||||
text += fmt.Sprintf(" by %s", nameFormatter(p.Sender.UserName))
|
||||
}
|
||||
|
||||
return text, color, pageLink
|
||||
}
|
||||
|
||||
func getIssueCommentPayloadInfo(p *api.IssueCommentPayload, linkFormatter linkFormatter, withSender bool) (string, string, int) {
|
||||
func getIssueCommentPayloadInfo(p *api.IssueCommentPayload, linkFormatter linkFormatter, nameFormatter nameFormatter, withSender bool) (string, string, int) {
|
||||
issueTitle := fmt.Sprintf("#%d %s", p.Issue.Index, p.Issue.Title)
|
||||
|
||||
var text, typ, titleLink string
|
||||
|
|
@ -280,13 +288,13 @@ func getIssueCommentPayloadInfo(p *api.IssueCommentPayload, linkFormatter linkFo
|
|||
color = redColor
|
||||
}
|
||||
if withSender {
|
||||
text += fmt.Sprintf(" by %s", p.Sender.UserName)
|
||||
text += fmt.Sprintf(" by %s", nameFormatter(p.Sender.UserName))
|
||||
}
|
||||
|
||||
return text, issueTitle, color
|
||||
}
|
||||
|
||||
func getPackagePayloadInfo(p *api.PackagePayload, linkFormatter linkFormatter, withSender bool) (text string, color int) {
|
||||
func getPackagePayloadInfo(p *api.PackagePayload, linkFormatter linkFormatter, nameFormatter nameFormatter, withSender bool) (text string, color int) {
|
||||
refLink := linkFormatter(p.Package.HTMLURL, p.Package.Name+":"+p.Package.Version)
|
||||
|
||||
switch p.Action {
|
||||
|
|
@ -298,7 +306,7 @@ func getPackagePayloadInfo(p *api.PackagePayload, linkFormatter linkFormatter, w
|
|||
color = redColor
|
||||
}
|
||||
if withSender {
|
||||
text += fmt.Sprintf(" by %s", p.Sender.UserName)
|
||||
text += fmt.Sprintf(" by %s", nameFormatter(p.Sender.UserName))
|
||||
}
|
||||
|
||||
return text, color
|
||||
|
|
|
|||
|
|
@ -476,7 +476,7 @@ func TestGetIssuesPayloadInfo(t *testing.T) {
|
|||
|
||||
for i, c := range cases {
|
||||
p.Action = c.action
|
||||
text, issueTitle, attachmentText, color := getIssuesPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, issueTitle, attachmentText, color := getIssuesPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
assert.Equal(t, c.text, text, "case %d", i)
|
||||
assert.Equal(t, c.issueTitle, issueTitle, "case %d", i)
|
||||
assert.Equal(t, c.attachmentText, attachmentText, "case %d", i)
|
||||
|
|
@ -575,7 +575,7 @@ func TestGetPullRequestPayloadInfo(t *testing.T) {
|
|||
|
||||
for i, c := range cases {
|
||||
p.Action = c.action
|
||||
text, issueTitle, attachmentText, color := getPullRequestPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, issueTitle, attachmentText, color := getPullRequestPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
assert.Equal(t, c.text, text, "case %d", i)
|
||||
assert.Equal(t, c.issueTitle, issueTitle, "case %d", i)
|
||||
assert.Equal(t, c.attachmentText, attachmentText, "case %d", i)
|
||||
|
|
@ -614,7 +614,7 @@ func TestGetWikiPayloadInfo(t *testing.T) {
|
|||
|
||||
for i, c := range cases {
|
||||
p.Action = c.action
|
||||
text, color, link := getWikiPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, color, link := getWikiPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
assert.Equal(t, c.text, text, "case %d", i)
|
||||
assert.Equal(t, c.color, color, "case %d", i)
|
||||
assert.Equal(t, c.link, link, "case %d", i)
|
||||
|
|
@ -648,7 +648,7 @@ func TestGetReleasePayloadInfo(t *testing.T) {
|
|||
|
||||
for i, c := range cases {
|
||||
p.Action = c.action
|
||||
text, color := getReleasePayloadInfo(p, noneLinkFormatter, true)
|
||||
text, color := getReleasePayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
assert.Equal(t, c.text, text, "case %d", i)
|
||||
assert.Equal(t, c.color, color, "case %d", i)
|
||||
}
|
||||
|
|
@ -685,7 +685,7 @@ func TestGetIssueCommentPayloadInfo(t *testing.T) {
|
|||
|
||||
for i, c := range cases {
|
||||
p.Action = c.action
|
||||
text, issueTitle, color := getIssueCommentPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, issueTitle, color := getIssueCommentPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
assert.Equal(t, c.text, text, "case %d", i)
|
||||
assert.Equal(t, c.issueTitle, issueTitle, "case %d", i)
|
||||
assert.Equal(t, c.color, color, "case %d", i)
|
||||
|
|
|
|||
|
|
@ -169,28 +169,28 @@ func (m matrixConvertor) Fork(p *api.ForkPayload) (MatrixPayload, error) {
|
|||
|
||||
// Issue implements payloadConvertor Issue method
|
||||
func (m matrixConvertor) Issue(p *api.IssuePayload) (MatrixPayload, error) {
|
||||
text, _, _, _ := getIssuesPayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _, _, _ := getIssuesPayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return m.newPayload(text)
|
||||
}
|
||||
|
||||
// IssueComment implements payloadConvertor IssueComment method
|
||||
func (m matrixConvertor) IssueComment(p *api.IssueCommentPayload) (MatrixPayload, error) {
|
||||
text, _, _ := getIssueCommentPayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _, _ := getIssueCommentPayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return m.newPayload(text)
|
||||
}
|
||||
|
||||
// Wiki implements payloadConvertor Wiki method
|
||||
func (m matrixConvertor) Wiki(p *api.WikiPayload) (MatrixPayload, error) {
|
||||
text, _, _ := getWikiPayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _, _ := getWikiPayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return m.newPayload(text)
|
||||
}
|
||||
|
||||
// Release implements payloadConvertor Release method
|
||||
func (m matrixConvertor) Release(p *api.ReleasePayload) (MatrixPayload, error) {
|
||||
text, _ := getReleasePayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _ := getReleasePayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return m.newPayload(text)
|
||||
}
|
||||
|
|
@ -222,7 +222,7 @@ func (m matrixConvertor) Push(p *api.PushPayload) (MatrixPayload, error) {
|
|||
|
||||
// PullRequest implements payloadConvertor PullRequest method
|
||||
func (m matrixConvertor) PullRequest(p *api.PullRequestPayload) (MatrixPayload, error) {
|
||||
text, _, _, _ := getPullRequestPayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _, _, _ := getPullRequestPayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return m.newPayload(text)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ func (m msteamsConvertor) Push(p *api.PushPayload) (MSTeamsPayload, error) {
|
|||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
func (m msteamsConvertor) Issue(p *api.IssuePayload) (MSTeamsPayload, error) {
|
||||
title, _, attachmentText, color := getIssuesPayloadInfo(p, noneLinkFormatter, false)
|
||||
title, _, attachmentText, color := getIssuesPayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return createMSTeamsPayload(
|
||||
p.Repository,
|
||||
|
|
@ -193,7 +193,7 @@ func (m msteamsConvertor) Issue(p *api.IssuePayload) (MSTeamsPayload, error) {
|
|||
|
||||
// IssueComment implements PayloadConvertor IssueComment method
|
||||
func (m msteamsConvertor) IssueComment(p *api.IssueCommentPayload) (MSTeamsPayload, error) {
|
||||
title, _, color := getIssueCommentPayloadInfo(p, noneLinkFormatter, false)
|
||||
title, _, color := getIssueCommentPayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return createMSTeamsPayload(
|
||||
p.Repository,
|
||||
|
|
@ -208,7 +208,7 @@ func (m msteamsConvertor) IssueComment(p *api.IssueCommentPayload) (MSTeamsPaylo
|
|||
|
||||
// PullRequest implements PayloadConvertor PullRequest method
|
||||
func (m msteamsConvertor) PullRequest(p *api.PullRequestPayload) (MSTeamsPayload, error) {
|
||||
title, _, attachmentText, color := getPullRequestPayloadInfo(p, noneLinkFormatter, false)
|
||||
title, _, attachmentText, color := getPullRequestPayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return createMSTeamsPayload(
|
||||
p.Repository,
|
||||
|
|
@ -284,7 +284,7 @@ func (m msteamsConvertor) Repository(p *api.RepositoryPayload) (MSTeamsPayload,
|
|||
|
||||
// Wiki implements PayloadConvertor Wiki method
|
||||
func (m msteamsConvertor) Wiki(p *api.WikiPayload) (MSTeamsPayload, error) {
|
||||
title, color, _ := getWikiPayloadInfo(p, noneLinkFormatter, false)
|
||||
title, color, _ := getWikiPayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return createMSTeamsPayload(
|
||||
p.Repository,
|
||||
|
|
@ -299,7 +299,7 @@ func (m msteamsConvertor) Wiki(p *api.WikiPayload) (MSTeamsPayload, error) {
|
|||
|
||||
// Release implements PayloadConvertor Release method
|
||||
func (m msteamsConvertor) Release(p *api.ReleasePayload) (MSTeamsPayload, error) {
|
||||
title, color := getReleasePayloadInfo(p, noneLinkFormatter, false)
|
||||
title, color := getReleasePayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return createMSTeamsPayload(
|
||||
p.Repository,
|
||||
|
|
@ -313,7 +313,7 @@ func (m msteamsConvertor) Release(p *api.ReleasePayload) (MSTeamsPayload, error)
|
|||
}
|
||||
|
||||
func (m msteamsConvertor) Package(p *api.PackagePayload) (MSTeamsPayload, error) {
|
||||
title, color := getPackagePayloadInfo(p, noneLinkFormatter, false)
|
||||
title, color := getPackagePayloadInfo(p, noneLinkFormatter, noneNameFormatter, false)
|
||||
|
||||
return createMSTeamsPayload(
|
||||
p.Repository,
|
||||
|
|
|
|||
|
|
@ -119,14 +119,17 @@ func SlackTextFormatter(s string) string {
|
|||
return s
|
||||
}
|
||||
|
||||
// SlackShortTextFormatter replaces &, <, > with HTML characters
|
||||
// SlackNameFormatter puts the name into an inline code block.
|
||||
// This way names do not trigger unwanted message notifications, as users usually don't want to get notified about their own actions.
|
||||
func SlackNameFormatter(name string) string {
|
||||
name = strings.ReplaceAll(name, "`", "'")
|
||||
return fmt.Sprintf("`%s`", SlackTextFormatter(name))
|
||||
}
|
||||
|
||||
// Same as SlackTextFormatter, but only keeps the first line of a multiline text
|
||||
func SlackShortTextFormatter(s string) string {
|
||||
s = strings.Split(s, "\n")[0]
|
||||
// replace & < >
|
||||
s = strings.ReplaceAll(s, "&", "&")
|
||||
s = strings.ReplaceAll(s, "<", "<")
|
||||
s = strings.ReplaceAll(s, ">", ">")
|
||||
return s
|
||||
return SlackTextFormatter(s)
|
||||
}
|
||||
|
||||
// SlackLinkFormatter creates a link compatible with slack
|
||||
|
|
@ -146,7 +149,7 @@ func SlackLinkToRef(repoURL, ref string) string {
|
|||
// Create implements payloadConvertor Create method
|
||||
func (s slackConvertor) Create(p *api.CreatePayload) (SlackPayload, error) {
|
||||
refLink := SlackLinkToRef(p.Repo.HTMLURL, p.Ref)
|
||||
text := fmt.Sprintf("[%s:%s] %s created by %s", p.Repo.FullName, refLink, p.RefType, p.Sender.UserName)
|
||||
text := fmt.Sprintf("[%s:%s] %s created by %s", p.Repo.FullName, refLink, p.RefType, SlackNameFormatter(p.Sender.UserName))
|
||||
|
||||
return s.createPayload(text, nil), nil
|
||||
}
|
||||
|
|
@ -155,7 +158,7 @@ func (s slackConvertor) Create(p *api.CreatePayload) (SlackPayload, error) {
|
|||
func (s slackConvertor) Delete(p *api.DeletePayload) (SlackPayload, error) {
|
||||
refName := git.RefName(p.Ref).ShortName()
|
||||
repoLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName)
|
||||
text := fmt.Sprintf("[%s:%s] %s deleted by %s", repoLink, refName, p.RefType, p.Sender.UserName)
|
||||
text := fmt.Sprintf("[%s:%s] %s deleted by %s", repoLink, refName, p.RefType, SlackNameFormatter(p.Sender.UserName))
|
||||
|
||||
return s.createPayload(text, nil), nil
|
||||
}
|
||||
|
|
@ -171,7 +174,7 @@ func (s slackConvertor) Fork(p *api.ForkPayload) (SlackPayload, error) {
|
|||
|
||||
// Issue implements payloadConvertor Issue method
|
||||
func (s slackConvertor) Issue(p *api.IssuePayload) (SlackPayload, error) {
|
||||
text, issueTitle, attachmentText, color := getIssuesPayloadInfo(p, SlackLinkFormatter, true)
|
||||
text, issueTitle, attachmentText, color := getIssuesPayloadInfo(p, SlackLinkFormatter, SlackNameFormatter, true)
|
||||
|
||||
var attachments []SlackAttachment
|
||||
if attachmentText != "" {
|
||||
|
|
@ -190,7 +193,7 @@ func (s slackConvertor) Issue(p *api.IssuePayload) (SlackPayload, error) {
|
|||
|
||||
// IssueComment implements payloadConvertor IssueComment method
|
||||
func (s slackConvertor) IssueComment(p *api.IssueCommentPayload) (SlackPayload, error) {
|
||||
text, issueTitle, color := getIssueCommentPayloadInfo(p, SlackLinkFormatter, true)
|
||||
text, issueTitle, color := getIssueCommentPayloadInfo(p, SlackLinkFormatter, SlackNameFormatter, true)
|
||||
|
||||
return s.createPayload(text, []SlackAttachment{{
|
||||
Color: fmt.Sprintf("%x", color),
|
||||
|
|
@ -202,20 +205,20 @@ func (s slackConvertor) IssueComment(p *api.IssueCommentPayload) (SlackPayload,
|
|||
|
||||
// Wiki implements payloadConvertor Wiki method
|
||||
func (s slackConvertor) Wiki(p *api.WikiPayload) (SlackPayload, error) {
|
||||
text, _, _ := getWikiPayloadInfo(p, SlackLinkFormatter, true)
|
||||
text, _, _ := getWikiPayloadInfo(p, SlackLinkFormatter, SlackNameFormatter, true)
|
||||
|
||||
return s.createPayload(text, nil), nil
|
||||
}
|
||||
|
||||
// Release implements payloadConvertor Release method
|
||||
func (s slackConvertor) Release(p *api.ReleasePayload) (SlackPayload, error) {
|
||||
text, _ := getReleasePayloadInfo(p, SlackLinkFormatter, true)
|
||||
text, _ := getReleasePayloadInfo(p, SlackLinkFormatter, SlackNameFormatter, true)
|
||||
|
||||
return s.createPayload(text, nil), nil
|
||||
}
|
||||
|
||||
func (s slackConvertor) Package(p *api.PackagePayload) (SlackPayload, error) {
|
||||
text, _ := getPackagePayloadInfo(p, SlackLinkFormatter, true)
|
||||
text, _ := getPackagePayloadInfo(p, SlackLinkFormatter, SlackNameFormatter, true)
|
||||
|
||||
return s.createPayload(text, nil), nil
|
||||
}
|
||||
|
|
@ -240,12 +243,12 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) {
|
|||
}
|
||||
|
||||
branchLink := SlackLinkToRef(p.Repo.HTMLURL, p.Ref)
|
||||
text := fmt.Sprintf("[%s:%s] %s pushed by %s", p.Repo.FullName, branchLink, commitString, p.Pusher.UserName)
|
||||
text := fmt.Sprintf("[%s:%s] %s pushed by %s", p.Repo.FullName, branchLink, commitString, SlackNameFormatter(p.Pusher.UserName))
|
||||
|
||||
var attachmentText string
|
||||
// for each commit, generate attachment text
|
||||
for i, commit := range p.Commits {
|
||||
attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name))
|
||||
attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackNameFormatter(commit.Author.Name))
|
||||
// add linebreak to each commit but the last
|
||||
if i < len(p.Commits)-1 {
|
||||
attachmentText += "\n"
|
||||
|
|
@ -262,7 +265,7 @@ func (s slackConvertor) Push(p *api.PushPayload) (SlackPayload, error) {
|
|||
|
||||
// PullRequest implements payloadConvertor PullRequest method
|
||||
func (s slackConvertor) PullRequest(p *api.PullRequestPayload) (SlackPayload, error) {
|
||||
text, issueTitle, attachmentText, color := getPullRequestPayloadInfo(p, SlackLinkFormatter, true)
|
||||
text, issueTitle, attachmentText, color := getPullRequestPayloadInfo(p, SlackLinkFormatter, SlackNameFormatter, true)
|
||||
|
||||
var attachments []SlackAttachment
|
||||
if attachmentText != "" {
|
||||
|
|
@ -291,7 +294,7 @@ func (s slackConvertor) Review(p *api.PullRequestPayload, event webhook_module.H
|
|||
return SlackPayload{}, err
|
||||
}
|
||||
|
||||
text = fmt.Sprintf("[%s] Pull request review %s: [%s](%s) by %s", p.Repository.FullName, action, title, titleLink, p.Sender.UserName)
|
||||
text = fmt.Sprintf("[%s] Pull request review %s: [%s](%s) by %s", p.Repository.FullName, action, title, titleLink, SlackNameFormatter(p.Sender.UserName))
|
||||
}
|
||||
|
||||
return s.createPayload(text, nil), nil
|
||||
|
|
@ -304,9 +307,9 @@ func (s slackConvertor) Repository(p *api.RepositoryPayload) (SlackPayload, erro
|
|||
|
||||
switch p.Action {
|
||||
case api.HookRepoCreated:
|
||||
text = fmt.Sprintf("[%s] Repository created by %s", repoLink, p.Sender.UserName)
|
||||
text = fmt.Sprintf("[%s] Repository created by %s", repoLink, SlackNameFormatter(p.Sender.UserName))
|
||||
case api.HookRepoDeleted:
|
||||
text = fmt.Sprintf("[%s] Repository deleted by %s", repoLink, p.Sender.UserName)
|
||||
text = fmt.Sprintf("[%s] Repository deleted by %s", repoLink, SlackNameFormatter(p.Sender.UserName))
|
||||
}
|
||||
|
||||
return s.createPayload(text, nil), nil
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.Create(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo:<http://localhost:3000/test/repo/src/branch/test|test>] branch created by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo:<http://localhost:3000/test/repo/src/branch/test|test>] branch created by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
|
|
@ -33,7 +33,7 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.Delete(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>:test] branch deleted by user1", pl.Text)
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>:test] branch deleted by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Fork", func(t *testing.T) {
|
||||
|
|
@ -51,7 +51,7 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.Push(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo:<http://localhost:3000/test/repo/src/branch/test|test>] 2 new commits pushed by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo:<http://localhost:3000/test/repo/src/branch/test|test>] 2 new commits pushed by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Issue", func(t *testing.T) {
|
||||
|
|
@ -61,13 +61,13 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Issue opened: <http://localhost:3000/test/repo/issues/2|#2 crash> by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo] Issue opened: <http://localhost:3000/test/repo/issues/2|#2 crash> by `user1`", pl.Text)
|
||||
|
||||
p.Action = api.HookIssueClosed
|
||||
pl, err = sc.Issue(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Issue closed: <http://localhost:3000/test/repo/issues/2|#2 crash> by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo] Issue closed: <http://localhost:3000/test/repo/issues/2|#2 crash> by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("IssueComment", func(t *testing.T) {
|
||||
|
|
@ -76,7 +76,7 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] New comment on issue <http://localhost:3000/test/repo/issues/2|#2 crash> by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo] New comment on issue <http://localhost:3000/test/repo/issues/2|#2 crash> by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("PullRequest", func(t *testing.T) {
|
||||
|
|
@ -85,7 +85,7 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.PullRequest(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Pull request opened: <http://localhost:3000/test/repo/pulls/12|#12 Fix bug> by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo] Pull request opened: <http://localhost:3000/test/repo/pulls/12|#12 Fix bug> by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("PullRequestComment", func(t *testing.T) {
|
||||
|
|
@ -94,7 +94,7 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.IssueComment(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] New comment on pull request <http://localhost:3000/test/repo/pulls/12|#12 Fix bug> by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo] New comment on pull request <http://localhost:3000/test/repo/pulls/12|#12 Fix bug> by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Review", func(t *testing.T) {
|
||||
|
|
@ -104,7 +104,7 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Pull request review approved: [#12 Fix bug](http://localhost:3000/test/repo/pulls/12) by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo] Pull request review approved: [#12 Fix bug](http://localhost:3000/test/repo/pulls/12) by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Repository", func(t *testing.T) {
|
||||
|
|
@ -113,7 +113,7 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.Repository(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Repository created by user1", pl.Text)
|
||||
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Repository created by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Package", func(t *testing.T) {
|
||||
|
|
@ -122,7 +122,7 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.Package(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Package created: <http://localhost:3000/user1/-/packages/container/GiteaContainer/latest|GiteaContainer:latest> by user1", pl.Text)
|
||||
assert.Equal(t, "Package created: <http://localhost:3000/user1/-/packages/container/GiteaContainer/latest|GiteaContainer:latest> by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Wiki", func(t *testing.T) {
|
||||
|
|
@ -132,19 +132,19 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] New wiki page '<http://localhost:3000/test/repo/wiki/index|index>' (Wiki change comment) by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo] New wiki page '<http://localhost:3000/test/repo/wiki/index|index>' (Wiki change comment) by `user1`", pl.Text)
|
||||
|
||||
p.Action = api.HookWikiEdited
|
||||
pl, err = sc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Wiki page '<http://localhost:3000/test/repo/wiki/index|index>' edited (Wiki change comment) by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo] Wiki page '<http://localhost:3000/test/repo/wiki/index|index>' edited (Wiki change comment) by `user1`", pl.Text)
|
||||
|
||||
p.Action = api.HookWikiDeleted
|
||||
pl, err = sc.Wiki(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Wiki page '<http://localhost:3000/test/repo/wiki/index|index>' deleted by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo] Wiki page '<http://localhost:3000/test/repo/wiki/index|index>' deleted by `user1`", pl.Text)
|
||||
})
|
||||
|
||||
t.Run("Release", func(t *testing.T) {
|
||||
|
|
@ -153,7 +153,7 @@ func TestSlackPayload(t *testing.T) {
|
|||
pl, err := sc.Release(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "[test/repo] Release created: <http://localhost:3000/test/repo/releases/tag/v1.0|v1.0> by user1", pl.Text)
|
||||
assert.Equal(t, "[test/repo] Release created: <http://localhost:3000/test/repo/releases/tag/v1.0|v1.0> by `user1`", pl.Text)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ func TestSlackJSONPayload(t *testing.T) {
|
|||
var body SlackPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "[test/repo:<http://localhost:3000/test/repo/src/branch/test|test>] 2 new commits pushed by user1", body.Text)
|
||||
assert.Equal(t, "[test/repo:<http://localhost:3000/test/repo/src/branch/test|test>] 2 new commits pushed by `user1`", body.Text)
|
||||
}
|
||||
|
||||
func TestIsValidSlackChannel(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -136,21 +136,21 @@ func (t telegramConvertor) Push(p *api.PushPayload) (TelegramPayload, error) {
|
|||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
func (t telegramConvertor) Issue(p *api.IssuePayload) (TelegramPayload, error) {
|
||||
text, _, attachmentText, _ := getIssuesPayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _, attachmentText, _ := getIssuesPayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createTelegramPayload(text + "\n\n" + attachmentText), nil
|
||||
}
|
||||
|
||||
// IssueComment implements PayloadConvertor IssueComment method
|
||||
func (t telegramConvertor) IssueComment(p *api.IssueCommentPayload) (TelegramPayload, error) {
|
||||
text, _, _ := getIssueCommentPayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _, _ := getIssueCommentPayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createTelegramPayload(text + "\n" + p.Comment.Body), nil
|
||||
}
|
||||
|
||||
// PullRequest implements PayloadConvertor PullRequest method
|
||||
func (t telegramConvertor) PullRequest(p *api.PullRequestPayload) (TelegramPayload, error) {
|
||||
text, _, attachmentText, _ := getPullRequestPayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _, attachmentText, _ := getPullRequestPayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createTelegramPayload(text + "\n" + attachmentText), nil
|
||||
}
|
||||
|
|
@ -187,20 +187,20 @@ func (t telegramConvertor) Repository(p *api.RepositoryPayload) (TelegramPayload
|
|||
|
||||
// Wiki implements PayloadConvertor Wiki method
|
||||
func (t telegramConvertor) Wiki(p *api.WikiPayload) (TelegramPayload, error) {
|
||||
text, _, _ := getWikiPayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _, _ := getWikiPayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createTelegramPayload(text), nil
|
||||
}
|
||||
|
||||
// Release implements PayloadConvertor Release method
|
||||
func (t telegramConvertor) Release(p *api.ReleasePayload) (TelegramPayload, error) {
|
||||
text, _ := getReleasePayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _ := getReleasePayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createTelegramPayload(text), nil
|
||||
}
|
||||
|
||||
func (t telegramConvertor) Package(p *api.PackagePayload) (TelegramPayload, error) {
|
||||
text, _ := getPackagePayloadInfo(p, htmlLinkFormatter, true)
|
||||
text, _ := getPackagePayloadInfo(p, htmlLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return createTelegramPayload(text), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ func (wc wechatworkConvertor) Push(p *api.PushPayload) (WechatworkPayload, error
|
|||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
func (wc wechatworkConvertor) Issue(p *api.IssuePayload) (WechatworkPayload, error) {
|
||||
text, issueTitle, attachmentText, _ := getIssuesPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, issueTitle, attachmentText, _ := getIssuesPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
var content string
|
||||
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)
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ func (wc wechatworkConvertor) Issue(p *api.IssuePayload) (WechatworkPayload, err
|
|||
|
||||
// IssueComment implements PayloadConvertor IssueComment method
|
||||
func (wc wechatworkConvertor) IssueComment(p *api.IssueCommentPayload) (WechatworkPayload, error) {
|
||||
text, issueTitle, _ := getIssueCommentPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, issueTitle, _ := getIssueCommentPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
var content string
|
||||
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)
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ func (wc wechatworkConvertor) IssueComment(p *api.IssueCommentPayload) (Wechatwo
|
|||
|
||||
// PullRequest implements PayloadConvertor PullRequest method
|
||||
func (wc wechatworkConvertor) PullRequest(p *api.PullRequestPayload) (WechatworkPayload, error) {
|
||||
text, issueTitle, attachmentText, _ := getPullRequestPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, issueTitle, attachmentText, _ := getPullRequestPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
pr := fmt.Sprintf("> <font color=\"info\"> %s </font> \r\n > <font color=\"comment\">%s </font> \r\n > <font color=\"comment\">%s </font> \r\n",
|
||||
text, issueTitle, attachmentText)
|
||||
|
||||
|
|
@ -183,20 +183,20 @@ func (wc wechatworkConvertor) Repository(p *api.RepositoryPayload) (WechatworkPa
|
|||
|
||||
// Wiki implements PayloadConvertor Wiki method
|
||||
func (wc wechatworkConvertor) Wiki(p *api.WikiPayload) (WechatworkPayload, error) {
|
||||
text, _, _ := getWikiPayloadInfo(p, noneLinkFormatter, true)
|
||||
text, _, _ := getWikiPayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return newWechatworkMarkdownPayload(text), nil
|
||||
}
|
||||
|
||||
// Release implements PayloadConvertor Release method
|
||||
func (wc wechatworkConvertor) Release(p *api.ReleasePayload) (WechatworkPayload, error) {
|
||||
text, _ := getReleasePayloadInfo(p, noneLinkFormatter, true)
|
||||
text, _ := getReleasePayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return newWechatworkMarkdownPayload(text), nil
|
||||
}
|
||||
|
||||
func (wc wechatworkConvertor) Package(p *api.PackagePayload) (WechatworkPayload, error) {
|
||||
text, _ := getPackagePayloadInfo(p, noneLinkFormatter, true)
|
||||
text, _ := getPackagePayloadInfo(p, noneLinkFormatter, noneNameFormatter, true)
|
||||
|
||||
return newWechatworkMarkdownPayload(text), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue