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 982B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. "fmt"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/log"
  10. "code.gitea.io/gitea/modules/setting"
  11. )
  12. // PushUpdate update publick key updates
  13. func PushUpdate(opt models.PushUpdateOptions) error {
  14. // Ask for running deliver hook and test pull request tasks.
  15. reqURL := setting.LocalURL + "api/internal/push/update"
  16. log.GitLogger.Trace("PushUpdate: %s", reqURL)
  17. body, err := json.Marshal(&opt)
  18. if err != nil {
  19. return err
  20. }
  21. resp, err := newInternalRequest(reqURL, "POST").Body(body).Response()
  22. if err != nil {
  23. return err
  24. }
  25. defer resp.Body.Close()
  26. // All 2XX status codes are accepted and others will return an error
  27. if resp.StatusCode/100 != 2 {
  28. return fmt.Errorf("Failed to update public key: %s", decodeJSONError(resp).Err)
  29. }
  30. return nil
  31. }