You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3 KiB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package comments
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/notification"
  8. )
  9. // CreateIssueComment creates a plain issue comment.
  10. func CreateIssueComment(doer *models.User, repo *models.Repository, issue *models.Issue, content string, attachments []string) (*models.Comment, error) {
  11. comment, err := models.CreateComment(&models.CreateCommentOptions{
  12. Type: models.CommentTypeComment,
  13. Doer: doer,
  14. Repo: repo,
  15. Issue: issue,
  16. Content: content,
  17. Attachments: attachments,
  18. })
  19. if err != nil {
  20. return nil, err
  21. }
  22. notification.NotifyCreateIssueComment(doer, repo, issue, comment)
  23. return comment, nil
  24. }
  25. // UpdateComment updates information of comment.
  26. func UpdateComment(c *models.Comment, doer *models.User, oldContent string) error {
  27. if err := models.UpdateComment(c, doer); err != nil {
  28. return err
  29. }
  30. notification.NotifyUpdateComment(doer, c, oldContent)
  31. return nil
  32. }
  33. // DeleteComment deletes the comment
  34. func DeleteComment(comment *models.Comment, doer *models.User) error {
  35. if err := models.DeleteComment(comment, doer); err != nil {
  36. return err
  37. }
  38. notification.NotifyDeleteComment(doer, comment)
  39. return nil
  40. }