mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 22:13:26 +09:00
feat(webhook): add reviewer name to MS Teams review request notifications (#38289)
Include the requested reviewer's username (along with their full name in parentheses, if available) and render the `Repository` and `Pull request` fields as clickable links in Microsoft Teams webhook notifications. Fixes: https://github.com/go-gitea/gitea/issues/38270 ## Screenshots <img width="1246" height="651" alt="image" src="https://github.com/user-attachments/assets/7299ce10-c6d4-4c89-a05a-a258d72c00e5" /> --------- Signed-off-by: Shudhanshu Singh <sudhanshuwriterblc@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
co-authored by
wxiaoguang
parent
a46e331637
commit
582217a0da
@@ -187,6 +187,18 @@ func (m msteamsConvertor) IssueComment(p *api.IssueCommentPayload) (MSTeamsPaylo
|
||||
func (m msteamsConvertor) PullRequest(p *api.PullRequestPayload) (MSTeamsPayload, error) {
|
||||
title, _, extraMarkdown, color := getPullRequestPayloadInfo(p, noneLinkFormatter, false)
|
||||
|
||||
facts := []*MSTeamsFact{
|
||||
{"Pull request:", fmt.Sprintf("[#%d](%s)", p.PullRequest.Index, p.PullRequest.HTMLURL)},
|
||||
}
|
||||
|
||||
if (p.Action == api.HookIssueReviewRequested || p.Action == api.HookIssueReviewRequestRemoved) && p.RequestedReviewer != nil {
|
||||
reviewerName := p.RequestedReviewer.UserName
|
||||
if p.RequestedReviewer.FullName != "" {
|
||||
reviewerName += " (" + p.RequestedReviewer.FullName + ")"
|
||||
}
|
||||
facts = append(facts, &MSTeamsFact{"Requested Reviewer:", reviewerName})
|
||||
}
|
||||
|
||||
return createMSTeamsPayload(
|
||||
p.Repository,
|
||||
p.Sender,
|
||||
@@ -194,7 +206,7 @@ func (m msteamsConvertor) PullRequest(p *api.PullRequestPayload) (MSTeamsPayload
|
||||
extraMarkdown,
|
||||
p.PullRequest.HTMLURL,
|
||||
color,
|
||||
&MSTeamsFact{"Pull request #:", strconv.FormatInt(p.PullRequest.ID, 10)},
|
||||
facts...,
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -231,7 +243,7 @@ func (m msteamsConvertor) Review(p *api.PullRequestPayload, event webhook_module
|
||||
text,
|
||||
p.PullRequest.HTMLURL,
|
||||
color,
|
||||
&MSTeamsFact{"Pull request #:", strconv.FormatInt(p.PullRequest.ID, 10)},
|
||||
&MSTeamsFact{"Pull request:", fmt.Sprintf("[#%d](%s)", p.PullRequest.Index, p.PullRequest.HTMLURL)},
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -271,7 +283,6 @@ func (m msteamsConvertor) Wiki(p *api.WikiPayload) (MSTeamsPayload, error) {
|
||||
"",
|
||||
p.Repository.HTMLURL+"/wiki/"+url.PathEscape(p.Page),
|
||||
color,
|
||||
&MSTeamsFact{"Repository:", p.Repository.FullName},
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -346,16 +357,18 @@ func (msteamsConvertor) WorkflowJob(p *api.WorkflowJobPayload) (MSTeamsPayload,
|
||||
), nil
|
||||
}
|
||||
|
||||
func createMSTeamsPayload(r *api.Repository, s *api.User, title, text, actionTarget string, color int, fact *MSTeamsFact) MSTeamsPayload {
|
||||
facts := make([]MSTeamsFact, 0, 2)
|
||||
func createMSTeamsPayload(r *api.Repository, s *api.User, title, text, actionTarget string, color int, extraFacts ...*MSTeamsFact) MSTeamsPayload {
|
||||
facts := make([]MSTeamsFact, 0, len(extraFacts)+1)
|
||||
if r != nil {
|
||||
facts = append(facts, MSTeamsFact{
|
||||
Name: "Repository:",
|
||||
Value: r.FullName,
|
||||
Value: fmt.Sprintf("[%s](%s)", r.FullName, r.HTMLURL),
|
||||
})
|
||||
}
|
||||
if fact != nil {
|
||||
facts = append(facts, *fact)
|
||||
for _, f := range extraFacts {
|
||||
if f != nil {
|
||||
facts = append(facts, *f)
|
||||
}
|
||||
}
|
||||
|
||||
return MSTeamsPayload{
|
||||
|
||||
Reference in New Issue
Block a user