本站源代码
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

57 lines
1.3KB

  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/gitea/models"
  9. "code.gitea.io/gitea/modules/git"
  10. "code.gitea.io/gitea/modules/log"
  11. "code.gitea.io/gitea/modules/repofiles"
  12. "gitea.com/macaron/macaron"
  13. )
  14. // PushUpdate update public key updates
  15. func PushUpdate(ctx *macaron.Context) {
  16. var opt models.PushUpdateOptions
  17. if err := json.NewDecoder(ctx.Req.Request.Body).Decode(&opt); err != nil {
  18. ctx.JSON(500, map[string]interface{}{
  19. "err": err.Error(),
  20. })
  21. return
  22. }
  23. branch := strings.TrimPrefix(opt.RefFullName, git.BranchPrefix)
  24. if len(branch) == 0 || opt.PusherID <= 0 {
  25. ctx.Error(404)
  26. log.Trace("PushUpdate: branch or secret is empty, or pusher ID is not valid")
  27. return
  28. }
  29. repo, err := models.GetRepositoryByOwnerAndName(opt.RepoUserName, opt.RepoName)
  30. if err != nil {
  31. ctx.JSON(500, map[string]interface{}{
  32. "err": err.Error(),
  33. })
  34. return
  35. }
  36. err = repofiles.PushUpdate(repo, branch, opt)
  37. if err != nil {
  38. if models.IsErrUserNotExist(err) {
  39. ctx.Error(404)
  40. } else {
  41. ctx.JSON(500, map[string]interface{}{
  42. "err": err.Error(),
  43. })
  44. }
  45. return
  46. }
  47. ctx.Status(202)
  48. }
上海开阖软件有限公司 沪ICP备12045867号-1