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.

pull.go 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 pull
  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. // NewPullRequest creates new pull request with labels for repository.
  12. func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int64, uuids []string, pr *models.PullRequest, patch []byte, assigneeIDs []int64) error {
  13. if err := models.NewPullRequest(repo, pull, labelIDs, uuids, pr, patch, assigneeIDs); err != nil {
  14. return err
  15. }
  16. if err := models.NotifyWatchers(&models.Action{
  17. ActUserID: pull.Poster.ID,
  18. ActUser: pull.Poster,
  19. OpType: models.ActionCreatePullRequest,
  20. Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
  21. RepoID: repo.ID,
  22. Repo: repo,
  23. IsPrivate: repo.IsPrivate,
  24. }); err != nil {
  25. log.Error("NotifyWatchers: %v", err)
  26. }
  27. pr.Issue = pull
  28. pull.PullRequest = pr
  29. mode, _ := models.AccessLevel(pull.Poster, repo)
  30. if err := models.PrepareWebhooks(repo, models.HookEventPullRequest, &api.PullRequestPayload{
  31. Action: api.HookIssueOpened,
  32. Index: pull.Index,
  33. PullRequest: pr.APIFormat(),
  34. Repository: repo.APIFormat(mode),
  35. Sender: pull.Poster.APIFormat(),
  36. }); err != nil {
  37. log.Error("PrepareWebhooks: %v", err)
  38. } else {
  39. go models.HookQueue.Add(repo.ID)
  40. }
  41. return nil
  42. }