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.

assignee.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 issue
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/notification"
  8. )
  9. // DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array
  10. func DeleteNotPassedAssignee(issue *models.Issue, doer *models.User, assignees []*models.User) (err error) {
  11. var found bool
  12. for _, assignee := range issue.Assignees {
  13. found = false
  14. for _, alreadyAssignee := range assignees {
  15. if assignee.ID == alreadyAssignee.ID {
  16. found = true
  17. break
  18. }
  19. }
  20. if !found {
  21. // This function also does comments and hooks, which is why we call it seperatly instead of directly removing the assignees here
  22. if _, _, err := ToggleAssignee(issue, doer, assignee.ID); err != nil {
  23. return err
  24. }
  25. }
  26. }
  27. return nil
  28. }
  29. // ToggleAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
  30. func ToggleAssignee(issue *models.Issue, doer *models.User, assigneeID int64) (removed bool, comment *models.Comment, err error) {
  31. removed, comment, err = issue.ToggleAssignee(doer, assigneeID)
  32. if err != nil {
  33. return
  34. }
  35. assignee, err1 := models.GetUserByID(assigneeID)
  36. if err1 != nil {
  37. err = err1
  38. return
  39. }
  40. notification.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment)
  41. return
  42. }
  43. // ReviewRequest add or remove a review for this PR, and make comment for it.
  44. func ReviewRequest(issue *models.Issue, doer *models.User, reviewer *models.User, isAdd bool) (err error) {
  45. var comment *models.Comment
  46. if isAdd {
  47. comment, err = models.AddRewiewRequest(issue, reviewer, doer)
  48. } else {
  49. comment, err = models.RemoveRewiewRequest(issue, reviewer, doer)
  50. }
  51. if err != nil {
  52. return
  53. }
  54. if comment != nil {
  55. notification.NotifyPullRewiewRequest(doer, issue, reviewer, isAdd, comment)
  56. }
  57. return nil
  58. }