Repository: google/go-github
Pull request #2250 (2022-01-12 03:18:50)

Add pagination options to list all package versions
Here is the detail of the problem: #2251.


codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2250?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2250](https://codecov.io/gh/google/go-github/pull/2250?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (7da192a) into [master](https://codecov.io/gh/google/go-github/commit/6e66a89c7618957e0f95f82d94bfbe3164fd21dc?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (6e66a89) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/2250/graphs/tree.svg?width=650&height=150&src=pr&token=EgYjGjZlI0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)](https://codecov.io/gh/google/go-github/pull/2250?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)

```diff
@@           Coverage Diff           @@
##           master    #2250   +/-   ##
=======================================
  Coverage   97.80%   97.80%           
=======================================
  Files         113      113           
  Lines       10207    10211    +4     
=======================================
+ Hits         9983     9987    +4     
  Misses        156      156           
  Partials       68       68           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2250?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/users\_packages.go](https://codecov.io/gh/google/go-github/pull/2250/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3VzZXJzX3BhY2thZ2VzLmdv) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/2250?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/2250?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Last update [6e66a89...7da192a](https://codecov.io/gh/google/go-github/pull/2250?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).

lpmatos: > Thank you, @lpmatos ! Once you sign the CLA, we can move forward with this PR. LGTM.

Do I have to commit using my gmail? I followed all the steps mentioned in the documentation. 

Sorry for the questions, this is my first contribution to a project like this.

## Screenshots

### CLA

![Screen Shot 2022-01-12 at 01 07 32](https://user-images.githubusercontent.com/58797390/149062221-7079ec94-4845-4b18-97db-00791255bcf4.png)

### E-mails on GitHub

![Screen Shot 2022-01-12 at 01 09 32](https://user-images.githubusercontent.com/58797390/149062403-4e67a7b0-4483-47ca-a7ba-cc9dad18a105.png)


gmlewis: The CLA email needs to match the email address you associated with your GitHub commits, and it looks like you sorted it all out.  Thanks.

We are now ready for a second LGTM/Approval from any other contributor to this repo.

Maybe @Parker77 has time to review this some time today.
gmlewis: Thank you, @Parker77 !
Merging.

Patch:
diff --git a/github/users_packages.go b/github/users_packages.go
index 4308b16e..cd20f8c1 100644
--- a/github/users_packages.go
+++ b/github/users_packages.go
@@ -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 {


Test patch:
diff --git a/github/users_packages_test.go b/github/users_packages_test.go
index 41e7698a..a0877593 100644
--- a/github/users_packages_test.go
+++ b/github/users_packages_test.go
@@ -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)
 	}
@@ -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)
 		}
@@ -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)
 	}
@@ -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)
 		}