Skip to content

Commit 0ace4ce

Browse files
jim-kirisamelunnytechknowlogick
authored
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>
1 parent 6f3efdf commit 0ace4ce

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

services/webhook/general.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@ func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkForm
8484
issueTitle := fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title)
8585
titleLink := linkFormatter(p.PullRequest.URL, issueTitle)
8686
var text string
87+
var attachmentText string
8788
color := yellowColor
8889

8990
switch p.Action {
9091
case api.HookIssueOpened:
9192
text = fmt.Sprintf("[%s] Pull request opened: %s", repoLink, titleLink)
93+
attachmentText = p.PullRequest.Body
9294
color = greenColor
9395
case api.HookIssueClosed:
9496
if p.PullRequest.HasMerged {
@@ -102,6 +104,7 @@ func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkForm
102104
text = fmt.Sprintf("[%s] Pull request re-opened: %s", repoLink, titleLink)
103105
case api.HookIssueEdited:
104106
text = fmt.Sprintf("[%s] Pull request edited: %s", repoLink, titleLink)
107+
attachmentText = p.PullRequest.Body
105108
case api.HookIssueAssigned:
106109
list := make([]string, len(p.PullRequest.Assignees))
107110
for i, user := range p.PullRequest.Assignees {
@@ -126,16 +129,12 @@ func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkForm
126129
text = fmt.Sprintf("[%s] Pull request milestone cleared: %s", repoLink, titleLink)
127130
case api.HookIssueReviewed:
128131
text = fmt.Sprintf("[%s] Pull request reviewed: %s", repoLink, titleLink)
132+
attachmentText = p.Review.Content
129133
}
130134
if withSender {
131135
text += fmt.Sprintf(" by %s", linkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName))
132136
}
133137

134-
var attachmentText string
135-
if p.Action == api.HookIssueOpened || p.Action == api.HookIssueEdited {
136-
attachmentText = p.PullRequest.Body
137-
}
138-
139138
return text, issueTitle, attachmentText, color
140139
}
141140

0 commit comments

Comments
 (0)