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.

47 lines
1.0 KiB

  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. err := models.PushUpdate(branch, opt)
  29. if err != nil {
  30. if models.IsErrUserNotExist(err) {
  31. ctx.Error(404)
  32. } else {
  33. ctx.JSON(500, map[string]interface{}{
  34. "err": err.Error(),
  35. })
  36. }
  37. return
  38. }
  39. ctx.Status(202)
  40. }