本站源代码
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

60 行
1.6KB

  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 models
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/log"
  8. api "code.gitea.io/gitea/modules/structs"
  9. )
  10. // ChangeMilestoneAssign changes assignment of milestone for issue.
  11. func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneID int64) (err error) {
  12. if err = models.ChangeMilestoneAssign(issue, doer, oldMilestoneID); err != nil {
  13. return
  14. }
  15. var hookAction api.HookIssueAction
  16. if issue.MilestoneID > 0 {
  17. hookAction = api.HookIssueMilestoned
  18. } else {
  19. hookAction = api.HookIssueDemilestoned
  20. }
  21. if err = issue.LoadAttributes(); err != nil {
  22. return err
  23. }
  24. mode, _ := models.AccessLevel(doer, issue.Repo)
  25. if issue.IsPull {
  26. err = issue.PullRequest.LoadIssue()
  27. if err != nil {
  28. log.Error("LoadIssue: %v", err)
  29. return
  30. }
  31. err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
  32. Action: hookAction,
  33. Index: issue.Index,
  34. PullRequest: issue.PullRequest.APIFormat(),
  35. Repository: issue.Repo.APIFormat(mode),
  36. Sender: doer.APIFormat(),
  37. })
  38. } else {
  39. err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
  40. Action: hookAction,
  41. Index: issue.Index,
  42. Issue: issue.APIFormat(),
  43. Repository: issue.Repo.APIFormat(mode),
  44. Sender: doer.APIFormat(),
  45. })
  46. }
  47. if err != nil {
  48. log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
  49. } else {
  50. go models.HookQueue.Add(issue.RepoID)
  51. }
  52. return nil
  53. }
上海开阖软件有限公司 沪ICP备12045867号-1