Skip to content

Commit b702650

Browse files
committed
move create issue comment to comments package
1 parent 5a438ee commit b702650

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

models/issue_comment.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -811,35 +811,6 @@ func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) {
811811
return comment, nil
812812
}
813813

814-
// CreateIssueComment creates a plain issue comment.
815-
func CreateIssueComment(doer *User, repo *Repository, issue *Issue, content string, attachments []string) (*Comment, error) {
816-
comment, err := CreateComment(&CreateCommentOptions{
817-
Type: CommentTypeComment,
818-
Doer: doer,
819-
Repo: repo,
820-
Issue: issue,
821-
Content: content,
822-
Attachments: attachments,
823-
})
824-
if err != nil {
825-
return nil, fmt.Errorf("CreateComment: %v", err)
826-
}
827-
828-
mode, _ := AccessLevel(doer, repo)
829-
if err = PrepareWebhooks(repo, HookEventIssueComment, &api.IssueCommentPayload{
830-
Action: api.HookIssueCommentCreated,
831-
Issue: issue.APIFormat(),
832-
Comment: comment.APIFormat(),
833-
Repository: repo.APIFormat(mode),
834-
Sender: doer.APIFormat(),
835-
}); err != nil {
836-
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
837-
} else {
838-
go HookQueue.Add(repo.ID)
839-
}
840-
return comment, nil
841-
}
842-
843814
// CreateRefComment creates a commit reference comment to issue.
844815
func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commitSHA string) error {
845816
if len(commitSHA) == 0 {

routers/api/v1/repo/issue_comment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/modules/context"
1313
"code.gitea.io/gitea/modules/notification"
1414
api "code.gitea.io/gitea/modules/structs"
15+
comment_service "code.gitea.io/gitea/services/comments"
1516
)
1617

1718
// ListIssueComments list all the comments of an issue
@@ -189,7 +190,7 @@ func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOpti
189190
return
190191
}
191192

192-
comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Body, nil)
193+
comment, err := comment_service.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Body, nil)
193194
if err != nil {
194195
ctx.Error(500, "CreateIssueComment", err)
195196
return

routers/repo/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"code.gitea.io/gitea/modules/setting"
2727
api "code.gitea.io/gitea/modules/structs"
2828
"code.gitea.io/gitea/modules/util"
29+
comment_service "code.gitea.io/gitea/services/comments"
2930
milestone_service "code.gitea.io/gitea/services/milestone"
3031

3132
"github.com/unknwon/com"
@@ -1299,7 +1300,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
12991300
return
13001301
}
13011302

1302-
comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
1303+
comment, err := comment_service.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
13031304
if err != nil {
13041305
ctx.ServerError("CreateIssueComment", err)
13051306
return

services/comments/comments.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,41 @@ import (
1111

1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/modules/git"
14+
"code.gitea.io/gitea/modules/log"
1415
"code.gitea.io/gitea/modules/setting"
16+
api "code.gitea.io/gitea/modules/structs"
1517
"code.gitea.io/gitea/services/gitdiff"
1618
)
1719

20+
// CreateIssueComment creates a plain issue comment.
21+
func CreateIssueComment(doer *models.User, repo *models.Repository, issue *models.Issue, content string, attachments []string) (*models.Comment, error) {
22+
comment, err := models.CreateComment(&models.CreateCommentOptions{
23+
Type: models.CommentTypeComment,
24+
Doer: doer,
25+
Repo: repo,
26+
Issue: issue,
27+
Content: content,
28+
Attachments: attachments,
29+
})
30+
if err != nil {
31+
return nil, err
32+
}
33+
34+
mode, _ := models.AccessLevel(doer, repo)
35+
if err = models.PrepareWebhooks(repo, models.HookEventIssueComment, &api.IssueCommentPayload{
36+
Action: api.HookIssueCommentCreated,
37+
Issue: issue.APIFormat(),
38+
Comment: comment.APIFormat(),
39+
Repository: repo.APIFormat(mode),
40+
Sender: doer.APIFormat(),
41+
}); err != nil {
42+
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
43+
} else {
44+
go models.HookQueue.Add(repo.ID)
45+
}
46+
return comment, nil
47+
}
48+
1849
// CreateCodeComment creates a plain code comment at the specified line / path
1950
func CreateCodeComment(doer *models.User, repo *models.Repository, issue *models.Issue, content, treePath string, line, reviewID int64) (*models.Comment, error) {
2051
var commitID, patch string

0 commit comments

Comments
 (0)