Skip to content

Commit

Permalink
Add pagination options to list all package versions (#2250)
Browse files Browse the repository at this point in the history
Fixes: #2251.
  • Loading branch information
CI Monk authored Jan 12, 2022
1 parent 6e66a89 commit 002f016
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
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

1 comment on commit 002f016

@gmlewis
Copy link
Collaborator

@gmlewis gmlewis commented on 002f016 Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RajeshPrameJagdeo - strike one. Three strikes and you will be reported and banned.

Please sign in to comment.