From ef6e01c09bfbce9dff1463291f89e10d6cf62055 Mon Sep 17 00:00:00 2001 From: Charlie Yan Date: Thu, 16 Oct 2014 13:57:02 -0700 Subject: [PATCH] ListUserTeams implementation and test, go build and go test pass --- github/orgs_teams.go | 23 +++++++++++++++++++++++ github/orgs_teams_test.go | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/github/orgs_teams.go b/github/orgs_teams.go index 9e32113..6c1a6b5 100644 --- a/github/orgs_teams.go +++ b/github/orgs_teams.go @@ -252,6 +252,29 @@ func (s *OrganizationsService) RemoveTeamRepo(team int, owner string, repo strin return s.client.Do(req, nil) } +// ListUserTeams lists a user's teams +// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-user-teams +func (s *OrganizationsService) ListUserTeams(opt *ListOptions) ([]Team, *Response, error) { + u := "user/teams" + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + teams := new([]Team) + resp, err := s.client.Do(req, teams) + if err != nil { + return nil, resp, err + } + + return *teams, resp, err +} + // GetTeamMembership returns the membership status for a user in a team. // // GitHub API docs: https://developer.github.com/v3/orgs/teams/#get-team-membership diff --git a/github/orgs_teams_test.go b/github/orgs_teams_test.go index e2ddae4..1f45e8c 100644 --- a/github/orgs_teams_test.go +++ b/github/orgs_teams_test.go @@ -493,3 +493,25 @@ func TestOrganizationsService_RemoveTeamMembership(t *testing.T) { t.Errorf("Organizations.RemoveTeamMembership returned error: %v", err) } } + +func TestOrganizationsService_ListUserTeams(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/user/teams", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "1"}) + fmt.Fprint(w, `[{"id":1}]`) + }) + + opt := &ListOptions{Page: 1} + teams, _, err := client.Organizations.ListUserTeams(opt) + if err != nil { + t.Errorf("Organizations.ListUserTeams returned error: %v", err) + } + + want := []Team{{ID: Int(1)}} + if !reflect.DeepEqual(teams, want) { + t.Errorf("Organizations.ListUserTeams returned %+v, want %+v", teams, want) + } +}