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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. macaron "gopkg.in/macaron.v1"
  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. }