Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add ListOptions for listing user migrations #2417

Merged
merged 2 commits into from Aug 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/migrations/main.go
Expand Up @@ -24,7 +24,7 @@ func fetchAllUserMigrations() ([]*github.UserMigration, error) {
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)

migrations, _, err := client.Migrations.ListUserMigrations(ctx)
migrations, _, err := client.Migrations.ListUserMigrations(ctx, &github.ListOptions{Page: 1})
return migrations, err
}

Expand Down
6 changes: 5 additions & 1 deletion github/migrations_user.go
Expand Up @@ -97,8 +97,12 @@ func (s *MigrationService) StartUserMigration(ctx context.Context, repos []strin
// ListUserMigrations lists the most recent migrations.
//
// GitHub API docs: https://docs.github.com/en/rest/migrations/users#list-user-migrations
func (s *MigrationService) ListUserMigrations(ctx context.Context) ([]*UserMigration, *Response, error) {
func (s *MigrationService) ListUserMigrations(ctx context.Context, opts *ListOptions) ([]*UserMigration, *Response, error) {
u := "user/migrations"
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
Comment on lines +102 to +105
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if this case got tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gmlewis @raynigon I am actually not sure how I can test this path..The ListOptions{} takes in Page and PerPage. Is there an example you can point me to?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, right... with the fixed URL, I'm not sure this can be tested, so let's leave it as-is. Thanks, @amitsaha .


req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions github/migrations_user_test.go
Expand Up @@ -66,7 +66,7 @@ func TestMigrationService_ListUserMigrations(t *testing.T) {
})

ctx := context.Background()
got, _, err := client.Migrations.ListUserMigrations(ctx)
got, _, err := client.Migrations.ListUserMigrations(ctx, &ListOptions{Page: 1, PerPage: 2})
if err != nil {
t.Errorf("ListUserMigrations returned error %v", err)
}
Expand All @@ -78,7 +78,7 @@ func TestMigrationService_ListUserMigrations(t *testing.T) {

const methodName = "ListUserMigrations"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Migrations.ListUserMigrations(ctx)
got, resp, err := client.Migrations.ListUserMigrations(ctx, &ListOptions{Page: 1, PerPage: 2})
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down