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.

action.go 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 action
  5. import (
  6. "fmt"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/notification/base"
  10. )
  11. type actionNotifier struct {
  12. base.NullNotifier
  13. }
  14. var (
  15. _ base.Notifier = &actionNotifier{}
  16. )
  17. // NewNotifier create a new webhookNotifier notifier
  18. func NewNotifier() base.Notifier {
  19. return &actionNotifier{}
  20. }
  21. func (a *actionNotifier) NotifyNewIssue(issue *models.Issue) {
  22. if err := issue.LoadPoster(); err != nil {
  23. log.Error("issue.LoadPoster: %v", err)
  24. return
  25. }
  26. if err := issue.LoadRepo(); err != nil {
  27. log.Error("issue.LoadRepo: %v", err)
  28. return
  29. }
  30. repo := issue.Repo
  31. if err := models.NotifyWatchers(&models.Action{
  32. ActUserID: issue.Poster.ID,
  33. ActUser: issue.Poster,
  34. OpType: models.ActionCreateIssue,
  35. Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
  36. RepoID: repo.ID,
  37. Repo: repo,
  38. IsPrivate: repo.IsPrivate,
  39. }); err != nil {
  40. log.Error("NotifyWatchers: %v", err)
  41. }
  42. }
  43. func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest) {
  44. if err := pull.LoadIssue(); err != nil {
  45. log.Error("pull.LoadIssue: %v", err)
  46. return
  47. }
  48. if err := pull.Issue.LoadRepo(); err != nil {
  49. log.Error("pull.Issue.LoadRepo: %v", err)
  50. return
  51. }
  52. if err := pull.Issue.LoadPoster(); err != nil {
  53. log.Error("pull.Issue.LoadPoster: %v", err)
  54. return
  55. }
  56. if err := models.NotifyWatchers(&models.Action{
  57. ActUserID: pull.Issue.Poster.ID,
  58. ActUser: pull.Issue.Poster,
  59. OpType: models.ActionCreatePullRequest,
  60. Content: fmt.Sprintf("%d|%s", pull.Issue.Index, pull.Issue.Title),
  61. RepoID: pull.Issue.Repo.ID,
  62. Repo: pull.Issue.Repo,
  63. IsPrivate: pull.Issue.Repo.IsPrivate,
  64. }); err != nil {
  65. log.Error("NotifyWatchers: %v", err)
  66. }
  67. }