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.

29 lines
846 B

  1. // Copyright 2018 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. "fmt"
  7. "code.gitea.io/gitea/modules/setting"
  8. )
  9. // UpdatePublicKeyInRepo update public key and if necessary deploy key updates
  10. func UpdatePublicKeyInRepo(keyID, repoID int64) error {
  11. // Ask for running deliver hook and test pull request tasks.
  12. reqURL := setting.LocalURL + fmt.Sprintf("api/internal/ssh/%d/update/%d", keyID, repoID)
  13. resp, err := newInternalRequest(reqURL, "POST").Response()
  14. if err != nil {
  15. return err
  16. }
  17. defer resp.Body.Close()
  18. // All 2XX status codes are accepted and others will return an error
  19. if resp.StatusCode/100 != 2 {
  20. return fmt.Errorf("Failed to update public key: %s", decodeJSONError(resp).Err)
  21. }
  22. return nil
  23. }