(ctx context.Context, orgName string, userName string, codespaceName string)
| 446 | } |
| 447 | |
| 448 | func (a *API) GetOrgMemberCodespace(ctx context.Context, orgName string, userName string, codespaceName string) (*Codespace, error) { |
| 449 | perPage := 100 |
| 450 | listURL := fmt.Sprintf("%s/orgs/%s/members/%s/codespaces?per_page=%d", a.githubAPI, orgName, userName, perPage) |
| 451 | |
| 452 | for { |
| 453 | req, err := http.NewRequest(http.MethodGet, listURL, nil) |
| 454 | if err != nil { |
| 455 | return nil, fmt.Errorf("error creating request: %w", err) |
| 456 | } |
| 457 | a.setHeaders(req) |
| 458 | |
| 459 | resp, err := a.do(ctx, req, "/orgs/*/members/*/codespaces") |
| 460 | if err != nil { |
| 461 | return nil, fmt.Errorf("error making request: %w", err) |
| 462 | } |
| 463 | defer resp.Body.Close() |
| 464 | |
| 465 | if resp.StatusCode != http.StatusOK { |
| 466 | return nil, api.HandleHTTPError(resp) |
| 467 | } |
| 468 | |
| 469 | var response struct { |
| 470 | Codespaces []*Codespace `json:"codespaces"` |
| 471 | } |
| 472 | |
| 473 | dec := json.NewDecoder(resp.Body) |
| 474 | if err := dec.Decode(&response); err != nil { |
| 475 | return nil, fmt.Errorf("error unmarshalling response: %w", err) |
| 476 | } |
| 477 | |
| 478 | for _, cs := range response.Codespaces { |
| 479 | if cs.Name == codespaceName { |
| 480 | return cs, nil |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | nextURL := findNextPage(resp.Header.Get("Link")) |
| 485 | if nextURL == "" { |
| 486 | break |
| 487 | } |
| 488 | listURL = nextURL |
| 489 | } |
| 490 | |
| 491 | return nil, fmt.Errorf("codespace not found for user %s with name %s", userName, codespaceName) |
| 492 | } |
| 493 | |
| 494 | // GetCodespace returns the user codespace based on the provided name. |
| 495 | // If the codespace is not found, an error is returned. |
nothing calls this directly
no test coverage detected