Fetch 100 codespaces by default
This commit is contained in:
parent
e29a0ac7c4
commit
20ae9d305d
2 changed files with 14 additions and 15 deletions
|
|
@ -196,11 +196,11 @@ type getCodespacesListResponse struct {
|
|||
// ListCodespaces returns a list of codespaces for the user.
|
||||
// It consumes all pages returned by the API until all codespaces have been fetched.
|
||||
func (a *API) ListCodespaces(ctx context.Context) (codespaces []*Codespace, err error) {
|
||||
per_page := 50
|
||||
per_page := 100
|
||||
for page := 1; ; page++ {
|
||||
response, err := a.fetchCodespaces(ctx, page)
|
||||
response, err := a.fetchCodespaces(ctx, page, per_page)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w", err)
|
||||
return nil, err
|
||||
}
|
||||
codespaces = append(codespaces, response.Codespaces...)
|
||||
if page*per_page >= response.TotalCount {
|
||||
|
|
@ -211,8 +211,7 @@ func (a *API) ListCodespaces(ctx context.Context) (codespaces []*Codespace, err
|
|||
return codespaces, nil
|
||||
}
|
||||
|
||||
func (a *API) fetchCodespaces(ctx context.Context, page int) (response *getCodespacesListResponse, err error) {
|
||||
per_page := 50
|
||||
func (a *API) fetchCodespaces(ctx context.Context, page int, per_page int) (response *getCodespacesListResponse, err error) {
|
||||
req, err := http.NewRequest(
|
||||
http.MethodGet, a.githubAPI+"/user/codespaces", nil,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func createFakeListEndpointServer(t *testing.T, initalTotal int, finalTotal int)
|
|||
}
|
||||
|
||||
func TestListCodespaces(t *testing.T) {
|
||||
svr := createFakeListEndpointServer(t, 100, 100)
|
||||
svr := createFakeListEndpointServer(t, 200, 200)
|
||||
defer svr.Close()
|
||||
|
||||
api := API{
|
||||
|
|
@ -73,7 +73,7 @@ func TestListCodespaces(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(codespaces) != 100 {
|
||||
if len(codespaces) != 200 {
|
||||
t.Fatalf("expected 100 codespace, got %d", len(codespaces))
|
||||
}
|
||||
|
||||
|
|
@ -81,13 +81,13 @@ func TestListCodespaces(t *testing.T) {
|
|||
t.Fatalf("expected codespace-0, got %s", codespaces[0].Name)
|
||||
}
|
||||
|
||||
if codespaces[99].Name != "codespace-99" {
|
||||
t.Fatalf("expected codespace-99, got %s", codespaces[0].Name)
|
||||
if codespaces[199].Name != "codespace-199" {
|
||||
t.Fatalf("expected codespace-199, got %s", codespaces[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMidIterationDeletion(t *testing.T) {
|
||||
svr := createFakeListEndpointServer(t, 100, 99)
|
||||
svr := createFakeListEndpointServer(t, 200, 199)
|
||||
defer svr.Close()
|
||||
|
||||
api := API{
|
||||
|
|
@ -100,13 +100,13 @@ func TestMidIterationDeletion(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(codespaces) != 100 {
|
||||
t.Fatalf("expected 100 codespace, got %d", len(codespaces))
|
||||
if len(codespaces) != 200 {
|
||||
t.Fatalf("expected 200 codespace, got %d", len(codespaces))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMidIterationAddition(t *testing.T) {
|
||||
svr := createFakeListEndpointServer(t, 99, 100)
|
||||
svr := createFakeListEndpointServer(t, 199, 200)
|
||||
defer svr.Close()
|
||||
|
||||
api := API{
|
||||
|
|
@ -119,7 +119,7 @@ func TestMidIterationAddition(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(codespaces) != 100 {
|
||||
t.Fatalf("expected 100 codespace, got %d", len(codespaces))
|
||||
if len(codespaces) != 200 {
|
||||
t.Fatalf("expected 200 codespace, got %d", len(codespaces))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue