Skip to content

Commit

Permalink
use getteambyslug instead of listteams in team data source (integrati…
Browse files Browse the repository at this point in the history
  • Loading branch information
k24dizzle authored Nov 13, 2020
1 parent 25499bf commit c197587
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions github/data_source_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package github

import (
"context"
"fmt"
"log"
"strconv"

"github.com/google/go-github/v32/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

Expand Down Expand Up @@ -56,7 +54,7 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
orgId := meta.(*Owner).id
ctx := context.Background()

team, err := getGithubTeamBySlug(ctx, client, meta.(*Owner).name, slug)
team, _, err := client.Teams.GetTeamBySlug(ctx, meta.(*Owner).name, slug)
if err != nil {
return err
}
Expand All @@ -81,26 +79,3 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {

return nil
}

func getGithubTeamBySlug(ctx context.Context, client *github.Client, org string, slug string) (team *github.Team, err error) {
opt := &github.ListOptions{PerPage: 10}
for {
teams, resp, err := client.Teams.ListTeams(ctx, org, opt)
if err != nil {
return team, err
}

for _, t := range teams {
if *t.Slug == slug {
return t, nil
}
}

if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}

return team, fmt.Errorf("Could not find team with slug: %s", slug)
}

0 comments on commit c197587

Please sign in to comment.