Skip to content

Commit 20ae9d3

Browse files
authored
Fetch 100 codespaces by default
1 parent e29a0ac commit 20ae9d3

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

internal/codespaces/api/api.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ type getCodespacesListResponse struct {
196196
// ListCodespaces returns a list of codespaces for the user.
197197
// It consumes all pages returned by the API until all codespaces have been fetched.
198198
func (a *API) ListCodespaces(ctx context.Context) (codespaces []*Codespace, err error) {
199-
per_page := 50
199+
per_page := 100
200200
for page := 1; ; page++ {
201-
response, err := a.fetchCodespaces(ctx, page)
201+
response, err := a.fetchCodespaces(ctx, page, per_page)
202202
if err != nil {
203-
return nil, fmt.Errorf("%w", err)
203+
return nil, err
204204
}
205205
codespaces = append(codespaces, response.Codespaces...)
206206
if page*per_page >= response.TotalCount {
@@ -211,8 +211,7 @@ func (a *API) ListCodespaces(ctx context.Context) (codespaces []*Codespace, err
211211
return codespaces, nil
212212
}
213213

214-
func (a *API) fetchCodespaces(ctx context.Context, page int) (response *getCodespacesListResponse, err error) {
215-
per_page := 50
214+
func (a *API) fetchCodespaces(ctx context.Context, page int, per_page int) (response *getCodespacesListResponse, err error) {
216215
req, err := http.NewRequest(
217216
http.MethodGet, a.githubAPI+"/user/codespaces", nil,
218217
)

internal/codespaces/api/api_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func createFakeListEndpointServer(t *testing.T, initalTotal int, finalTotal int)
6060
}
6161

6262
func TestListCodespaces(t *testing.T) {
63-
svr := createFakeListEndpointServer(t, 100, 100)
63+
svr := createFakeListEndpointServer(t, 200, 200)
6464
defer svr.Close()
6565

6666
api := API{
@@ -73,21 +73,21 @@ func TestListCodespaces(t *testing.T) {
7373
if err != nil {
7474
t.Fatal(err)
7575
}
76-
if len(codespaces) != 100 {
76+
if len(codespaces) != 200 {
7777
t.Fatalf("expected 100 codespace, got %d", len(codespaces))
7878
}
7979

8080
if codespaces[0].Name != "codespace-0" {
8181
t.Fatalf("expected codespace-0, got %s", codespaces[0].Name)
8282
}
8383

84-
if codespaces[99].Name != "codespace-99" {
85-
t.Fatalf("expected codespace-99, got %s", codespaces[0].Name)
84+
if codespaces[199].Name != "codespace-199" {
85+
t.Fatalf("expected codespace-199, got %s", codespaces[0].Name)
8686
}
8787
}
8888

8989
func TestMidIterationDeletion(t *testing.T) {
90-
svr := createFakeListEndpointServer(t, 100, 99)
90+
svr := createFakeListEndpointServer(t, 200, 199)
9191
defer svr.Close()
9292

9393
api := API{
@@ -100,13 +100,13 @@ func TestMidIterationDeletion(t *testing.T) {
100100
if err != nil {
101101
t.Fatal(err)
102102
}
103-
if len(codespaces) != 100 {
104-
t.Fatalf("expected 100 codespace, got %d", len(codespaces))
103+
if len(codespaces) != 200 {
104+
t.Fatalf("expected 200 codespace, got %d", len(codespaces))
105105
}
106106
}
107107

108108
func TestMidIterationAddition(t *testing.T) {
109-
svr := createFakeListEndpointServer(t, 99, 100)
109+
svr := createFakeListEndpointServer(t, 199, 200)
110110
defer svr.Close()
111111

112112
api := API{
@@ -119,7 +119,7 @@ func TestMidIterationAddition(t *testing.T) {
119119
if err != nil {
120120
t.Fatal(err)
121121
}
122-
if len(codespaces) != 100 {
123-
t.Fatalf("expected 100 codespace, got %d", len(codespaces))
122+
if len(codespaces) != 200 {
123+
t.Fatalf("expected 200 codespace, got %d", len(codespaces))
124124
}
125125
}

0 commit comments

Comments
 (0)