forked from gitea/gitea
Fix webhook attachment text is not set in review comment (#21763)
The `getPullRequestPayloadInfo` function is widely used in many webhook, it works well when PR is open or edit. But when we comment in PR review panel (not PR panel), the comment content is not set as `attachmentText`. This commit set comment content as `attachmentText` when PR review, so webhook could obtain this information via this function. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
6f3efdfe11
commit
0ace4cee33
|
@ -84,11 +84,13 @@ func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkForm
|
||||||
issueTitle := fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title)
|
issueTitle := fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title)
|
||||||
titleLink := linkFormatter(p.PullRequest.URL, issueTitle)
|
titleLink := linkFormatter(p.PullRequest.URL, issueTitle)
|
||||||
var text string
|
var text string
|
||||||
|
var attachmentText string
|
||||||
color := yellowColor
|
color := yellowColor
|
||||||
|
|
||||||
switch p.Action {
|
switch p.Action {
|
||||||
case api.HookIssueOpened:
|
case api.HookIssueOpened:
|
||||||
text = fmt.Sprintf("[%s] Pull request opened: %s", repoLink, titleLink)
|
text = fmt.Sprintf("[%s] Pull request opened: %s", repoLink, titleLink)
|
||||||
|
attachmentText = p.PullRequest.Body
|
||||||
color = greenColor
|
color = greenColor
|
||||||
case api.HookIssueClosed:
|
case api.HookIssueClosed:
|
||||||
if p.PullRequest.HasMerged {
|
if p.PullRequest.HasMerged {
|
||||||
|
@ -102,6 +104,7 @@ func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkForm
|
||||||
text = fmt.Sprintf("[%s] Pull request re-opened: %s", repoLink, titleLink)
|
text = fmt.Sprintf("[%s] Pull request re-opened: %s", repoLink, titleLink)
|
||||||
case api.HookIssueEdited:
|
case api.HookIssueEdited:
|
||||||
text = fmt.Sprintf("[%s] Pull request edited: %s", repoLink, titleLink)
|
text = fmt.Sprintf("[%s] Pull request edited: %s", repoLink, titleLink)
|
||||||
|
attachmentText = p.PullRequest.Body
|
||||||
case api.HookIssueAssigned:
|
case api.HookIssueAssigned:
|
||||||
list := make([]string, len(p.PullRequest.Assignees))
|
list := make([]string, len(p.PullRequest.Assignees))
|
||||||
for i, user := range p.PullRequest.Assignees {
|
for i, user := range p.PullRequest.Assignees {
|
||||||
|
@ -126,16 +129,12 @@ func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkForm
|
||||||
text = fmt.Sprintf("[%s] Pull request milestone cleared: %s", repoLink, titleLink)
|
text = fmt.Sprintf("[%s] Pull request milestone cleared: %s", repoLink, titleLink)
|
||||||
case api.HookIssueReviewed:
|
case api.HookIssueReviewed:
|
||||||
text = fmt.Sprintf("[%s] Pull request reviewed: %s", repoLink, titleLink)
|
text = fmt.Sprintf("[%s] Pull request reviewed: %s", repoLink, titleLink)
|
||||||
|
attachmentText = p.Review.Content
|
||||||
}
|
}
|
||||||
if withSender {
|
if withSender {
|
||||||
text += fmt.Sprintf(" by %s", linkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName))
|
text += fmt.Sprintf(" by %s", linkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName))
|
||||||
}
|
}
|
||||||
|
|
||||||
var attachmentText string
|
|
||||||
if p.Action == api.HookIssueOpened || p.Action == api.HookIssueEdited {
|
|
||||||
attachmentText = p.PullRequest.Body
|
|
||||||
}
|
|
||||||
|
|
||||||
return text, issueTitle, attachmentText, color
|
return text, issueTitle, attachmentText, color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue