Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add pagination options to list all package versions #2250

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion github/users_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ func (s *UsersService) RestorePackage(ctx context.Context, user, packageType, pa
//
// GitHub API docs: https://docs.github.com/en/rest/reference/packages#get-all-package-versions-for-a-package-owned-by-the-authenticated-user
// GitHub API docs: https://docs.github.com/en/rest/reference/users#delete-an-email-address-for-the-authenticated-user
func (s *UsersService) PackageGetAllVersions(ctx context.Context, user, packageType, packageName string) ([]*PackageVersion, *Response, error) {
func (s *UsersService) PackageGetAllVersions(ctx context.Context, user, packageType, packageName string, opts *PackageListOptions) ([]*PackageVersion, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/packages/%v/%v/versions", user, packageType, packageName)
} else {
u = fmt.Sprintf("user/packages/%v/%v/versions", packageType, packageName)
}
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
Expand Down
18 changes: 12 additions & 6 deletions github/users_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ func TestUsersService_Authenticated_ListPackagesVersions(t *testing.T) {
})

ctx := context.Background()
packages, _, err := client.Users.PackageGetAllVersions(ctx, "", "container", "hello_docker")
opts := &PackageListOptions{
String("internal"), String("container"), String("deleted"), ListOptions{Page: 1, PerPage: 2},
}
packages, _, err := client.Users.PackageGetAllVersions(ctx, "", "container", "hello_docker", opts)
if err != nil {
t.Errorf("Users.Authenticated_PackageGetAllVersions returned error: %v", err)
}
Expand All @@ -389,12 +392,12 @@ func TestUsersService_Authenticated_ListPackagesVersions(t *testing.T) {

const methodName = "PackageGetAllVersions"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Users.PackageGetAllVersions(ctx, "\n", "", "")
_, _, err = client.Users.PackageGetAllVersions(ctx, "\n", "", "", &PackageListOptions{})
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Users.PackageGetAllVersions(ctx, "", "", "")
got, resp, err := client.Users.PackageGetAllVersions(ctx, "", "", "", &PackageListOptions{})
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down Expand Up @@ -429,7 +432,10 @@ func TestUsersService_specifiedUser_ListPackagesVersions(t *testing.T) {
})

ctx := context.Background()
packages, _, err := client.Users.PackageGetAllVersions(ctx, "u", "container", "hello_docker")
opts := &PackageListOptions{
String("internal"), String("container"), String("deleted"), ListOptions{Page: 1, PerPage: 2},
}
packages, _, err := client.Users.PackageGetAllVersions(ctx, "u", "container", "hello_docker", opts)
if err != nil {
t.Errorf("Users.specifiedUser_PackageGetAllVersions returned error: %v", err)
}
Expand All @@ -455,12 +461,12 @@ func TestUsersService_specifiedUser_ListPackagesVersions(t *testing.T) {

const methodName = "PackageGetAllVersions"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Users.PackageGetAllVersions(ctx, "\n", "", "")
_, _, err = client.Users.PackageGetAllVersions(ctx, "\n", "", "", &PackageListOptions{})
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Users.PackageGetAllVersions(ctx, "", "", "")
got, resp, err := client.Users.PackageGetAllVersions(ctx, "", "", "", &PackageListOptions{})
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down