Skip to content

Commit 1f336cc

Browse files
committed
Add ListExternalGroupsForTeamBySlug to Teams API
1 parent 4814a50 commit 1f336cc

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

github/teams.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ type ListExternalGroupsOptions struct {
913913
ListOptions
914914
}
915915

916-
// ListExternalGroups lists external groups connected to a team on GitHub.
916+
// ListExternalGroups lists external groups in an organization on GitHub.
917917
//
918918
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/teams/external-groups#list-external-groups-in-an-organization
919919
func (s *TeamsService) ListExternalGroups(ctx context.Context, org string, opts *ListExternalGroupsOptions) (*ExternalGroupList, *Response, error) {
@@ -937,6 +937,26 @@ func (s *TeamsService) ListExternalGroups(ctx context.Context, org string, opts
937937
return externalGroups, resp, nil
938938
}
939939

940+
// ListExternalGroupsForTeamBySlug lists external groups connected to a team on GitHub.
941+
//
942+
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/teams/external-groups#list-a-connection-between-an-external-group-and-a-team
943+
func (s *TeamsService) ListExternalGroupsForTeamBySlug(ctx context.Context, org, slug string) (*ExternalGroupList, *Response, error) {
944+
u := fmt.Sprintf("orgs/%v/teams/%v/external-groups", org, slug)
945+
946+
req, err := s.client.NewRequest("GET", u, nil)
947+
if err != nil {
948+
return nil, nil, err
949+
}
950+
951+
externalGroups := new(ExternalGroupList)
952+
resp, err := s.client.Do(ctx, req, externalGroups)
953+
if err != nil {
954+
return nil, resp, err
955+
}
956+
957+
return externalGroups, resp, nil
958+
}
959+
940960
// UpdateConnectedExternalGroup updates the connection between an external group and a team.
941961
//
942962
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/teams/external-groups#update-the-connection-between-an-external-group-and-a-team

github/teams_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,79 @@ func TestTeamsService_ListExternalGroups_notFound(t *testing.T) {
19351935
}
19361936
}
19371937

1938+
func TestTeamsService_ListExternalGroupsForTeamBySlug(t *testing.T) {
1939+
client, mux, _, teardown := setup()
1940+
defer teardown()
1941+
1942+
mux.HandleFunc("/orgs/o/teams/t/external-groups", func(w http.ResponseWriter, r *http.Request) {
1943+
testMethod(t, r, "GET")
1944+
fmt.Fprint(w, `{
1945+
"groups": [
1946+
{
1947+
"group_id": 123,
1948+
"group_name": "Octocat admins",
1949+
"updated_at": "2006-01-02T15:04:05Z"
1950+
}
1951+
]
1952+
}`)
1953+
})
1954+
1955+
ctx := context.Background()
1956+
list, _, err := client.Teams.ListExternalGroupsForTeamBySlug(ctx, "o", "t")
1957+
if err != nil {
1958+
t.Errorf("Teams.ListExternalGroupsForTeamBySlug returned error: %v", err)
1959+
}
1960+
1961+
want := &ExternalGroupList{
1962+
Groups: []*ExternalGroup{
1963+
{
1964+
GroupID: Int64(123),
1965+
GroupName: String("Octocat admins"),
1966+
UpdatedAt: &Timestamp{Time: referenceTime},
1967+
},
1968+
},
1969+
}
1970+
if !cmp.Equal(list, want) {
1971+
t.Errorf("Teams.ListExternalGroupsForTeamBySlug returned %+v, want %+v", list, want)
1972+
}
1973+
1974+
const methodName = "ListExternalGroupsForTeamBySlug"
1975+
testBadOptions(t, methodName, func() (err error) {
1976+
_, _, err = client.Teams.ListExternalGroupsForTeamBySlug(ctx, "\n", "\n")
1977+
return err
1978+
})
1979+
1980+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
1981+
got, resp, err := client.Teams.ListExternalGroupsForTeamBySlug(ctx, "o", "t")
1982+
if got != nil {
1983+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
1984+
}
1985+
return resp, err
1986+
})
1987+
}
1988+
1989+
func TestTeamsService_ListExternalGroupsForTeamBySlug_notFound(t *testing.T) {
1990+
client, mux, _, teardown := setup()
1991+
defer teardown()
1992+
1993+
mux.HandleFunc("/orgs/o/teams/t/external-groups", func(w http.ResponseWriter, r *http.Request) {
1994+
testMethod(t, r, "GET")
1995+
w.WriteHeader(http.StatusNotFound)
1996+
})
1997+
1998+
ctx := context.Background()
1999+
eg, resp, err := client.Teams.ListExternalGroupsForTeamBySlug(ctx, "o", "t")
2000+
if err == nil {
2001+
t.Errorf("Expected HTTP 404 response")
2002+
}
2003+
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
2004+
t.Errorf("Teams.ListExternalGroupsForTeamBySlug returned status %d, want %d", got, want)
2005+
}
2006+
if eg != nil {
2007+
t.Errorf("Teams.ListExternalGroupsForTeamBySlug returned %+v, want nil", eg)
2008+
}
2009+
}
2010+
19382011
func TestTeamsService_UpdateConnectedExternalGroup(t *testing.T) {
19392012
client, mux, _, teardown := setup()
19402013
defer teardown()

0 commit comments

Comments
 (0)