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.

branch.go 1.1 kB

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. // GetProtectedBranchBy get protected branch information
  13. func GetProtectedBranchBy(repoID int64, branchName string) (*models.ProtectedBranch, error) {
  14. // Ask for running deliver hook and test pull request tasks.
  15. reqURL := setting.LocalURL + fmt.Sprintf("api/internal/branch/%d/%s", repoID, branchName)
  16. log.GitLogger.Trace("GetProtectedBranchBy: %s", reqURL)
  17. resp, err := newInternalRequest(reqURL, "GET").Response()
  18. if err != nil {
  19. return nil, err
  20. }
  21. var branch models.ProtectedBranch
  22. if err := json.NewDecoder(resp.Body).Decode(&branch); err != nil {
  23. return nil, 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 nil, fmt.Errorf("Failed to update public key: %s", decodeJSONError(resp).Err)
  29. }
  30. return &branch, nil
  31. }