From d4d42d0d9e090a7b6965905afa6d6ca89a8216dd Mon Sep 17 00:00:00 2001 From: Martin Kiesel Date: Sun, 22 Jan 2023 23:04:52 +0100 Subject: [PATCH] Implement pagination for Projects.ListVariables --- project.go | 10 +++++++--- project_test.go | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/project.go b/project.go index ad63e71..eba6e63 100644 --- a/project.go +++ b/project.go @@ -14,7 +14,7 @@ type Projects interface { GetCheckoutKey(ctx context.Context, projectSlug, fingerprint string) (*ProjectCheckoutKey, error) DeleteCheckoutKey(ctx context.Context, projectSlug, fingerprint string) error CreateVariable(ctx context.Context, projectSlug string, options ProjectCreateVariableOptions) (*ProjectVariable, error) - ListVariables(ctx context.Context, projectSlug string) (*ProjectVariableList, error) + ListVariables(ctx context.Context, projectSlug string, options ProjectListVariablesOptions) (*ProjectVariableList, error) DeleteVariable(ctx context.Context, projectSlug, name string) error GetVariable(ctx context.Context, projectSlug, name string) (*ProjectVariable, error) TriggerPipeline(ctx context.Context, projectSlug string, options ProjectTriggerPipelineOptions) (*Pipeline, error) @@ -234,18 +234,22 @@ func (s *projects) CreateVariable(ctx context.Context, projectSlug string, optio return pv, nil } +type ProjectListVariablesOptions struct { + PageToken *string `url:"page-token,omitempty"` +} + type ProjectVariableList struct { Items []*ProjectVariable `json:"items"` NextPageToken string `json:"next_page_token"` } -func (s *projects) ListVariables(ctx context.Context, projectSlug string) (*ProjectVariableList, error) { +func (s *projects) ListVariables(ctx context.Context, projectSlug string, options ProjectListVariablesOptions) (*ProjectVariableList, error) { if !validString(&projectSlug) { return nil, ErrRequiredProjectSlug } u := fmt.Sprintf("project/%s/envvar", projectSlug) - req, err := s.client.newRequest("GET", u, nil) + req, err := s.client.newRequest("GET", u, &options) if err != nil { return nil, err } diff --git a/project_test.go b/project_test.go index 85bd830..d22e1c6 100644 --- a/project_test.go +++ b/project_test.go @@ -203,7 +203,7 @@ func Test_projects_ListVariables(t *testing.T) { }) ctx := context.Background() - pvl, err := client.Projects.ListVariables(ctx, projectSlug) + pvl, err := client.Projects.ListVariables(ctx, projectSlug, ProjectListVariablesOptions{}) if err != nil { t.Errorf("Projects.ListVariables got error: %v", err) }