Skip to content

Commit

Permalink
Add ListOptions for listing user migrations (#2417)
Browse files Browse the repository at this point in the history
Fixes: #2416.
  • Loading branch information
amitsaha committed Aug 22, 2022
1 parent 01c8feb commit dd22b73
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
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
}

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

0 comments on commit dd22b73

Please sign in to comment.