diff --git a/github/orgs_members.go b/github/orgs_members.go index 902dc5a..9c51132 100644 --- a/github/orgs_members.go +++ b/github/orgs_members.go @@ -7,18 +7,34 @@ package github import "fmt" +// ListMembersOptions specifies optional parameters to the +// OrganizationsService.ListMembers method. +type ListMembersOptions struct { + // If true (or if the authenticated user is not an owner of the + // organization), list only publicly visible members. + PublicOnly bool `url:"-"` + + // Filter members returned in the list. Possible values are: + // 2fa_disabled, all. Default is "all". + Filter string `url:"filter,omitempty"` +} + // ListMembers lists the members for an organization. If the authenticated // user is an owner of the organization, this will return both concealed and // public members, otherwise it will only return public members. // // GitHub API docs: http://developer.github.com/v3/orgs/members/#members-list -func (s *OrganizationsService) ListMembers(org string, publicOnly bool) ([]User, *Response, error) { +func (s *OrganizationsService) ListMembers(org string, opt *ListMembersOptions) ([]User, *Response, error) { var u string - if publicOnly { + if opt != nil && opt.PublicOnly { u = fmt.Sprintf("orgs/%v/public_members", org) } else { u = fmt.Sprintf("orgs/%v/members", org) } + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/github/orgs_members_test.go b/github/orgs_members_test.go index e687612..43ac1bb 100644 --- a/github/orgs_members_test.go +++ b/github/orgs_members_test.go @@ -18,10 +18,12 @@ func TestOrganizationsService_ListMembers(t *testing.T) { mux.HandleFunc("/orgs/o/members", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"filter": "2fa_disabled"}) fmt.Fprint(w, `[{"id":1}]`) }) - members, _, err := client.Organizations.ListMembers("o", false) + opt := &ListMembersOptions{PublicOnly: false, Filter: "2fa_disabled"} + members, _, err := client.Organizations.ListMembers("o", opt) if err != nil { t.Errorf("Organizations.ListMembers returned error: %v", err) } @@ -33,7 +35,7 @@ func TestOrganizationsService_ListMembers(t *testing.T) { } func TestOrganizationsService_ListMembers_invalidOrg(t *testing.T) { - _, _, err := client.Organizations.ListMembers("%", false) + _, _, err := client.Organizations.ListMembers("%", nil) testURLParseError(t, err) } @@ -46,7 +48,8 @@ func TestOrganizationsService_ListMembers_public(t *testing.T) { fmt.Fprint(w, `[{"id":1}]`) }) - members, _, err := client.Organizations.ListMembers("o", true) + opt := &ListMembersOptions{PublicOnly: true} + members, _, err := client.Organizations.ListMembers("o", opt) if err != nil { t.Errorf("Organizations.ListMembers returned error: %v", err) }