Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to go-github v29.0.3 #369

Merged
merged 7 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions github/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {

type Organization struct {
name string
id int64
client *github.Client
StopContext context.Context
}
Expand All @@ -48,12 +49,6 @@ func (c *Config) Client() (interface{}, error) {
return nil, fmt.Errorf("If `individual` is false, `organization` is required.")
}

if c.Individual {
org.name = ""
} else {
org.name = c.Organization
}

// Either run as anonymous, or run with a Token
if c.Token != "" && c.Anonymous {
return nil, fmt.Errorf("If `anonymous` is true, `token` cannot be set.")
Expand Down Expand Up @@ -89,6 +84,18 @@ func (c *Config) Client() (interface{}, error) {
org.client.BaseURL = u
}

if c.Individual {
org.name = ""
} else {
org.name = c.Organization

remoteOrg, _, err := org.client.Organizations.Get(ctx, org.name)
if err != nil {
return nil, err
}
org.id = remoteOrg.GetID()
}

return &org, nil
}

Expand Down
24 changes: 21 additions & 3 deletions github/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error {
}

func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
err := checkOrganization(meta)
if err != nil {
return err
}

client := meta.(*Organization).client
orgId := meta.(*Organization).id

id, err := strconv.ParseInt(d.Id(), 10, 64)
if err != nil {
Expand All @@ -110,7 +116,7 @@ func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
}

log.Printf("[DEBUG] Reading team: %s", d.Id())
team, resp, err := client.Teams.GetTeam(ctx, id)
team, resp, err := client.Teams.GetTeamByID(ctx, orgId, id)
if err != nil {
if ghErr, ok := err.(*github.ErrorResponse); ok {
if ghErr.Response.StatusCode == http.StatusNotModified {
Expand Down Expand Up @@ -142,7 +148,13 @@ func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
}

func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error {
err := checkOrganization(meta)
if err != nil {
return err
}

client := meta.(*Organization).client
orgId := meta.(*Organization).id

editedTeam := github.NewTeam{
Name: d.Get("name").(string),
Expand All @@ -161,7 +173,7 @@ func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error {
ctx := context.WithValue(context.Background(), ctxId, d.Id())

log.Printf("[DEBUG] Updating team: %s", d.Id())
team, _, err := client.Teams.EditTeam(ctx, teamId, editedTeam, false)
team, _, err := client.Teams.EditTeamByID(ctx, orgId, teamId, editedTeam, false)
if err != nil {
return err
}
Expand All @@ -182,7 +194,13 @@ func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error {
}

func resourceGithubTeamDelete(d *schema.ResourceData, meta interface{}) error {
err := checkOrganization(meta)
if err != nil {
return err
}

client := meta.(*Organization).client
orgId := meta.(*Organization).id

id, err := strconv.ParseInt(d.Id(), 10, 64)
if err != nil {
Expand All @@ -191,6 +209,6 @@ func resourceGithubTeamDelete(d *schema.ResourceData, meta interface{}) error {
ctx := context.WithValue(context.Background(), ctxId, d.Id())

log.Printf("[DEBUG] Deleting team: %s", d.Id())
_, err = client.Teams.DeleteTeam(ctx, id)
_, err = client.Teams.DeleteTeamByID(ctx, orgId, id)
return err
}
15 changes: 10 additions & 5 deletions github/resource_github_team_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func resourceGithubTeamRepositoryCreate(d *schema.ResourceData, meta interface{}
}

client := meta.(*Organization).client
orgId := meta.(*Organization).id

teamIdString := d.Get("team_id").(string)
teamId, err := strconv.ParseInt(teamIdString, 10, 64)
Expand All @@ -66,7 +67,8 @@ func resourceGithubTeamRepositoryCreate(d *schema.ResourceData, meta interface{}

log.Printf("[DEBUG] Creating team repository association: %s:%s (%s/%s)",
teamIdString, permission, orgName, repoName)
_, err = client.Teams.AddTeamRepo(ctx,
_, err = client.Teams.AddTeamRepoByID(ctx,
orgId,
teamId,
orgName,
repoName,
Expand All @@ -91,6 +93,7 @@ func resourceGithubTeamRepositoryRead(d *schema.ResourceData, meta interface{})
}

client := meta.(*Organization).client
orgId := meta.(*Organization).id

teamIdString, repoName, err := parseTwoPartID(d.Id(), "team_id", "repository")
if err != nil {
Expand All @@ -108,7 +111,7 @@ func resourceGithubTeamRepositoryRead(d *schema.ResourceData, meta interface{})
}

log.Printf("[DEBUG] Reading team repository association: %s (%s/%s)", teamIdString, orgName, repoName)
repo, resp, repoErr := client.Teams.IsTeamRepo(ctx, teamId, orgName, repoName)
repo, resp, repoErr := client.Teams.IsTeamRepoByID(ctx, orgId, teamId, orgName, repoName)
if repoErr != nil {
if ghErr, ok := repoErr.(*github.ErrorResponse); ok {
if ghErr.Response.StatusCode == http.StatusNotModified {
Expand Down Expand Up @@ -145,6 +148,7 @@ func resourceGithubTeamRepositoryUpdate(d *schema.ResourceData, meta interface{}
}

client := meta.(*Organization).client
orgId := meta.(*Organization).id

teamIdString := d.Get("team_id").(string)
teamId, err := strconv.ParseInt(teamIdString, 10, 64)
Expand All @@ -159,7 +163,8 @@ func resourceGithubTeamRepositoryUpdate(d *schema.ResourceData, meta interface{}
log.Printf("[DEBUG] Updating team repository association: %s:%s (%s/%s)",
teamIdString, permission, orgName, repoName)
// the go-github library's AddTeamRepo method uses the add/update endpoint from Github API
_, err = client.Teams.AddTeamRepo(ctx,
_, err = client.Teams.AddTeamRepoByID(ctx,
orgId,
teamId,
orgName,
repoName,
Expand All @@ -183,6 +188,7 @@ func resourceGithubTeamRepositoryDelete(d *schema.ResourceData, meta interface{}
}

client := meta.(*Organization).client
orgId := meta.(*Organization).id

teamIdString := d.Get("team_id").(string)

Expand All @@ -196,7 +202,6 @@ func resourceGithubTeamRepositoryDelete(d *schema.ResourceData, meta interface{}

log.Printf("[DEBUG] Deleting team repository association: %s (%s/%s)",
teamIdString, orgName, repoName)
_, err = client.Teams.RemoveTeamRepo(ctx,
teamId, orgName, repoName)
_, err = client.Teams.RemoveTeamRepoByID(ctx, orgId, teamId, orgName, repoName)
return err
}
7 changes: 5 additions & 2 deletions github/resource_github_team_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ func testAccCheckGithubTeamRepositoryExists(n string, repository *github.Reposit
return unconvertibleIdErr(teamIdString, err)
}

repo, _, err := conn.Teams.IsTeamRepo(context.TODO(),
repo, _, err := conn.Teams.IsTeamRepoByID(context.TODO(),
testAccProvider.Meta().(*Organization).id,
teamId,
testAccProvider.Meta().(*Organization).name,
repoName)
Expand All @@ -137,6 +138,7 @@ func testAccCheckGithubTeamRepositoryExists(n string, repository *github.Reposit

func testAccCheckGithubTeamRepositoryDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*Organization).client
orgId := testAccProvider.Meta().(*Organization).id

for _, rs := range s.RootModule().Resources {
if rs.Type != "github_team_repository" {
Expand All @@ -152,7 +154,8 @@ func testAccCheckGithubTeamRepositoryDestroy(s *terraform.State) error {
return unconvertibleIdErr(teamIdString, err)
}

repo, resp, err := conn.Teams.IsTeamRepo(context.TODO(),
repo, resp, err := conn.Teams.IsTeamRepoByID(context.TODO(),
orgId,
teamId,
testAccProvider.Meta().(*Organization).name,
repoName)
Expand Down
5 changes: 3 additions & 2 deletions github/resource_github_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func testAccCheckGithubTeamExists(n string, team *github.Team) resource.TestChec
return unconvertibleIdErr(rs.Primary.ID, err)
}

githubTeam, _, err := conn.Teams.GetTeam(context.TODO(), id)
githubTeam, _, err := conn.Teams.GetTeamByID(context.TODO(), testAccProvider.Meta().(*Organization).id, id)
if err != nil {
return err
}
Expand Down Expand Up @@ -179,6 +179,7 @@ func testAccCheckGithubTeamAttributes(team *github.Team, name, description strin

func testAccCheckGithubTeamDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*Organization).client
orgId := testAccProvider.Meta().(*Organization).id

for _, rs := range s.RootModule().Resources {
if rs.Type != "github_team" {
Expand All @@ -190,7 +191,7 @@ func testAccCheckGithubTeamDestroy(s *terraform.State) error {
return unconvertibleIdErr(rs.Primary.ID, err)
}

team, resp, err := conn.Teams.GetTeam(context.TODO(), id)
team, resp, err := conn.Teams.GetTeamByID(context.TODO(), orgId, id)
if err == nil {
teamId := strconv.FormatInt(*team.ID, 10)
if team != nil && teamId == rs.Primary.ID {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/terraform-providers/terraform-provider-github

require (
github.com/google/go-github/v29 v29.0.2
github.com/google/go-github/v29 v29.0.3
github.com/hashicorp/terraform-plugin-sdk v1.7.0
github.com/kylelemons/godebug v1.1.0
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-github/v29 v29.0.2 h1:opYN6Wc7DOz7Ku3Oh4l7prmkOMwEcQxpFtxdU8N8Pts=
github.com/google/go-github/v29 v29.0.2/go.mod h1:CHKiKKPHJ0REzfwc14QMklvtHwCveD0PxlMjLlzAM5E=
github.com/google/go-github/v29 v29.0.3 h1:IktKCTwU//aFHnpA+2SLIi7Oo9uhAzgsdZNbcAqhgdc=
github.com/google/go-github/v29 v29.0.3/go.mod h1:CHKiKKPHJ0REzfwc14QMklvtHwCveD0PxlMjLlzAM5E=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
Expand Down
12 changes: 12 additions & 0 deletions vendor/github.com/google/go-github/v29/github/actions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 132 additions & 0 deletions vendor/github.com/google/go-github/v29/github/actions_secrets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading