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.

issue.go 2.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. "fmt"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/log"
  9. api "code.gitea.io/gitea/modules/structs"
  10. )
  11. // NewIssue creates new issue with labels for repository.
  12. func NewIssue(repo *models.Repository, issue *models.Issue, labelIDs []int64, assigneeIDs []int64, uuids []string) error {
  13. if err := models.NewIssue(repo, issue, labelIDs, assigneeIDs, uuids); err != nil {
  14. return err
  15. }
  16. if err := models.NotifyWatchers(&models.Action{
  17. ActUserID: issue.Poster.ID,
  18. ActUser: issue.Poster,
  19. OpType: models.ActionCreateIssue,
  20. Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
  21. RepoID: repo.ID,
  22. Repo: repo,
  23. IsPrivate: repo.IsPrivate,
  24. }); err != nil {
  25. log.Error("NotifyWatchers: %v", err)
  26. }
  27. mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
  28. if err := models.PrepareWebhooks(repo, models.HookEventIssues, &api.IssuePayload{
  29. Action: api.HookIssueOpened,
  30. Index: issue.Index,
  31. Issue: issue.APIFormat(),
  32. Repository: repo.APIFormat(mode),
  33. Sender: issue.Poster.APIFormat(),
  34. }); err != nil {
  35. log.Error("PrepareWebhooks: %v", err)
  36. } else {
  37. go models.HookQueue.Add(issue.RepoID)
  38. }
  39. return nil
  40. }
  41. // ChangeTitle changes the title of this issue, as the given user.
  42. func ChangeTitle(issue *models.Issue, doer *models.User, title string) (err error) {
  43. oldTitle := issue.Title
  44. issue.Title = title
  45. if err = issue.ChangeTitle(doer, oldTitle); err != nil {
  46. return
  47. }
  48. mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
  49. if issue.IsPull {
  50. if err = issue.LoadPullRequest(); err != nil {
  51. return fmt.Errorf("loadPullRequest: %v", err)
  52. }
  53. issue.PullRequest.Issue = issue
  54. err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
  55. Action: api.HookIssueEdited,
  56. Index: issue.Index,
  57. Changes: &api.ChangesPayload{
  58. Title: &api.ChangesFromPayload{
  59. From: oldTitle,
  60. },
  61. },
  62. PullRequest: issue.PullRequest.APIFormat(),
  63. Repository: issue.Repo.APIFormat(mode),
  64. Sender: doer.APIFormat(),
  65. })
  66. } else {
  67. err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
  68. Action: api.HookIssueEdited,
  69. Index: issue.Index,
  70. Changes: &api.ChangesPayload{
  71. Title: &api.ChangesFromPayload{
  72. From: oldTitle,
  73. },
  74. },
  75. Issue: issue.APIFormat(),
  76. Repository: issue.Repo.APIFormat(mode),
  77. Sender: issue.Poster.APIFormat(),
  78. })
  79. }
  80. if err != nil {
  81. log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
  82. } else {
  83. go models.HookQueue.Add(issue.RepoID)
  84. }
  85. return nil
  86. }