Skip to content

Commit 8dbe83d

Browse files
GiteaBotKN4CK3R
andauthored
Add missing comment reply handling (#32050) (#32065)
Backport #32050 by @KN4CK3R Fixes #31937 - Add missing comment reply handling - Use `onGiteaRun` in the test because the fixtures are not present otherwise (did this behaviour change?) Compare without whitespaces. Co-authored-by: KN4CK3R <[email protected]>
1 parent 2831ae3 commit 8dbe83d

File tree

2 files changed

+172
-166
lines changed

2 files changed

+172
-166
lines changed

services/mailer/incoming/incoming_handler.go

+29-27
Original file line numberDiff line numberDiff line change
@@ -82,43 +82,40 @@ func (h *ReplyHandler) Handle(ctx context.Context, content *MailContent, doer *u
8282
return nil
8383
}
8484

85-
switch r := ref.(type) {
86-
case *issues_model.Issue:
87-
attachmentIDs := make([]string, 0, len(content.Attachments))
88-
if setting.Attachment.Enabled {
89-
for _, attachment := range content.Attachments {
90-
a, err := attachment_service.UploadAttachment(ctx, bytes.NewReader(attachment.Content), setting.Attachment.AllowedTypes, int64(len(attachment.Content)), &repo_model.Attachment{
91-
Name: attachment.Name,
92-
UploaderID: doer.ID,
93-
RepoID: issue.Repo.ID,
94-
})
95-
if err != nil {
96-
if upload.IsErrFileTypeForbidden(err) {
97-
log.Info("Skipping disallowed attachment type: %s", attachment.Name)
98-
continue
99-
}
100-
return err
85+
attachmentIDs := make([]string, 0, len(content.Attachments))
86+
if setting.Attachment.Enabled {
87+
for _, attachment := range content.Attachments {
88+
a, err := attachment_service.UploadAttachment(ctx, bytes.NewReader(attachment.Content), setting.Attachment.AllowedTypes, int64(len(attachment.Content)), &repo_model.Attachment{
89+
Name: attachment.Name,
90+
UploaderID: doer.ID,
91+
RepoID: issue.Repo.ID,
92+
})
93+
if err != nil {
94+
if upload.IsErrFileTypeForbidden(err) {
95+
log.Info("Skipping disallowed attachment type: %s", attachment.Name)
96+
continue
10197
}
102-
attachmentIDs = append(attachmentIDs, a.UUID)
98+
return err
10399
}
100+
attachmentIDs = append(attachmentIDs, a.UUID)
104101
}
102+
}
105103

106-
if content.Content == "" && len(attachmentIDs) == 0 {
107-
return nil
108-
}
104+
if content.Content == "" && len(attachmentIDs) == 0 {
105+
return nil
106+
}
109107

110-
_, err = issue_service.CreateIssueComment(ctx, doer, issue.Repo, issue, content.Content, attachmentIDs)
108+
switch r := ref.(type) {
109+
case *issues_model.Issue:
110+
_, err := issue_service.CreateIssueComment(ctx, doer, issue.Repo, issue, content.Content, attachmentIDs)
111111
if err != nil {
112112
return fmt.Errorf("CreateIssueComment failed: %w", err)
113113
}
114114
case *issues_model.Comment:
115115
comment := r
116116

117-
if content.Content == "" {
118-
return nil
119-
}
120-
121-
if comment.Type == issues_model.CommentTypeCode {
117+
switch comment.Type {
118+
case issues_model.CommentTypeCode:
122119
_, err := pull_service.CreateCodeComment(
123120
ctx,
124121
doer,
@@ -130,11 +127,16 @@ func (h *ReplyHandler) Handle(ctx context.Context, content *MailContent, doer *u
130127
false, // not pending review but a single review
131128
comment.ReviewID,
132129
"",
133-
nil,
130+
attachmentIDs,
134131
)
135132
if err != nil {
136133
return fmt.Errorf("CreateCodeComment failed: %w", err)
137134
}
135+
default:
136+
_, err := issue_service.CreateIssueComment(ctx, doer, issue.Repo, issue, content.Content, attachmentIDs)
137+
if err != nil {
138+
return fmt.Errorf("CreateIssueComment failed: %w", err)
139+
}
138140
}
139141
}
140142
return nil

0 commit comments

Comments
 (0)