Skip to content

Commit

Permalink
Merge pull request #31 from Kyslik/add-pagination-to-projects-endpoint
Browse files Browse the repository at this point in the history
Add pagination to `project` endpoint
  • Loading branch information
Riki Makita authored Jan 23, 2023
2 parents 52abc37 + d4d42d0 commit a42f5e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
32 changes: 20 additions & 12 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
type Projects interface {
Get(ctx context.Context, projectSlug string) (*Project, error)
CreateCheckoutKey(ctx context.Context, projectSlug string, options ProjectCreateCheckoutKeyOptions) (*ProjectCheckoutKey, error)
ListCheckoutKeys(ctx context.Context, projectSlug string) (*ProjectCheckoutKeyList, error)
ListCheckoutKeys(ctx context.Context, projectSlug string, options ProjectListCheckoutKeysOptions) (*ProjectCheckoutKeyList, error)
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 All @@ -23,7 +23,7 @@ type Projects interface {
GetPipeline(ctx context.Context, projectSlug string, pipelineNumber string) (*Pipeline, error)
}

// projects implementes Projects interface
// projects implements Projects interface
type projects struct {
client *Client
}
Expand Down Expand Up @@ -70,15 +70,15 @@ func (s *projects) Get(ctx context.Context, projectSlug string) (*Project, error
}

type ProjectCheckoutKey struct {
// seems like public documentation says public-key should be the key but
// actually returned one is public_key
// seems like public documentation says public-key should be the key but
// actually returned one is public_key
PublicKey string `json:"public_key"`
Type CheckoutKeyTypeType `json:"type"`
Fingerprint string `json:"fingerprint"`
Preferred bool `json:"preferred"`
// seems like public documentation says created-at should be the key but
// actually returned one is created_at
CreatedAt time.Time `json:"created_at"`
// seems like public documentation says created-at should be the key but
// actually returned one is created_at
CreatedAt time.Time `json:"created_at"`
}

type ProjectCreateCheckoutKeyOptions struct {
Expand Down Expand Up @@ -117,18 +117,22 @@ func (s *projects) CreateCheckoutKey(ctx context.Context, projectSlug string, op
return pck, nil
}

type ProjectListCheckoutKeysOptions struct {
PageToken *string `url:"page-token,omitempty"`
}

type ProjectCheckoutKeyList struct {
Items []*ProjectCheckoutKey `json:"items"`
NextPageToken string `json:"next_page_token"`
}

func (s *projects) ListCheckoutKeys(ctx context.Context, projectSlug string) (*ProjectCheckoutKeyList, error) {
func (s *projects) ListCheckoutKeys(ctx context.Context, projectSlug string, options ProjectListCheckoutKeysOptions) (*ProjectCheckoutKeyList, error) {
if !validString(&projectSlug) {
return nil, ErrRequiredProjectSlug
}

u := fmt.Sprintf("project/%s/checkout-key", 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 Expand Up @@ -230,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
4 changes: 2 additions & 2 deletions project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Test_projects_ListCheckoutKeys(t *testing.T) {
})

ctx := context.Background()
pckl, err := client.Projects.ListCheckoutKeys(ctx, projectSlug)
pckl, err := client.Projects.ListCheckoutKeys(ctx, projectSlug, ProjectListCheckoutKeysOptions{})
if err != nil {
t.Errorf("Projects.ListCheckoutKeys got error: %v", err)
}
Expand Down 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 a42f5e1

Please sign in to comment.