Skip to content

Add parent team id param #724

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
40 changes: 40 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 34 additions & 7 deletions github/orgs_teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ type Team struct {
URL *string `json:"url,omitempty"`
Slug *string `json:"slug,omitempty"`

// Permission is deprecated when creating or editing a team in an org
// using the new GitHub permission model. It no longer identifies the
// permission a team has on its repos, but only specifies the default
// permission a repo is initially added with. Avoid confusion by
// specifying a permission value when calling AddTeamRepo.
// Permission specifies the default permission for repositories owned by the team.
Permission *string `json:"permission,omitempty"`

// Privacy identifies the level of privacy this team should have.
Expand Down Expand Up @@ -114,10 +110,41 @@ func (s *OrganizationsService) GetTeam(ctx context.Context, team int) (*Team, *R
return t, resp, nil
}

// NewTeam represents a team to be created or modified.
type NewTeam struct {
Name string `json:"name"` // Name of the team. (Required.)
Description *string `json:"description,omitempty"`
Maintainers []string `json:"maintainers,omitempty"`
RepoNames []string `json:"repo_names,omitempty"`
ParentTeamID *string `json:"parent_team_id,omitempty"`

// Deprecated: Permission is deprecated when creating or editing a team in an org
// using the new GitHub permission model. It no longer identifies the
// permission a team has on its repos, but only specifies the default
// permission a repo is initially added with. Avoid confusion by
// specifying a permission value when calling AddTeamRepo.
Permission *string `json:"permission,omitempty"`

// Privacy identifies the level of privacy this team should have.
// Possible values are:
// secret - only visible to organization owners and members of this team
// closed - visible to all members of this organization
// Default is "secret".
Privacy *string `json:"privacy,omitempty"`

// LDAPDN may be used in GitHub Enterprise when the team membership
// is synchronized with LDAP.
LDAPDN *string `json:"ldap_dn,omitempty"`
}

func (s NewTeam) String() string {
return Stringify(s)
}

// CreateTeam creates a new team within an organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#create-team
func (s *OrganizationsService) CreateTeam(ctx context.Context, org string, team *Team) (*Team, *Response, error) {
func (s *OrganizationsService) CreateTeam(ctx context.Context, org string, team *NewTeam) (*Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams", org)
req, err := s.client.NewRequest("POST", u, team)
if err != nil {
Expand All @@ -139,7 +166,7 @@ func (s *OrganizationsService) CreateTeam(ctx context.Context, org string, team
// EditTeam edits a team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#edit-team
func (s *OrganizationsService) EditTeam(ctx context.Context, id int, team *Team) (*Team, *Response, error) {
func (s *OrganizationsService) EditTeam(ctx context.Context, id int, team *NewTeam) (*Team, *Response, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's odd that the EditTeam endpoint requires both a name and an id for the team, but that is the documented behavior.

u := fmt.Sprintf("teams/%v", id)
req, err := s.client.NewRequest("PATCH", u, team)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions github/orgs_teams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ func TestOrganizationsService_CreateTeam(t *testing.T) {
setup()
defer teardown()

input := &Team{Name: String("n"), Privacy: String("closed")}
input := &NewTeam{Name: "n", Privacy: String("closed"), RepoNames: []string{"r"}}

mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) {
v := new(Team)
v := new(NewTeam)
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "POST")
Expand Down Expand Up @@ -126,12 +127,13 @@ func TestOrganizationsService_EditTeam(t *testing.T) {
setup()
defer teardown()

input := &Team{Name: String("n"), Privacy: String("closed")}
input := &NewTeam{Name: "n", Privacy: String("closed")}

mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) {
v := new(Team)
v := new(NewTeam)
json.NewDecoder(r.Body).Decode(v)

testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview)
testMethod(t, r, "PATCH")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
Expand Down