Skip to content

Commit 3e35f60

Browse files
committed
Merge branch 'add-parent-team-id-param' of https://github.com/e-beach/go-github into add-parent-team-id-param
2 parents 511f540 + ecc3db0 commit 3e35f60

File tree

4 files changed

+124
-7
lines changed

4 files changed

+124
-7
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/github.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ const (
102102

103103
// https://developer.github.com/changes/2017-07-26-team-review-request-thor-preview/
104104
mediaTypeTeamReviewPreview = "application/vnd.github.thor-preview+json"
105+
106+
// https://developer.github.com/changes/2017-08-30-preview-nested-teams/
107+
mediaTypeNestedTeamsPreview = "application/vnd.github.hellcat-preview+json"
105108
)
106109

107110
// A Client manages communication with the GitHub API.

github/orgs_teams.go

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Team struct {
3939
Organization *Organization `json:"organization,omitempty"`
4040
MembersURL *string `json:"members_url,omitempty"`
4141
RepositoriesURL *string `json:"repositories_url,omitempty"`
42+
Parent *Team `json:"parent,omitempty"`
4243

4344
// LDAPDN is only available in GitHub Enterprise and when the team
4445
// membership is synchronized with LDAP.
@@ -79,6 +80,9 @@ func (s *OrganizationsService) ListTeams(ctx context.Context, org string, opt *L
7980
return nil, nil, err
8081
}
8182

83+
// TODO: remove custom Accept header when this API fully launches.
84+
req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
85+
8286
var teams []*Team
8387
resp, err := s.client.Do(ctx, req, &teams)
8488
if err != nil {
@@ -98,6 +102,9 @@ func (s *OrganizationsService) GetTeam(ctx context.Context, team int) (*Team, *R
98102
return nil, nil, err
99103
}
100104

105+
// TODO: remove custom Accept header when this API fully launches.
106+
req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
107+
101108
t := new(Team)
102109
resp, err := s.client.Do(ctx, req, t)
103110
if err != nil {
@@ -107,16 +114,48 @@ func (s *OrganizationsService) GetTeam(ctx context.Context, team int) (*Team, *R
107114
return t, resp, nil
108115
}
109116

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

156+
// TODO: remove custom Accept header when this API fully launches.
157+
req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
158+
120159
t := new(Team)
121160
resp, err := s.client.Do(ctx, req, t)
122161
if err != nil {
@@ -129,13 +168,16 @@ func (s *OrganizationsService) CreateTeam(ctx context.Context, org string, team
129168
// EditTeam edits a team.
130169
//
131170
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#edit-team
132-
func (s *OrganizationsService) EditTeam(ctx context.Context, id int, team *Team) (*Team, *Response, error) {
171+
func (s *OrganizationsService) EditTeam(ctx context.Context, id int, team *NewTeam) (*Team, *Response, error) {
133172
u := fmt.Sprintf("teams/%v", id)
134173
req, err := s.client.NewRequest("PATCH", u, team)
135174
if err != nil {
136175
return nil, nil, err
137176
}
138177

178+
// TODO: remove custom Accept header when this API fully launches.
179+
req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
180+
139181
t := new(Team)
140182
resp, err := s.client.Do(ctx, req, t)
141183
if err != nil {
@@ -315,6 +357,9 @@ func (s *OrganizationsService) ListUserTeams(ctx context.Context, opt *ListOptio
315357
return nil, nil, err
316358
}
317359

360+
// TODO: remove custom Accept header when this API fully launches.
361+
req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
362+
318363
var teams []*Team
319364
resp, err := s.client.Do(ctx, req, &teams)
320365
if err != nil {

github/orgs_teams_test.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func TestOrganizationsService_ListTeams(t *testing.T) {
2121

2222
mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) {
2323
testMethod(t, r, "GET")
24+
testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview)
2425
testFormValues(t, r, values{"page": "2"})
2526
fmt.Fprint(w, `[{"id":1}]`)
2627
})
@@ -48,7 +49,8 @@ func TestOrganizationsService_GetTeam(t *testing.T) {
4849

4950
mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) {
5051
testMethod(t, r, "GET")
51-
fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p", "ldap_dn":"cn=n,ou=groups,dc=example,dc=com"}`)
52+
testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview)
53+
fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p", "ldap_dn":"cn=n,ou=groups,dc=example,dc=com", "parent":null}`)
5254
})
5355

5456
team, _, err := client.Organizations.GetTeam(context.Background(), 1)
@@ -62,17 +64,42 @@ func TestOrganizationsService_GetTeam(t *testing.T) {
6264
}
6365
}
6466

67+
func TestOrganizationService_GetTeam_nestedTeams(t *testing.T) {
68+
setup()
69+
defer teardown()
70+
71+
mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) {
72+
testMethod(t, r, "GET")
73+
testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview)
74+
fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p",
75+
"parent": {"id":2, "name":"n", "description": "d", "parent": null}}`)
76+
})
77+
78+
team, _, err := client.Organizations.GetTeam(context.Background(), 1)
79+
if err != nil {
80+
t.Errorf("Organizations.GetTeam returned error: %v", err)
81+
}
82+
83+
want := &Team{ID: Int(1), Name: String("n"), Description: String("d"), URL: String("u"), Slug: String("s"), Permission: String("p"),
84+
Parent: &Team{ID: Int(2), Name: String("n"), Description: String("d")},
85+
}
86+
if !reflect.DeepEqual(team, want) {
87+
t.Errorf("Organizations.GetTeam returned %+v, want %+v", team, want)
88+
}
89+
}
90+
6591
func TestOrganizationsService_CreateTeam(t *testing.T) {
6692
setup()
6793
defer teardown()
6894

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

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

75101
testMethod(t, r, "POST")
102+
testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview)
76103
if !reflect.DeepEqual(v, input) {
77104
t.Errorf("Request body = %+v, want %+v", v, input)
78105
}
@@ -100,12 +127,13 @@ func TestOrganizationsService_EditTeam(t *testing.T) {
100127
setup()
101128
defer teardown()
102129

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

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

136+
testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview)
109137
testMethod(t, r, "PATCH")
110138
if !reflect.DeepEqual(v, input) {
111139
t.Errorf("Request body = %+v, want %+v", v, input)
@@ -487,6 +515,7 @@ func TestOrganizationsService_ListUserTeams(t *testing.T) {
487515

488516
mux.HandleFunc("/user/teams", func(w http.ResponseWriter, r *http.Request) {
489517
testMethod(t, r, "GET")
518+
testHeader(t, r, "Accept", mediaTypeNestedTeamsPreview)
490519
testFormValues(t, r, values{"page": "1"})
491520
fmt.Fprint(w, `[{"id":1}]`)
492521
})

0 commit comments

Comments
 (0)