package task import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/services/task" "strings" ) type taskNotifier struct { base.NullNotifier } var ( _ base.Notifier = &taskNotifier{} ) // NewNotifier create a new actionNotifier notifier func NewNotifier() base.Notifier { return &taskNotifier{} } func (t *taskNotifier) NotifyNewIssue(issue *models.Issue) { task.Accomplish(issue.Poster.ID, models.TaskTypeNewIssue) } // NotifyIssueChangeStatus notifies close or reopen issue to notifiers func (t *taskNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) { task.Accomplish(doer.ID, models.TaskTypeIssueChangeStatus) } // NotifyCreateIssueComment notifies comment on an issue to notifiers func (t *taskNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, issue *models.Issue, comment *models.Comment) { task.Accomplish(doer.ID, models.TaskTypeCreateIssueComment) } func (t *taskNotifier) NotifyNewPullRequest(pull *models.PullRequest) { task.Accomplish(pull.Issue.Poster.ID, models.TaskTypeNewPullRequest) } func (t *taskNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { task.Accomplish(doer.ID, models.TaskTypeRenameRepository) } func (t *taskNotifier) NotifyAliasRepository(doer *models.User, repo *models.Repository, oldAlias string) { task.Accomplish(doer.ID, models.TaskTypeAliasRepository) } func (t *taskNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { task.Accomplish(doer.ID, models.TaskTypeTransferRepository) } func (t *taskNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { if !repo.IsPrivate { task.Accomplish(doer.ID, models.TaskTypeCreatePublicRepository) } } func (t *taskNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) { task.Accomplish(doer.ID, models.TaskTypeForkRepository) } func (t *taskNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment) { for _, lines := range review.CodeComments { for _, comments := range lines { for _, _ = range comments { task.Accomplish(review.Reviewer.ID, models.TaskTypePullRequestReview) } } } if review.Type != models.ReviewTypeComment || strings.TrimSpace(comment.Content) != "" { switch review.Type { case models.ReviewTypeApprove: task.Accomplish(review.Reviewer.ID, models.TaskTypeApprovePullRequest) case models.ReviewTypeReject: task.Accomplish(review.Reviewer.ID, models.TaskTypeRejectPullRequest) default: task.Accomplish(review.Reviewer.ID, models.TaskTypeCommentPull) } } } func (t *taskNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) { task.Accomplish(doer.ID, models.TaskTypeMergePullRequest) } func (t *taskNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) { task.Accomplish(repo.OwnerID, models.TaskTypeSyncPushCommits) } func (t *taskNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) { task.Accomplish(repo.OwnerID, models.TaskTypeSyncCreateRef) } func (t *taskNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) { task.Accomplish(repo.OwnerID, models.TaskTypeSyncDeleteRef) } func (t *taskNotifier) NotifyOtherTask(doer *models.User, repo *models.Repository, id string, name string, optype models.ActionType) { switch optype { case models.ActionUploadAttachment: task.Accomplish(doer.ID, models.TaskTypeUploadAttachment) case models.ActionCreateDebugGPUTask, models.ActionCreateDebugNPUTask, models.ActionCreateTrainTask, models.ActionCreateInferenceTask, models.ActionCreateBenchMarkTask, models.ActionCreateGPUTrainTask: task.Accomplish(doer.ID, models.TaskTypeCreateCloudbrainTask) case models.ActionCreateNewModelTask: task.Accomplish(doer.ID, models.TaskTypeCreateModel) } return } func (t *taskNotifier) NotifyWechatBind(userId int64, wechatOpenId string) { task.Accomplish(userId, models.TaskTypeBindWechat) } func (t *taskNotifier) NotifyDatasetRecommend(optUser *models.User, dataset *models.Dataset, action string) { switch action { case "recommend": userIds, err := models.GetAllUserIdByDatasetId(dataset.ID) if err != nil { return } for _, userId := range userIds { task.Accomplish(userId, models.TaskTypeDatasetRecommended) } } } func (t *taskNotifier) NotifyCreateImage(optUserId int64, image models.Image) { if !image.IsPrivate { task.Accomplish(optUserId, models.TaskTypeCreatePublicImage) } } func (t *taskNotifier) NotifyImageRecommend(optUser *models.User, imageId int64, action string) { switch action { case "recommend": task.Accomplish(optUser.ID, models.TaskTypeImageRecommend) } } func (t *taskNotifier) NotifyChangeUserAvatar(user *models.User) { task.Accomplish(user.ID, models.TaskTypeChangeUserAvatar) } func (t *taskNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) { task.Accomplish(pusher.ID, models.TaskTypePushCommits) }