Skip to content

Commit beb277c

Browse files
elliott-beachdmitshur
authored andcommitted
Add NewTeam struct. (#724)
This replaces Team with NewTeam in function that accept a team for creating or editing a team. The NewTeam struct is similar to the existing NewPullRequest for creating pull requests. We need a new struct because the set of parameters for creating or editing a team contains some parameters that are not in the parameter for teams, and most properties of teams cannot be used for editing. The specific change is that Teams are returned with a parent field, but are created/edited with a parent_id field. Helps #714.
1 parent d25a6ce commit beb277c

File tree

3 files changed

+80
-11
lines changed

3 files changed

+80
-11
lines changed

github/github-accessors.go

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

github/orgs_teams.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ type Team struct {
2020
URL *string `json:"url,omitempty"`
2121
Slug *string `json:"slug,omitempty"`
2222

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

3026
// 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
114110
return t, resp, nil
115111
}
116112

113+
// NewTeam represents a team to be created or modified.
114+
type NewTeam struct {
115+
Name string `json:"name"` // Name of the team. (Required.)
116+
Description *string `json:"description,omitempty"`
117+
Maintainers []string `json:"maintainers,omitempty"`
118+
RepoNames []string `json:"repo_names,omitempty"`
119+
ParentTeamID *string `json:"parent_team_id,omitempty"`
120+
121+
// Deprecated: Permission is deprecated when creating or editing a team in an org
122+
// using the new GitHub permission model. It no longer identifies the
123+
// permission a team has on its repos, but only specifies the default
124+
// permission a repo is initially added with. Avoid confusion by
125+
// specifying a permission value when calling AddTeamRepo.
126+
Permission *string `json:"permission,omitempty"`
127+
128+
// Privacy identifies the level of privacy this team should have.
129+
// Possible values are:
130+
// secret - only visible to organization owners and members of this team
131+
// closed - visible to all members of this organization
132+
// Default is "secret".
133+
Privacy *string `json:"privacy,omitempty"`
134+
135+
// LDAPDN may be used in GitHub Enterprise when the team membership
136+
// is synchronized with LDAP.
137+
LDAPDN *string `json:"ldap_dn,omitempty"`
138+
}
139+
140+
func (s NewTeam) String() string {
141+
return Stringify(s)
142+
}
143+
117144
// CreateTeam creates a new team within an organization.
118145
//
119146
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#create-team
120-
func (s *OrganizationsService) CreateTeam(ctx context.Context, org string, team *Team) (*Team, *Response, error) {
147+
func (s *OrganizationsService) CreateTeam(ctx context.Context, org string, team *NewTeam) (*Team, *Response, error) {
121148
u := fmt.Sprintf("orgs/%v/teams", org)
122149
req, err := s.client.NewRequest("POST", u, team)
123150
if err != nil {
@@ -139,7 +166,7 @@ func (s *OrganizationsService) CreateTeam(ctx context.Context, org string, team
139166
// EditTeam edits a team.
140167
//
141168
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#edit-team
142-
func (s *OrganizationsService) EditTeam(ctx context.Context, id int, team *Team) (*Team, *Response, error) {
169+
func (s *OrganizationsService) EditTeam(ctx context.Context, id int, team *NewTeam) (*Team, *Response, error) {
143170
u := fmt.Sprintf("teams/%v", id)
144171
req, err := s.client.NewRequest("PATCH", u, team)
145172
if err != nil {

github/orgs_teams_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ func TestOrganizationsService_CreateTeam(t *testing.T) {
9292
setup()
9393
defer teardown()
9494

95-
input := &Team{Name: String("n"), Privacy: String("closed")}
95+
input := &NewTeam{Name: "n", Privacy: String("closed"), RepoNames: []string{"r"}}
96+
9697
mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) {
97-
v := new(Team)
98+
v := new(NewTeam)
9899
json.NewDecoder(r.Body).Decode(v)
99100

100101
testMethod(t, r, "POST")
@@ -126,12 +127,13 @@ func TestOrganizationsService_EditTeam(t *testing.T) {
126127
setup()
127128
defer teardown()
128129

129-
input := &Team{Name: String("n"), Privacy: String("closed")}
130+
input := &NewTeam{Name: "n", Privacy: String("closed")}
130131

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

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

0 commit comments

Comments
 (0)