git_repo.go 847 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package api
  2. import (
  3. "context"
  4. "fmt"
  5. "net/http"
  6. "github.com/porter-dev/porter/internal/models"
  7. )
  8. // ListGitRepoResponse is the list of Git repo integrations for a project
  9. type ListGitRepoResponse []models.GitRepoExternal
  10. // ListGitRepos returns a list of Git repos for a project
  11. func (c *Client) ListGitRepos(
  12. ctx context.Context,
  13. projectID uint,
  14. ) (ListGitRepoResponse, error) {
  15. req, err := http.NewRequest(
  16. "GET",
  17. fmt.Sprintf("%s/projects/%d/gitrepos", c.BaseURL, projectID),
  18. nil,
  19. )
  20. if err != nil {
  21. return nil, err
  22. }
  23. req = req.WithContext(ctx)
  24. bodyResp := &ListGitRepoResponse{}
  25. if httpErr, err := c.sendRequest(req, bodyResp, true); httpErr != nil || err != nil {
  26. if httpErr != nil {
  27. return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
  28. }
  29. return nil, err
  30. }
  31. return *bodyResp, nil
  32. }