+
Skip to content

Update IdP team-sync list and create/update endpoints with ByID and BySlug #1484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2020
Merged
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
56 changes: 49 additions & 7 deletions github/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,12 @@ func (s *TeamsService) ListIDPGroupsInOrganization(ctx context.Context, org stri
return groups, resp, nil
}

// ListIDPGroupsForTeam lists IDP groups connected to a team on GitHub.
// ListIDPGroupsForTeamByID lists IDP groups connected to a team on GitHub
// given organization and team IDs.
//
// GitHub API docs: https://developer.github.com/v3/teams/team_sync/#list-idp-groups-for-a-team
func (s *TeamsService) ListIDPGroupsForTeam(ctx context.Context, teamID string) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("teams/%v/team-sync/group-mappings", teamID)
func (s *TeamsService) ListIDPGroupsForTeamByID(ctx context.Context, orgID, teamID int64) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v/team-sync/group-mappings", orgID, teamID)

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
Expand All @@ -784,12 +785,53 @@ func (s *TeamsService) ListIDPGroupsForTeam(ctx context.Context, teamID string)
return groups, resp, err
}

// CreateOrUpdateIDPGroupConnections creates, updates, or removes a connection between a team
// and an IDP group.
// ListIDPGroupsForTeamBySlug lists IDP groups connected to a team on GitHub
// given organization name and team slug.
//
// GitHub API docs: https://developer.github.com/v3/teams/team_sync/#list-idp-groups-for-a-team
func (s *TeamsService) ListIDPGroupsForTeamBySlug(ctx context.Context, org, slug string) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/team-sync/group-mappings", org, slug)

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

groups := new(IDPGroupList)
resp, err := s.client.Do(ctx, req, groups)
if err != nil {
return nil, resp, err
}
return groups, resp, err
}

// CreateOrUpdateIDPGroupConnectionsByID creates, updates, or removes a connection
// between a team and an IDP group given organization and team IDs.
//
// GitHub API docs: https://developer.github.com/v3/teams/team_sync/#create-or-update-idp-group-connections
func (s *TeamsService) CreateOrUpdateIDPGroupConnectionsByID(ctx context.Context, orgID, teamID int64, opts IDPGroupList) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("organizations/%v/team/%v/team-sync/group-mappings", orgID, teamID)

req, err := s.client.NewRequest("PATCH", u, opts)
if err != nil {
return nil, nil, err
}

groups := new(IDPGroupList)
resp, err := s.client.Do(ctx, req, groups)
if err != nil {
return nil, resp, err
}

return groups, resp, nil
}

// CreateOrUpdateIDPGroupConnectionsBySlug creates, updates, or removes a connection
// between a team and an IDP group given organization name and team slug.
//
// GitHub API docs: https://developer.github.com/v3/teams/team_sync/#create-or-update-idp-group-connections
func (s *TeamsService) CreateOrUpdateIDPGroupConnections(ctx context.Context, teamID string, opts IDPGroupList) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("teams/%v/team-sync/group-mappings", teamID)
func (s *TeamsService) CreateOrUpdateIDPGroupConnectionsBySlug(ctx context.Context, org, slug string, opts IDPGroupList) (*IDPGroupList, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams/%v/team-sync/group-mappings", org, slug)

req, err := s.client.NewRequest("PATCH", u, opts)
if err != nil {
Expand Down
121 changes: 106 additions & 15 deletions github/teams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,18 +946,18 @@ func TestTeamsService_ListIDPGroupsInOrganization(t *testing.T) {
}
}

func TestTeamsService_ListIDPGroupsForTeam(t *testing.T) {
func TestTeamsService_ListIDPGroupsForTeamByID(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/teams/1/team-sync/group-mappings", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/organizations/1/team/1/team-sync/group-mappings", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"groups": [{"group_id": "1", "group_name": "n", "group_description": "d"}]}`)
})

groups, _, err := client.Teams.ListIDPGroupsForTeam(context.Background(), "1")
groups, _, err := client.Teams.ListIDPGroupsForTeamByID(context.Background(), 1, 1)
if err != nil {
t.Errorf("Teams.ListIDPGroupsForTeam returned error: %v", err)
t.Errorf("Teams.ListIDPGroupsForTeamByID returned error: %v", err)
}

want := &IDPGroupList{
Expand All @@ -970,15 +970,81 @@ func TestTeamsService_ListIDPGroupsForTeam(t *testing.T) {
},
}
if !reflect.DeepEqual(groups, want) {
t.Errorf("Teams.ListIDPGroupsForTeam returned %+v. want %+v", groups, want)
t.Errorf("Teams.ListIDPGroupsForTeamByID returned %+v. want %+v", groups, want)
}
}

func TestTeamsService_CreateOrUpdateIDPGroupConnections(t *testing.T) {
func TestTeamsService_ListIDPGroupsForTeamBySlug(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/teams/1/team-sync/group-mappings", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/orgs/o/teams/slug/team-sync/group-mappings", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"groups": [{"group_id": "1", "group_name": "n", "group_description": "d"}]}`)
})

