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 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. }