diff --git a/github/github-accessors.go b/github/github-accessors.go index 4fed8e50a62..2704f508946 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -2916,6 +2916,46 @@ func (n *NewPullRequest) GetTitle() string { return *n.Title } +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (n *NewTeam) GetDescription() string { + if n == nil || n.Description == nil { + return "" + } + return *n.Description +} + +// GetLDAPDN returns the LDAPDN field if it's non-nil, zero value otherwise. +func (n *NewTeam) GetLDAPDN() string { + if n == nil || n.LDAPDN == nil { + return "" + } + return *n.LDAPDN +} + +// GetParentTeamID returns the ParentTeamID field if it's non-nil, zero value otherwise. +func (n *NewTeam) GetParentTeamID() string { + if n == nil || n.ParentTeamID == nil { + return "" + } + return *n.ParentTeamID +} + +// GetPermission returns the Permission field if it's non-nil, zero value otherwise. +func (n *NewTeam) GetPermission() string { + if n == nil || n.Permission == nil { + return "" + } + return *n.Permission +} + +// GetPrivacy returns the Privacy field if it's non-nil, zero value otherwise. +func (n *NewTeam) GetPrivacy() string { + if n == nil || n.Privacy == nil { + return "" + } + return *n.Privacy +} + // GetID returns the ID field if it's non-nil, zero value otherwise. func (n *Notification) GetID() string { if n == nil || n.ID == nil { diff --git a/github/orgs_teams.go b/github/orgs_teams.go index 39161d7580f..ae3d449be21 100644 --- a/github/orgs_teams.go +++ b/github/orgs_teams.go @@ -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. @@ -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 { @@ -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) { u := fmt.Sprintf("teams/%v", id) req, err := s.client.NewRequest("PATCH", u, team) if err != nil { diff --git a/github/orgs_teams_test.go b/github/orgs_teams_test.go index a3933240368..239183c8e1d 100644 --- a/github/orgs_teams_test.go +++ b/github/orgs_teams_test.go @@ -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") @@ -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)