groups, _, err := client.Teams.ListIDPGroupsForTeamBySlug(context.Background(), "o", "slug")
if err != nil {
t.Errorf("Teams.ListIDPGroupsForTeamBySlug returned error: %v", err)
}

want := &IDPGroupList{
Groups: []*IDPGroup{
{
GroupID: String("1"),
GroupName: String("n"),
GroupDescription: String("d"),
},
},
}
if !reflect.DeepEqual(groups, want) {
t.Errorf("Teams.ListIDPGroupsForTeamBySlug returned %+v. want %+v", groups, want)
}
}

func TestTeamsService_CreateOrUpdateIDPGroupConnectionsByID(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/organizations/1/team/1/team-sync/group-mappings", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
fmt.Fprint(w, `{"groups": [{"group_id": "1", "group_name": "n", "group_description": "d"}]}`)
})

input := IDPGroupList{
Groups: []*IDPGroup{
{
GroupID: String("1"),
GroupName: String("n"),
GroupDescription: String("d"),
},
},
}

groups, _, err := client.Teams.CreateOrUpdateIDPGroupConnectionsByID(context.Background(), 1, 1, input)
if err != nil {
t.Errorf("Teams.CreateOrUpdateIDPGroupConnectionsByID returned error: %v", err)
}

want := &IDPGroupList{
Groups: []*IDPGroup{
{
GroupID: String("1"),
GroupName: String("n"),
GroupDescription: String("d"),
},
},
}
if !reflect.DeepEqual(groups, want) {
t.Errorf("Teams.CreateOrUpdateIDPGroupConnectionsByID returned %+v. want %+v", groups, want)
}
}

func TestTeamsService_CreateOrUpdateIDPGroupConnectionsBySlug(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/orgs/o/teams/slug/team-sync/group-mappings", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
fmt.Fprint(w, `{"groups": [{"group_id": "1", "group_name": "n", "group_description": "d"}]}`)
})
Expand All @@ -993,9 +1059,9 @@ func TestTeamsService_CreateOrUpdateIDPGroupConnections(t *testing.T) {
},
}

groups, _, err := client.Teams.CreateOrUpdateIDPGroupConnections(context.Background(), "1", input)
groups, _, err := client.Teams.CreateOrUpdateIDPGroupConnectionsBySlug(context.Background(), "o", "slug", input)
if err != nil {
t.Errorf("Teams.CreateOrUpdateIDPGroupConnections returned error: %v", err)
t.Errorf("Teams.CreateOrUpdateIDPGroupConnectionsBySlug returned error: %v", err)
}

want := &IDPGroupList{
Expand All @@ -1008,15 +1074,40 @@ func TestTeamsService_CreateOrUpdateIDPGroupConnections(t *testing.T) {
},
}
if !reflect.DeepEqual(groups, want) {
t.Errorf("Teams.CreateOrUpdateIDPGroupConnections returned %+v. want %+v", groups, want)
t.Errorf("Teams.CreateOrUpdateIDPGroupConnectionsBySlug returned %+v. want %+v", groups, want)
}
}
func TestTeamsService_CreateOrUpdateIDPGroupConnectionsByID_empty(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/organizations/1/team/1/team-sync/group-mappings", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
fmt.Fprint(w, `{"groups": []}`)
})

input := IDPGroupList{
Groups: []*IDPGroup{},
}

groups, _, err := client.Teams.CreateOrUpdateIDPGroupConnectionsByID(context.Background(), 1, 1, input)
if err != nil {
t.Errorf("Teams.CreateOrUpdateIDPGroupConnectionsByID returned error: %v", err)
}

want := &IDPGroupList{
Groups: []*IDPGroup{},
}
if !reflect.DeepEqual(groups, want) {
t.Errorf("Teams.CreateOrUpdateIDPGroupConnectionsByID returned %+v. want %+v", groups, want)
}
}

func TestTeamsService_CreateOrUpdateIDPGroupConnections_empty(t *testing.T) {
func TestTeamsService_CreateOrUpdateIDPGroupConnectionsBySlug_empty(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/teams/1/team-sync/group-mappings", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/orgs/o/teams/slug/team-sync/group-mappings", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
fmt.Fprint(w, `{"groups": []}`)
})
Expand All @@ -1025,15 +1116,15 @@ func TestTeamsService_CreateOrUpdateIDPGroupConnections_empty(t *testing.T) {
Groups: []*IDPGroup{},
}

groups, _, err := client.Teams.CreateOrUpdateIDPGroupConnections(context.Background(), "1", input)
groups, _, err := client.Teams.CreateOrUpdateIDPGroupConnectionsBySlug(context.Background(), "o", "slug", input)
if err != nil {
t.Errorf("Teams.CreateOrUpdateIDPGroupConnections returned error: %v", err)
t.Errorf("Teams.CreateOrUpdateIDPGroupConnectionsBySlug returned error: %v", err)
}

want := &IDPGroupList{
Groups: []*IDPGroup{},
}
if !reflect.DeepEqual(groups, want) {
t.Errorf("Teams.CreateOrUpdateIDPGroupConnections returned %+v. want %+v", groups, want)
t.Errorf("Teams.CreateOrUpdateIDPGroupConnectionsBySlug returned %+v. want %+v", groups, want)
}
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载