Skip to content

Commit

Permalink
Implement pagination for Projects.ListVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyslik committed Jan 22, 2023
1 parent 2513cf0 commit d4d42d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit d4d42d0

Please sign in to comment.