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

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

2 changes: 1 addition & 1 deletion github/github-iterators_test.go

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

13 changes: 12 additions & 1 deletion github/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,23 @@ func (i Invitation) String() string {
return Stringify(i)
}

// ListTeamsOptions specifies the optional parameters to the TeamsService.ListTeams method.
type ListTeamsOptions struct {
// Type filters the list of teams by ownership type. Possible values are:
// "all" - returns all teams (default)
// "organization" - returns only organization-level teams
// "enterprise" - returns only enterprise-level teams
Type string `url:"type,omitempty"`

ListOptions
}

// ListTeams lists all of the teams for an organization.
//
// GitHub API docs: https://docs.github.com/rest/teams/teams#list-teams
//
//meta:operation GET /orgs/{org}/teams
func (s *TeamsService) ListTeams(ctx context.Context, org string, opts *ListOptions) ([]*Team, *Response, error) {
func (s *TeamsService) ListTeams(ctx context.Context, org string, opts *ListTeamsOptions) ([]*Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams", org)
u, err := addOptions(u, opts)
if err != nil {
Expand Down
25 changes: 24 additions & 1 deletion github/teams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestTeamsService_ListTeams(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`)
})

opt := &ListOptions{Page: 2}
opt := &ListTeamsOptions{ListOptions: ListOptions{Page: 2}}
ctx := t.Context()
teams, _, err := client.Teams.ListTeams(ctx, "o", opt)
if err != nil {
Expand All @@ -53,6 +53,29 @@ func TestTeamsService_ListTeams(t *testing.T) {
})
}

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

mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"type": "enterprise"})
fmt.Fprint(w, `[{"id":1,"type":"enterprise"}]`)
})

opt := &ListTeamsOptions{Type: "enterprise"}
ctx := t.Context()
teams, _, err := client.Teams.ListTeams(ctx, "o", opt)
if err != nil {
t.Errorf("Teams.ListTeams returned error: %v", err)
}

want := []*Team{{ID: Ptr(int64(1)), Type: Ptr("enterprise")}}
if !cmp.Equal(teams, want) {
t.Errorf("Teams.ListTeams returned %+v, want %+v", teams, want)
}
}

func TestTeamsService_ListTeams_invalidOrg(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
Expand Down