Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

push_update.go 1.0KB

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