X Tutup
Skip to content

Commit 01adff0

Browse files
committed
api: prevent repeating GET parameters when paginating
1 parent 5bf185c commit 01adff0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkg/cmd/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ func apiRun(opts *ApiOptions) error {
319319
}
320320
} else {
321321
requestPath, hasNextPage = findNextPage(resp)
322+
requestBody = nil // prevent repeating GET parameters
322323
}
323324

324325
if hasNextPage && opts.ShowResponseHeaders {

pkg/cmd/api/api_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,11 @@ func Test_apiRun_paginationREST(t *testing.T) {
577577
return config.NewBlankConfig(), nil
578578
},
579579

580-
RequestPath: "issues",
581-
Paginate: true,
580+
RequestMethod: "GET",
581+
RequestMethodPassed: true,
582+
RequestPath: "issues",
583+
Paginate: true,
584+
RawFields: []string{"per_page=50", "page=1"},
582585
}
583586

584587
err := apiRun(&options)
@@ -587,7 +590,7 @@ func Test_apiRun_paginationREST(t *testing.T) {
587590
assert.Equal(t, `{"page":1}{"page":2}{"page":3}`, stdout.String(), "stdout")
588591
assert.Equal(t, "", stderr.String(), "stderr")
589592

590-
assert.Equal(t, "https://api.github.com/issues?per_page=100", responses[0].Request.URL.String())
593+
assert.Equal(t, "https://api.github.com/issues?page=1&per_page=50", responses[0].Request.URL.String())
591594
assert.Equal(t, "https://api.github.com/repositories/1227/issues?page=2", responses[1].Request.URL.String())
592595
assert.Equal(t, "https://api.github.com/repositories/1227/issues?page=3", responses[2].Request.URL.String())
593596
}

0 commit comments

Comments
 (0)
X Tutup