Skip to content

Commit 63a1994

Browse files
authored
Add support for External Groups (#2217)
Fixes: #2213.
1 parent 1d9884e commit 63a1994

File tree

4 files changed

+646
-0
lines changed

4 files changed

+646
-0
lines changed

github/github-accessors.go

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/teams.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,3 +854,116 @@ func (s *TeamsService) CreateOrUpdateIDPGroupConnectionsBySlug(ctx context.Conte
854854

855855
return groups, resp, nil
856856
}
857+
858+
// ExternalGroupMember represents a member of an external group.
859+
type ExternalGroupMember struct {
860+
MemberID *int64 `json:"member_id,omitempty"`
861+
MemberLogin *string `json:"member_login,omitempty"`
862+
MemberName *string `json:"member_name,omitempty"`
863+
MemberEmail *string `json:"member_email,omitempty"`
864+
}
865+
866+
// ExternalGroupTeam represents a team connected to an external group.
867+
type ExternalGroupTeam struct {
868+
TeamID *int64 `json:"team_id,omitempty"`
869+
TeamName *string `json:"team_name,omitempty"`
870+
}
871+
872+
// ExternalGroup represents an external group.
873+
type ExternalGroup struct {
874+
GroupID *int64 `json:"group_id,omitempty"`
875+
GroupName *string `json:"group_name,omitempty"`
876+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
877+
Teams []*ExternalGroupTeam `json:"teams,omitempty"`
878+
Members []*ExternalGroupMember `json:"members,omitempty"`
879+
}
880+
881+
// ExternalGroupList represents a list of external groups.
882+
type ExternalGroupList struct {
883+
Groups []*ExternalGroup `json:"groups"`
884+
}
885+
886+
// GetExternalGroup fetches an external group.
887+
//
888+
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/reference/teams#get-an-external-group
889+
func (s *TeamsService) GetExternalGroup(ctx context.Context, org string, groupID int64) (*ExternalGroup, *Response, error) {
890+
u := fmt.Sprintf("orgs/%v/external-group/%v", org, groupID)
891+
req, err := s.client.NewRequest("GET", u, nil)
892+
if err != nil {
893+
return nil, nil, err
894+
}
895+
896+
externalGroup := new(ExternalGroup)
897+
resp, err := s.client.Do(ctx, req, externalGroup)
898+
if err != nil {
899+
return nil, resp, err
900+
}
901+
902+
return externalGroup, resp, nil
903+
}
904+
905+
// ListExternalGroupsOptions specifies the optional parameters to the
906+
// TeamsService.ListExternalGroups method.
907+
type ListExternalGroupsOptions struct {
908+
DisplayName *string `url:"display_name,omitempty"`
909+
910+
ListOptions
911+
}
912+
913+
// ListExternalGroups lists external groups connected to a team on GitHub.
914+
//
915+
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/reference/teams#list-external-groups-in-an-organization
916+
func (s *TeamsService) ListExternalGroups(ctx context.Context, org string, opts *ListExternalGroupsOptions) (*ExternalGroupList, *Response, error) {
917+
u := fmt.Sprintf("orgs/%v/external-groups", org)
918+
u, err := addOptions(u, opts)
919+
if err != nil {
920+
return nil, nil, err
921+
}
922+
923+
req, err := s.client.NewRequest("GET", u, nil)
924+
if err != nil {
925+
return nil, nil, err
926+
}
927+
928+
externalGroups := new(ExternalGroupList)
929+
resp, err := s.client.Do(ctx, req, externalGroups)
930+
if err != nil {
931+
return nil, resp, err
932+
}
933+
934+
return externalGroups, resp, nil
935+
}
936+
937+
// UpdateConnectedExternalGroup updates the connection between an external group and a team.
938+
//
939+
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/reference/teams#update-the-connection-between-an-external-group-and-a-team
940+
func (s *TeamsService) UpdateConnectedExternalGroup(ctx context.Context, org, slug string, eg *ExternalGroup) (*ExternalGroup, *Response, error) {
941+
u := fmt.Sprintf("orgs/%v/teams/%v/external-groups", org, slug)
942+
943+
req, err := s.client.NewRequest("PATCH", u, eg)
944+
if err != nil {
945+
return nil, nil, err
946+
}
947+
948+
externalGroup := new(ExternalGroup)
949+
resp, err := s.client.Do(ctx, req, externalGroup)
950+
if err != nil {
951+
return nil, resp, err
952+
}
953+
954+
return externalGroup, resp, nil
955+
}
956+
957+
// RemoveConnectedExternalGroup removes the connection between an external group and a team.
958+
//
959+
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/reference/teams#remove-the-connection-between-an-external-group-and-a-team
960+
func (s *TeamsService) RemoveConnectedExternalGroup(ctx context.Context, org, slug string) (*Response, error) {
961+
u := fmt.Sprintf("orgs/%v/teams/%v/external-groups", org, slug)
962+
963+
req, err := s.client.NewRequest("DELETE", u, nil)
964+
if err != nil {
965+
return nil, err
966+
}
967+
968+
return s.client.Do(ctx, req, nil)
969+
}

0 commit comments

Comments
 (0)