Skip to content
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
62 changes: 62 additions & 0 deletions github/github-iterators.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

144 changes: 144 additions & 0 deletions github/github-iterators_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions github/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,29 @@ func (s *MigrationService) UnlockRepo(ctx context.Context, org string, id int64,

return s.client.Do(req, nil)
}

// ListRepositories lists all the repositories for an organization migration.
//
// GitHub API docs: https://docs.github.com/rest/migrations/orgs?apiVersion=2022-11-28#list-repositories-in-an-organization-migration
//
//meta:operation GET /orgs/{org}/migrations/{migration_id}/repositories
func (s *MigrationService) ListRepositories(ctx context.Context, org string, migrationID int64, opts *ListOptions) ([]*Repository, *Response, error) {
u := fmt.Sprintf("orgs/%v/migrations/%v/repositories", org, migrationID)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}

var repos []*Repository
resp, err := s.client.Do(req, &repos)
if err != nil {
return nil, resp, err
}

return repos, resp, nil
}
36 changes: 36 additions & 0 deletions github/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,42 @@ func TestMigrationService_UnlockRepo(t *testing.T) {
})
}

func TestMigrationService_ListRepositories(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/orgs/o/migrations/1/repositories", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "1", "per_page": "2"})
fmt.Fprint(w, `[{"id":1,"name":"r","full_name":"o/r"}]`)
})

ctx := t.Context()
opts := &ListOptions{Page: 1, PerPage: 2}
got, _, err := client.Migrations.ListRepositories(ctx, "o", 1, opts)
if err != nil {
t.Errorf("ListRepositories returned error: %v", err)
}
want := []*Repository{{ID: new(int64(1)), Name: new("r"), FullName: new("o/r")}}
if !cmp.Equal(got, want) {
t.Errorf("ListRepositories = %+v, want %+v", got, want)
}

const methodName = "ListRepositories"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Migrations.ListRepositories(ctx, "\n", 1, opts)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Migrations.ListRepositories(ctx, "o", 1, opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

var migrationJSON = []byte(`{
"id": 79,
"guid": "0b989ba4-242f-11e5-81e1-c7b6966d2516",
Expand Down
26 changes: 26 additions & 0 deletions github/migrations_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,29 @@ func (s *MigrationService) UnlockUserRepo(ctx context.Context, id int64, repo st

return s.client.Do(req, nil)
}

// ListUserRepositories lists all the repositories for a user migration.
//
// GitHub API docs: https://docs.github.com/rest/migrations/users?apiVersion=2022-11-28#list-repositories-for-a-user-migration
//
//meta:operation GET /user/migrations/{migration_id}/repositories
func (s *MigrationService) ListUserRepositories(ctx context.Context, migrationID int64, opts *ListOptions) ([]*Repository, *Response, error) {
u := fmt.Sprintf("user/migrations/%v/repositories", migrationID)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}

var repos []*Repository
resp, err := s.client.Do(req, &repos)
if err != nil {
return nil, resp, err
}

return repos, resp, nil
}
31 changes: 31 additions & 0 deletions github/migrations_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,37 @@ func TestMigrationService_UnlockUserRepo(t *testing.T) {
})
}

func TestMigrationService_ListUserRepositories(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/user/migrations/1/repositories", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "1", "per_page": "2"})
fmt.Fprint(w, `[{"id":1,"name":"r","full_name":"o/r"}]`)
})

ctx := t.Context()
opts := &ListOptions{Page: 1, PerPage: 2}
got, _, err := client.Migrations.ListUserRepositories(ctx, 1, opts)
if err != nil {
t.Errorf("ListUserRepositories returned error: %v", err)
}
want := []*Repository{{ID: new(int64(1)), Name: new("r"), FullName: new("o/r")}}
if !cmp.Equal(got, want) {
t.Errorf("ListUserRepositories = %+v, want %+v", got, want)
}

const methodName = "ListUserRepositories"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Migrations.ListUserRepositories(ctx, 1, opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

var userMigrationJSON = []byte(`{
"id": 79,
"guid": "0b989ba4-242f-11e5-81e1-c7b6966d2516",
Expand Down
Loading