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.

push_update.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2017 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 private
  5. import (
  6. "encoding/json"
  7. "strings"
  8. "code.gitea.io/git"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/log"
  11. macaron "gopkg.in/macaron.v1"
  12. )
  13. // PushUpdate update public key updates
  14. func PushUpdate(ctx *macaron.Context) {
  15. var opt models.PushUpdateOptions
  16. if err := json.NewDecoder(ctx.Req.Request.Body).Decode(&opt); err != nil {
  17. ctx.JSON(500, map[string]interface{}{
  18. "err": err.Error(),
  19. })
  20. return
  21. }
  22. branch := strings.TrimPrefix(opt.RefFullName, git.BranchPrefix)
  23. if len(branch) == 0 || opt.PusherID <= 0 {
  24. ctx.Error(404)
  25. log.Trace("PushUpdate: branch or secret is empty, or pusher ID is not valid")
  26. return
  27. }
  28. repo, err := models.PushUpdate(opt)
  29. if err != nil {
  30. ctx.JSON(500, map[string]interface{}{
  31. "err": err.Error(),
  32. })
  33. return
  34. }
  35. pusher, err := models.GetUserByID(opt.PusherID)
  36. if err != nil {
  37. if models.IsErrUserNotExist(err) {
  38. ctx.Error(404)
  39. } else {
  40. ctx.JSON(500, map[string]interface{}{
  41. "err": err.Error(),
  42. })
  43. }
  44. return
  45. }
  46. log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
  47. go models.HookQueue.Add(repo.ID)
  48. go models.AddTestPullRequestTask(pusher, repo.ID, branch, true)
  49. ctx.Status(202)
  50. }