aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/google/go-github/github/orgs_teams.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/google/go-github/github/orgs_teams.go')
-rw-r--r--vendor/github.com/google/go-github/github/orgs_teams.go135
1 files changed, 109 insertions, 26 deletions
diff --git a/vendor/github.com/google/go-github/github/orgs_teams.go b/vendor/github.com/google/go-github/github/orgs_teams.go
index 684e2da..b3cc9f0 100644
--- a/vendor/github.com/google/go-github/github/orgs_teams.go
+++ b/vendor/github.com/google/go-github/github/orgs_teams.go
@@ -8,23 +8,20 @@ package github
import (
"context"
"fmt"
+ "strings"
"time"
)
// Team represents a team within a GitHub organization. Teams are used to
// manage access to an organization's repositories.
type Team struct {
- ID *int `json:"id,omitempty"`
+ ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
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.
@@ -39,6 +36,7 @@ type Team struct {
Organization *Organization `json:"organization,omitempty"`
MembersURL *string `json:"members_url,omitempty"`
RepositoriesURL *string `json:"repositories_url,omitempty"`
+ Parent *Team `json:"parent,omitempty"`
// LDAPDN is only available in GitHub Enterprise and when the team
// membership is synchronized with LDAP.
@@ -51,13 +49,15 @@ func (t Team) String() string {
// Invitation represents a team member's invitation status.
type Invitation struct {
- ID *int `json:"id,omitempty"`
+ ID *int64 `json:"id,omitempty"`
Login *string `json:"login,omitempty"`
Email *string `json:"email,omitempty"`
// Role can be one of the values - 'direct_member', 'admin', 'billing_manager', 'hiring_manager', or 'reinstate'.
- Role *string `json:"role,omitempty"`
- CreatedAt *time.Time `json:"created_at,omitempty"`
- Inviter *User `json:"inviter,omitempty"`
+ Role *string `json:"role,omitempty"`
+ CreatedAt *time.Time `json:"created_at,omitempty"`
+ Inviter *User `json:"inviter,omitempty"`
+ TeamCount *int `json:"team_count,omitempty"`
+ InvitationTeamURL *string `json:"invitation_team_url,omitempty"`
}
func (i Invitation) String() string {
@@ -79,6 +79,9 @@ func (s *OrganizationsService) ListTeams(ctx context.Context, org string, opt *L
return nil, nil, err
}
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
+
var teams []*Team
resp, err := s.client.Do(ctx, req, &teams)
if err != nil {
@@ -91,13 +94,16 @@ func (s *OrganizationsService) ListTeams(ctx context.Context, org string, opt *L
// GetTeam fetches a team by ID.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#get-team
-func (s *OrganizationsService) GetTeam(ctx context.Context, team int) (*Team, *Response, error) {
+func (s *OrganizationsService) GetTeam(ctx context.Context, team int64) (*Team, *Response, error) {
u := fmt.Sprintf("teams/%v", team)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
+
t := new(Team)
resp, err := s.client.Do(ctx, req, t)
if err != nil {
@@ -107,16 +113,50 @@ 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 *int64 `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 {
return nil, nil, err
}
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
+
t := new(Team)
resp, err := s.client.Do(ctx, req, t)
if err != nil {
@@ -129,13 +169,16 @@ 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 int64, team *NewTeam) (*Team, *Response, error) {
u := fmt.Sprintf("teams/%v", id)
req, err := s.client.NewRequest("PATCH", u, team)
if err != nil {
return nil, nil, err
}
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
+
t := new(Team)
resp, err := s.client.Do(ctx, req, t)
if err != nil {
@@ -148,13 +191,15 @@ func (s *OrganizationsService) EditTeam(ctx context.Context, id int, team *Team)
// DeleteTeam deletes a team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#delete-team
-func (s *OrganizationsService) DeleteTeam(ctx context.Context, team int) (*Response, error) {
+func (s *OrganizationsService) DeleteTeam(ctx context.Context, team int64) (*Response, error) {
u := fmt.Sprintf("teams/%v", team)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
+ req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
+
return s.client.Do(ctx, req, nil)
}
@@ -168,11 +213,37 @@ type OrganizationListTeamMembersOptions struct {
ListOptions
}
+// ListChildTeams lists child teams for a team.
+//
+// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-child-teams
+func (s *OrganizationsService) ListChildTeams(ctx context.Context, teamID int64, opt *ListOptions) ([]*Team, *Response, error) {
+ u := fmt.Sprintf("teams/%v/teams", teamID)
+ u, err := addOptions(u, opt)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ req, err := s.client.NewRequest("GET", u, nil)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
+
+ var teams []*Team
+ resp, err := s.client.Do(ctx, req, &teams)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ return teams, resp, nil
+}
+
// ListTeamMembers lists all of the users who are members of the specified
// team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-team-members
-func (s *OrganizationsService) ListTeamMembers(ctx context.Context, team int, opt *OrganizationListTeamMembersOptions) ([]*User, *Response, error) {
+func (s *OrganizationsService) ListTeamMembers(ctx context.Context, team int64, opt *OrganizationListTeamMembersOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("teams/%v/members", team)
u, err := addOptions(u, opt)
if err != nil {
@@ -184,6 +255,8 @@ func (s *OrganizationsService) ListTeamMembers(ctx context.Context, team int, op
return nil, nil, err
}
+ req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
+
var members []*User
resp, err := s.client.Do(ctx, req, &members)
if err != nil {
@@ -196,7 +269,10 @@ func (s *OrganizationsService) ListTeamMembers(ctx context.Context, team int, op
// IsTeamMember checks if a user is a member of the specified team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#get-team-member
-func (s *OrganizationsService) IsTeamMember(ctx context.Context, team int, user string) (bool, *Response, error) {
+//
+// Deprecated: This API has been marked as deprecated in the Github API docs,
+// OrganizationsService.GetTeamMembership method should be used instead.
+func (s *OrganizationsService) IsTeamMember(ctx context.Context, team int64, user string) (bool, *Response, error) {
u := fmt.Sprintf("teams/%v/members/%v", team, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -211,7 +287,7 @@ func (s *OrganizationsService) IsTeamMember(ctx context.Context, team int, user
// ListTeamRepos lists the repositories that the specified team has access to.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-team-repos
-func (s *OrganizationsService) ListTeamRepos(ctx context.Context, team int, opt *ListOptions) ([]*Repository, *Response, error) {
+func (s *OrganizationsService) ListTeamRepos(ctx context.Context, team int64, opt *ListOptions) ([]*Repository, *Response, error) {
u := fmt.Sprintf("teams/%v/repos", team)
u, err := addOptions(u, opt)
if err != nil {
@@ -224,7 +300,8 @@ func (s *OrganizationsService) ListTeamRepos(ctx context.Context, team int, opt
}
// TODO: remove custom Accept header when topics API fully launches.
- req.Header.Set("Accept", mediaTypeTopicsPreview)
+ headers := []string{mediaTypeTopicsPreview, mediaTypeNestedTeamsPreview}
+ req.Header.Set("Accept", strings.Join(headers, ", "))
var repos []*Repository
resp, err := s.client.Do(ctx, req, &repos)
@@ -240,14 +317,15 @@ func (s *OrganizationsService) ListTeamRepos(ctx context.Context, team int, opt
// permissions team has for that repo.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#check-if-a-team-manages-a-repository
-func (s *OrganizationsService) IsTeamRepo(ctx context.Context, team int, owner string, repo string) (*Repository, *Response, error) {
+func (s *OrganizationsService) IsTeamRepo(ctx context.Context, team int64, owner string, repo string) (*Repository, *Response, error) {
u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
- req.Header.Set("Accept", mediaTypeOrgPermissionRepo)
+ headers := []string{mediaTypeOrgPermissionRepo, mediaTypeNestedTeamsPreview}
+ req.Header.Set("Accept", strings.Join(headers, ", "))
repository := new(Repository)
resp, err := s.client.Do(ctx, req, repository)
@@ -276,7 +354,7 @@ type OrganizationAddTeamRepoOptions struct {
// belongs, or a direct fork of a repository owned by the organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#add-team-repo
-func (s *OrganizationsService) AddTeamRepo(ctx context.Context, team int, owner string, repo string, opt *OrganizationAddTeamRepoOptions) (*Response, error) {
+func (s *OrganizationsService) AddTeamRepo(ctx context.Context, team int64, owner string, repo string, opt *OrganizationAddTeamRepoOptions) (*Response, error) {
u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo)
req, err := s.client.NewRequest("PUT", u, opt)
if err != nil {
@@ -291,7 +369,7 @@ func (s *OrganizationsService) AddTeamRepo(ctx context.Context, team int, owner
// from the team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#remove-team-repo
-func (s *OrganizationsService) RemoveTeamRepo(ctx context.Context, team int, owner string, repo string) (*Response, error) {
+func (s *OrganizationsService) RemoveTeamRepo(ctx context.Context, team int64, owner string, repo string) (*Response, error) {
u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@@ -315,6 +393,9 @@ func (s *OrganizationsService) ListUserTeams(ctx context.Context, opt *ListOptio
return nil, nil, err
}
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
+
var teams []*Team
resp, err := s.client.Do(ctx, req, &teams)
if err != nil {
@@ -327,13 +408,15 @@ func (s *OrganizationsService) ListUserTeams(ctx context.Context, opt *ListOptio
// GetTeamMembership returns the membership status for a user in a team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#get-team-membership
-func (s *OrganizationsService) GetTeamMembership(ctx context.Context, team int, user string) (*Membership, *Response, error) {
+func (s *OrganizationsService) GetTeamMembership(ctx context.Context, team int64, user string) (*Membership, *Response, error) {
u := fmt.Sprintf("teams/%v/memberships/%v", team, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
+ req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
+
t := new(Membership)
resp, err := s.client.Do(ctx, req, t)
if err != nil {
@@ -375,7 +458,7 @@ type OrganizationAddTeamMembershipOptions struct {
// added as a member of the team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#add-team-membership
-func (s *OrganizationsService) AddTeamMembership(ctx context.Context, team int, user string, opt *OrganizationAddTeamMembershipOptions) (*Membership, *Response, error) {
+func (s *OrganizationsService) AddTeamMembership(ctx context.Context, team int64, user string, opt *OrganizationAddTeamMembershipOptions) (*Membership, *Response, error) {
u := fmt.Sprintf("teams/%v/memberships/%v", team, user)
req, err := s.client.NewRequest("PUT", u, opt)
if err != nil {
@@ -394,7 +477,7 @@ func (s *OrganizationsService) AddTeamMembership(ctx context.Context, team int,
// RemoveTeamMembership removes a user from a team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#remove-team-membership
-func (s *OrganizationsService) RemoveTeamMembership(ctx context.Context, team int, user string) (*Response, error) {
+func (s *OrganizationsService) RemoveTeamMembership(ctx context.Context, team int64, user string) (*Response, error) {
u := fmt.Sprintf("teams/%v/memberships/%v", team, user)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@@ -409,7 +492,7 @@ func (s *OrganizationsService) RemoveTeamMembership(ctx context.Context, team in
// Preview features are not supported for production use.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations
-func (s *OrganizationsService) ListPendingTeamInvitations(ctx context.Context, team int, opt *ListOptions) ([]*Invitation, *Response, error) {
+func (s *OrganizationsService) ListPendingTeamInvitations(ctx context.Context, team int64, opt *ListOptions) ([]*Invitation, *Response, error) {
u := fmt.Sprintf("teams/%v/invitations", team)
u, err := addOptions(u, opt)
if err != nil {