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

task.go 5.4 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package task
  2. import (
  3. "code.gitea.io/gitea/models"
  4. "code.gitea.io/gitea/modules/notification/base"
  5. "code.gitea.io/gitea/modules/repository"
  6. "code.gitea.io/gitea/services/task"
  7. "strings"
  8. )
  9. type taskNotifier struct {
  10. base.NullNotifier
  11. }
  12. var (
  13. _ base.Notifier = &taskNotifier{}
  14. )
  15. // NewNotifier create a new actionNotifier notifier
  16. func NewNotifier() base.Notifier {
  17. return &taskNotifier{}
  18. }
  19. func (t *taskNotifier) NotifyNewIssue(issue *models.Issue) {
  20. task.Accomplish(issue.Poster.ID, models.TaskTypeNewIssue)
  21. }
  22. // NotifyIssueChangeStatus notifies close or reopen issue to notifiers
  23. func (t *taskNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) {
  24. task.Accomplish(doer.ID, models.TaskTypeIssueChangeStatus)
  25. }
  26. // NotifyCreateIssueComment notifies comment on an issue to notifiers
  27. func (t *taskNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
  28. issue *models.Issue, comment *models.Comment) {
  29. task.Accomplish(doer.ID, models.TaskTypeCreateIssueComment)
  30. }
  31. func (t *taskNotifier) NotifyNewPullRequest(pull *models.PullRequest) {
  32. task.Accomplish(pull.Issue.Poster.ID, models.TaskTypeNewPullRequest)
  33. }
  34. func (t *taskNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) {
  35. task.Accomplish(doer.ID, models.TaskTypeRenameRepository)
  36. }
  37. func (t *taskNotifier) NotifyAliasRepository(doer *models.User, repo *models.Repository, oldAlias string) {
  38. task.Accomplish(doer.ID, models.TaskTypeAliasRepository)
  39. }
  40. func (t *taskNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) {
  41. task.Accomplish(doer.ID, models.TaskTypeTransferRepository)
  42. }
  43. func (t *taskNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  44. if !repo.IsPrivate {
  45. task.Accomplish(doer.ID, models.TaskTypeCreatePublicRepository)
  46. }
  47. }
  48. func (t *taskNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
  49. task.Accomplish(doer.ID, models.TaskTypeForkRepository)
  50. }
  51. func (t *taskNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment) {
  52. for _, lines := range review.CodeComments {
  53. for _, comments := range lines {
  54. for _, _ = range comments {
  55. task.Accomplish(review.Reviewer.ID, models.TaskTypePullRequestReview)
  56. }
  57. }
  58. }
  59. if review.Type != models.ReviewTypeComment || strings.TrimSpace(comment.Content) != "" {
  60. switch review.Type {
  61. case models.ReviewTypeApprove:
  62. task.Accomplish(review.Reviewer.ID, models.TaskTypeApprovePullRequest)
  63. case models.ReviewTypeReject:
  64. task.Accomplish(review.Reviewer.ID, models.TaskTypeRejectPullRequest)
  65. default:
  66. task.Accomplish(review.Reviewer.ID, models.TaskTypeCommentPull)
  67. }
  68. }
  69. }
  70. func (t *taskNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
  71. task.Accomplish(doer.ID, models.TaskTypeMergePullRequest)
  72. }
  73. func (t *taskNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) {
  74. task.Accomplish(repo.OwnerID, models.TaskTypeSyncPushCommits)
  75. }
  76. func (t *taskNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
  77. task.Accomplish(repo.OwnerID, models.TaskTypeSyncCreateRef)
  78. }
  79. func (t *taskNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
  80. task.Accomplish(repo.OwnerID, models.TaskTypeSyncDeleteRef)
  81. }
  82. func (t *taskNotifier) NotifyOtherTask(doer *models.User, repo *models.Repository, id string, name string, optype models.ActionType) {
  83. switch optype {
  84. case models.ActionUploadAttachment:
  85. task.Accomplish(doer.ID, models.TaskTypeUploadAttachment)
  86. case models.ActionCreateDebugGPUTask,
  87. models.ActionCreateDebugNPUTask,
  88. models.ActionCreateTrainTask,
  89. models.ActionCreateInferenceTask,
  90. models.ActionCreateBenchMarkTask,
  91. models.ActionCreateGPUTrainTask:
  92. task.Accomplish(doer.ID, models.TaskTypeCreateCloudbrainTask)
  93. case models.ActionCreateNewModelTask:
  94. task.Accomplish(doer.ID, models.TaskTypeCreateModel)
  95. }
  96. return
  97. }
  98. func (t *taskNotifier) NotifyWechatBind(userId int64, wechatOpenId string) {
  99. task.Accomplish(userId, models.TaskTypeBindWechat)
  100. }
  101. func (t *taskNotifier) NotifyDatasetRecommend(optUser *models.User, dataset *models.Dataset, action string) {
  102. switch action {
  103. case "recommend":
  104. userIds, err := models.GetAllUserIdByDatasetId(dataset.ID)
  105. if err != nil {
  106. return
  107. }
  108. for _, userId := range userIds {
  109. task.Accomplish(userId, models.TaskTypeDatasetRecommended)
  110. }
  111. }
  112. }
  113. func (t *taskNotifier) NotifyCreateImage(optUserId int64, image models.Image) {
  114. if !image.IsPrivate {
  115. task.Accomplish(optUserId, models.TaskTypeCreatePublicImage)
  116. }
  117. }
  118. func (t *taskNotifier) NotifyImageRecommend(optUser *models.User, imageId int64, action string) {
  119. switch action {
  120. case "recommend":
  121. task.Accomplish(optUser.ID, models.TaskTypeImageRecommend)
  122. }
  123. }
  124. func (t *taskNotifier) NotifyChangeUserAvatar(user *models.User) {
  125. task.Accomplish(user.ID, models.TaskTypeChangeUserAvatar)
  126. }
  127. func (t *taskNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) {
  128. task.Accomplish(pusher.ID, models.TaskTypePushCommits)
  129. }