Skip to content

Commit

Permalink
Merge pull request #124 from xrstf/remove-deprecated-github-functions
Browse files Browse the repository at this point in the history
Remove deprecated GitHub client functions
  • Loading branch information
k8s-ci-robot authored Apr 24, 2024
2 parents a88484d + 8088a9d commit 5f7490e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 288 deletions.
251 changes: 0 additions & 251 deletions pkg/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,15 @@ type RepositoryClient interface {
type TeamClient interface {
CreateTeam(org string, team Team) (*Team, error)
EditTeam(org string, t Team) (*Team, error)
DeleteTeam(org string, id int) error
DeleteTeamBySlug(org, teamSlug string) error
ListTeams(org string) ([]Team, error)
UpdateTeamMembership(org string, id int, user string, maintainer bool) (*TeamMembership, error)
UpdateTeamMembershipBySlug(org, teamSlug, user string, maintainer bool) (*TeamMembership, error)
RemoveTeamMembership(org string, id int, user string) error
RemoveTeamMembershipBySlug(org, teamSlug, user string) error
ListTeamMembers(org string, id int, role string) ([]TeamMember, error)
ListTeamMembersBySlug(org, teamSlug, role string) ([]TeamMember, error)
ListTeamRepos(org string, id int) ([]Repo, error)
ListTeamReposBySlug(org, teamSlug string) ([]Repo, error)
UpdateTeamRepo(id int, org, repo string, permission TeamPermission) error
UpdateTeamRepoBySlug(org, teamSlug, repo string, permission TeamPermission) error
RemoveTeamRepo(id int, org, repo string) error
RemoveTeamRepoBySlug(org, teamSlug, repo string) error
ListTeamInvitations(org string, id int) ([]OrgInvitation, error)
ListTeamInvitationsBySlug(org, teamSlug string) ([]OrgInvitation, error)
TeamHasMember(org string, teamID int, memberLogin string) (bool, error)
TeamBySlugHasMember(org string, teamSlug string, memberLogin string) (bool, error)
Expand Down Expand Up @@ -3600,31 +3593,6 @@ func (c *client) EditTeam(org string, t Team) (*Team, error) {
return &retTeam, err
}

// DeleteTeam removes team.ID from GitHub.
//
// See https://developer.github.com/v3/teams/#delete-team
// Deprecated: please use DeleteTeamBySlug
func (c *client) DeleteTeam(org string, id int) error {
c.logger.WithField("methodName", "DeleteTeam").
Warn("method is deprecated, and will result in multiple api calls to achieve result")
durationLogger := c.log("DeleteTeam", org, id)
defer durationLogger()

organization, err := c.GetOrg(org)
if err != nil {
return err
}

path := fmt.Sprintf("/organizations/%d/team/%d", organization.Id, id)
_, err = c.request(&request{
method: http.MethodDelete,
path: path,
org: org,
exitCodes: []int{204},
}, nil)
return err
}

// DeleteTeamBySlug removes team.Slug from GitHub.
//
// See https://docs.github.com/en/rest/reference/teams#delete-a-team
Expand Down Expand Up @@ -3670,47 +3638,6 @@ func (c *client) ListTeams(org string) ([]Team, error) {
return teams, nil
}

// UpdateTeamMembership adds the user to the team and/or updates their role in that team.
//
// If the user is not a member of the org, GitHub will invite them to become an outside collaborator, setting their status to pending.
//
// https://developer.github.com/v3/teams/members/#add-or-update-team-membership
// Deprecated: please use UpdateTeamMembershipBySlug
func (c *client) UpdateTeamMembership(org string, id int, user string, maintainer bool) (*TeamMembership, error) {
c.logger.WithField("methodName", "UpdateTeamMembership").
Warn("method is deprecated, and will result in multiple api calls to achieve result")
durationLogger := c.log("UpdateTeamMembership", org, id, user, maintainer)
defer durationLogger()

if c.fake {
return nil, nil
}
tm := TeamMembership{}
if maintainer {
tm.Role = RoleMaintainer
} else {
tm.Role = RoleMember
}

if c.dry {
return &tm, nil
}

organization, err := c.GetOrg(org)
if err != nil {
return nil, err
}

_, err = c.request(&request{
method: http.MethodPut,
path: fmt.Sprintf("/organizations/%d/team/%d/memberships/%s", organization.Id, id, user),
org: org,
requestBody: &tm,
exitCodes: []int{200},
}, &tm)
return &tm, err
}

// UpdateTeamMembershipBySlug adds the user to the team and/or updates their role in that team.
//
// If the user is not a member of the org, GitHub will invite them to become an outside collaborator, setting their status to pending.
Expand Down Expand Up @@ -3744,34 +3671,6 @@ func (c *client) UpdateTeamMembershipBySlug(org, teamSlug, user string, maintain
return &tm, err
}

// RemoveTeamMembership removes the user from the team (but not the org).
//
// https://developer.github.com/v3/teams/members/#remove-team-member
// Deprecated: please use RemoveTeamMembershipBySlug
func (c *client) RemoveTeamMembership(org string, id int, user string) error {
c.logger.WithField("methodName", "RemoveTeamMembership").
Warn("method is deprecated, and will result in multiple api calls to achieve result")
durationLogger := c.log("RemoveTeamMembership", org, id, user)
defer durationLogger()

if c.fake {
return nil
}

organization, err := c.GetOrg(org)
if err != nil {
return err
}

_, err = c.request(&request{
method: http.MethodDelete,
path: fmt.Sprintf("/organizations/%d/team/%d/memberships/%s", organization.Id, id, user),
org: org,
exitCodes: []int{204},
}, nil)
return err
}

// RemoveTeamMembershipBySlug removes the user from the team (but not the org).
//
// https://docs.github.com/en/rest/reference/teams#remove-team-membership-for-a-user
Expand Down Expand Up @@ -3864,55 +3763,6 @@ func (c *client) ListTeamMembersBySlug(org, teamSlug, role string) ([]TeamMember
return teamMembers, nil
}

// ListTeamRepos gets a list of team repos for the given team id
//
// https://developer.github.com/v3/teams/#list-team-repos
// Deprecated: please use ListTeamReposBySlug
func (c *client) ListTeamRepos(org string, id int) ([]Repo, error) {
c.logger.WithField("methodName", "ListTeamRepos").
Warn("method is deprecated, and will result in multiple api calls to achieve result")
durationLogger := c.log("ListTeamRepos", org, id)
defer durationLogger()

if c.fake {
return nil, nil
}

organization, err := c.GetOrg(org)
if err != nil {
return nil, err
}

path := fmt.Sprintf("/organizations/%d/team/%d/repos", organization.Id, id)
var repos []Repo
err = c.readPaginatedResultsWithValues(
path,
url.Values{
"per_page": []string{"100"},
},
"application/vnd.github+json",
org,
func() interface{} {
return &[]Repo{}
},
func(obj interface{}) {
for _, repo := range *obj.(*[]Repo) {
// Currently, GitHub API returns false for all permission levels
// for a repo on which the team has 'Maintain' or 'Triage' role.
// This check is to avoid listing a repo under the team but
// showing the permission level as none.
if LevelFromPermissions(repo.Permissions) != None {
repos = append(repos, repo)
}
}
},
)
if err != nil {
return nil, err
}
return repos, nil
}

// ListTeamReposBySlug gets a list of team repos for the given team slug
//
// https://docs.github.com/en/rest/reference/teams#list-team-repositories
Expand Down Expand Up @@ -3953,41 +3803,6 @@ func (c *client) ListTeamReposBySlug(org, teamSlug string) ([]Repo, error) {
return repos, nil
}

// UpdateTeamRepo adds the repo to the team with the provided role.
//
// https://developer.github.com/v3/teams/#add-or-update-team-repository
// Deprecated: please use UpdateTeamRepoBySlug
func (c *client) UpdateTeamRepo(id int, org, repo string, permission TeamPermission) error {
c.logger.WithField("methodName", "UpdateTeamRepo").
Warn("method is deprecated, and will result in multiple api calls to achieve result")
durationLogger := c.log("UpdateTeamRepo", id, org, repo, permission)
defer durationLogger()

if c.fake || c.dry {
return nil
}

organization, err := c.GetOrg(org)
if err != nil {
return err
}

data := struct {
Permission string `json:"permission"`
}{
Permission: string(permission),
}

_, err = c.request(&request{
method: http.MethodPut,
path: fmt.Sprintf("/organizations/%d/team/%d/repos/%s/%s", organization.Id, id, org, repo),
org: org,
requestBody: &data,
exitCodes: []int{204},
}, nil)
return err
}

// UpdateTeamRepoBySlug adds the repo to the team with the provided role.
//
// https://docs.github.com/en/rest/reference/teams#add-or-update-team-repository-permissions
Expand Down Expand Up @@ -4015,34 +3830,6 @@ func (c *client) UpdateTeamRepoBySlug(org, teamSlug, repo string, permission Tea
return err
}

// RemoveTeamRepo removes the team from the repo.
//
// https://docs.github.com/en/rest/reference/teams#remove-a-repository-from-a-team-legacy
// Deprecated: please use RemoveTeamRepoBySlug
func (c *client) RemoveTeamRepo(id int, org, repo string) error {
c.logger.WithField("methodName", "RemoveTeamRepo").
Warn("method is deprecated, and will result in multiple api calls to achieve result")
durationLogger := c.log("RemoveTeamRepo", id, org, repo)
defer durationLogger()

if c.fake || c.dry {
return nil
}

organization, err := c.GetOrg(org)
if err != nil {
return err
}

_, err = c.request(&request{
method: http.MethodDelete,
path: fmt.Sprintf("/organizations/%d/team/%d/repos/%s/%s", organization.Id, id, org, repo),
org: org,
exitCodes: []int{204},
}, nil)
return err
}

// RemoveTeamRepoBySlug removes the team from the repo.
//
// https://docs.github.com/en/rest/reference/teams#remove-a-repository-from-a-team
Expand All @@ -4063,44 +3850,6 @@ func (c *client) RemoveTeamRepoBySlug(org, teamSlug, repo string) error {
return err
}

// ListTeamInvitations gets a list of team members with pending invitations for the
// given team id
//
// https://developer.github.com/v3/teams/members/#list-pending-team-invitations
// Deprecated: please use ListTeamInvitationsBySlug
func (c *client) ListTeamInvitations(org string, id int) ([]OrgInvitation, error) {
c.logger.WithField("methodName", "ListTeamInvitations").
Warn("method is deprecated, and will result in multiple api calls to achieve result")
durationLogger := c.log("ListTeamInvitations", org, id)
defer durationLogger()

if c.fake {
return nil, nil
}

organization, err := c.GetOrg(org)
if err != nil {
return nil, err
}
path := fmt.Sprintf("/organizations/%d/team/%d/invitations", organization.Id, id)
var ret []OrgInvitation
err = c.readPaginatedResults(
path,
acceptNone,
org,
func() interface{} {
return &[]OrgInvitation{}
},
func(obj interface{}) {
ret = append(ret, *(obj.(*[]OrgInvitation))...)
},
)
if err != nil {
return nil, err
}
return ret, nil
}

// ListTeamInvitationsBySlug gets a list of team members with pending invitations for the given team slug
//
// https://docs.github.com/en/rest/reference/teams#list-pending-team-invitations
Expand Down
37 changes: 0 additions & 37 deletions pkg/github/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2895,43 +2895,6 @@ func TestAuthHeaderGetsSet(t *testing.T) {
}
}

func TestListTeamRepos(t *testing.T) {
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("Bad method: %s", r.Method)
}

var result interface{}
switch r.URL.Path {
case "/organizations/1/team/1/repos":
result = []Repo{
{Name: "repo-bar", Permissions: RepoPermissions{Pull: true}},
{Name: "repo-invalid-permission-level"}}
case "/orgs/orgName":
result = Organization{Login: "orgName", Id: 1}
default:
t.Errorf("Bad request path: %s", r.URL.Path)
return
}

b, err := json.Marshal(result)
if err != nil {
t.Fatalf("Didn't expect error: %v", err)
}
fmt.Fprint(w, string(b))
}))
defer ts.Close()
c := getClient(ts.URL)
repos, err := c.ListTeamRepos("orgName", 1)
if err != nil {
t.Errorf("Didn't expect error: %v", err)
} else if len(repos) != 1 {
t.Errorf("Expected one repo, found %d: %v", len(repos), repos)
} else if repos[0].Name != "repo-bar" {
t.Errorf("Wrong repos: %v", repos)
}
}

func TestListTeamReposBySlug(t *testing.T) {
ts := simpleTestServer(t, "/orgs/orgName/teams/team-name/repos", []Repo{
{Name: "repo-bar", Permissions: RepoPermissions{Pull: true}},
Expand Down

0 comments on commit 5f7490e

Please sign in to comment.