You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

push_update.go 1.1 kB

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