From 01adff037f44c0d1ff311b8f4656faf0db34fdae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 18 Oct 2021 20:18:23 +0200 Subject: [PATCH] api: prevent repeating GET parameters when paginating --- pkg/cmd/api/api.go | 1 + pkg/cmd/api/api_test.go | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/api/api.go b/pkg/cmd/api/api.go index 7d9faf9b6..18498249e 100644 --- a/pkg/cmd/api/api.go +++ b/pkg/cmd/api/api.go @@ -319,6 +319,7 @@ func apiRun(opts *ApiOptions) error { } } else { requestPath, hasNextPage = findNextPage(resp) + requestBody = nil // prevent repeating GET parameters } if hasNextPage && opts.ShowResponseHeaders { diff --git a/pkg/cmd/api/api_test.go b/pkg/cmd/api/api_test.go index daed26926..408b74674 100644 --- a/pkg/cmd/api/api_test.go +++ b/pkg/cmd/api/api_test.go @@ -577,8 +577,11 @@ func Test_apiRun_paginationREST(t *testing.T) { return config.NewBlankConfig(), nil }, - RequestPath: "issues", - Paginate: true, + RequestMethod: "GET", + RequestMethodPassed: true, + RequestPath: "issues", + Paginate: true, + RawFields: []string{"per_page=50", "page=1"}, } err := apiRun(&options) @@ -587,7 +590,7 @@ func Test_apiRun_paginationREST(t *testing.T) { assert.Equal(t, `{"page":1}{"page":2}{"page":3}`, stdout.String(), "stdout") assert.Equal(t, "", stderr.String(), "stderr") - assert.Equal(t, "https://api.github.com/issues?per_page=100", responses[0].Request.URL.String()) + assert.Equal(t, "https://api.github.com/issues?page=1&per_page=50", responses[0].Request.URL.String()) assert.Equal(t, "https://api.github.com/repositories/1227/issues?page=2", responses[1].Request.URL.String()) assert.Equal(t, "https://api.github.com/repositories/1227/issues?page=3", responses[2].Request.URL.String()) }