From f471d2c16bd844335fc9ce273c3ace90c5cfa082 Mon Sep 17 00:00:00 2001 From: Eliasz Slusarczyk Date: Sat, 19 May 2018 20:23:59 +0100 Subject: [PATCH 01/11] Rename organization type struct to owner --- github/config.go | 37 +++++++++---------- github/data_source_github_collaborators.go | 2 +- github/data_source_github_ip_ranges.go | 4 +- github/data_source_github_repositories.go | 2 +- github/data_source_github_repository.go | 4 +- github/data_source_github_team.go | 8 ++-- github/data_source_github_user.go | 2 +- github/provider.go | 14 +++---- github/provider_test.go | 4 +- github/resource_github_branch_protection.go | 24 ++++++------ .../resource_github_branch_protection_test.go | 8 ++-- github/resource_github_issue_label.go | 12 +++--- github/resource_github_issue_label_test.go | 8 ++-- github/resource_github_membership.go | 12 +++--- github/resource_github_membership_test.go | 6 +-- .../resource_github_organization_project.go | 16 ++++---- .../resource_github_organization_webhook.go | 16 ++++---- ...source_github_organization_webhook_test.go | 12 +++--- github/resource_github_project_column.go | 10 ++--- github/resource_github_repository.go | 16 ++++---- ...resource_github_repository_collaborator.go | 12 +++--- ...rce_github_repository_collaborator_test.go | 12 +++--- .../resource_github_repository_deploy_key.go | 12 +++--- ...ource_github_repository_deploy_key_test.go | 8 ++-- github/resource_github_repository_project.go | 12 +++--- github/resource_github_repository_test.go | 32 ++++++++-------- github/resource_github_repository_webhook.go | 16 ++++---- ...resource_github_repository_webhook_test.go | 12 +++--- github/resource_github_team.go | 10 ++--- github/resource_github_team_membership.go | 6 +-- .../resource_github_team_membership_test.go | 6 +-- github/resource_github_team_repository.go | 16 ++++---- .../resource_github_team_repository_test.go | 8 ++-- github/resource_github_team_test.go | 4 +- github/resource_github_user_gpg_key.go | 6 +-- ...esource_github_user_invitation_accepter.go | 2 +- github/resource_github_user_ssh_key.go | 6 +-- github/resource_organization_block.go | 12 +++--- github/sweeper_test.go | 10 ++--- github/util.go | 2 +- go.mod | 4 +- go.sum | 2 + 42 files changed, 214 insertions(+), 213 deletions(-) diff --git a/github/config.go b/github/config.go index b1637fef32..350c9d13d8 100644 --- a/github/config.go +++ b/github/config.go @@ -13,15 +13,15 @@ import ( ) type Config struct { - Token string - Organization string - BaseURL string - Insecure bool - Individual bool - Anonymous bool + Token string + Owner string + BaseURL string + Insecure bool + Individual bool + Anonymous bool } -type Organization struct { +type Owner struct { name string client *github.Client StopContext context.Context @@ -29,7 +29,7 @@ type Organization struct { // Client configures and returns a fully initialized GithubClient func (c *Config) Client() (interface{}, error) { - var org Organization + var owner Owner var ts oauth2.TokenSource var tc *http.Client @@ -40,18 +40,16 @@ func (c *Config) Client() (interface{}, error) { ctx = context.WithValue(ctx, oauth2.HTTPClient, insecureClient) } - // Either Organization needs to be set, or Individual needs to be true - if c.Organization != "" && c.Individual { - return nil, fmt.Errorf("If `individual` is true, `organization` cannot be set.") + // Either Owner needs to be set, or Individual needs to be true + if c.Owner != "" && c.Individual { + return nil, fmt.Errorf("If `individual` is true, `owner` cannot be set.") } - if c.Organization == "" && !c.Individual { - return nil, fmt.Errorf("If `individual` is false, `organization` is required.") + if c.Owner == "" && !c.Individual { + return nil, fmt.Errorf("If `individual` is false, `owner` is required.") } if c.Individual { - org.name = "" - } else { - org.name = c.Organization + owner.name = "" } // Either run as anonymous, or run with a Token @@ -79,17 +77,16 @@ func (c *Config) Client() (interface{}, error) { tc.Transport = NewRateLimitTransport(tc.Transport) tc.Transport = logging.NewTransport("Github", tc.Transport) - org.client = github.NewClient(tc) - + owner.client = github.NewClient(tc) if c.BaseURL != "" { u, err := url.Parse(c.BaseURL) if err != nil { return nil, err } - org.client.BaseURL = u + owner.client.BaseURL = u } - return &org, nil + return &owner, nil } func insecureHttpClient() *http.Client { diff --git a/github/data_source_github_collaborators.go b/github/data_source_github_collaborators.go index 782b5d10e3..b6a2fec6ca 100644 --- a/github/data_source_github_collaborators.go +++ b/github/data_source_github_collaborators.go @@ -110,7 +110,7 @@ func dataSourceGithubCollaborators() *schema.Resource { func dataSourceGithubCollaboratorsRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client ctx := context.Background() owner := d.Get("owner").(string) diff --git a/github/data_source_github_ip_ranges.go b/github/data_source_github_ip_ranges.go index 6bf25914c2..7487d30d87 100644 --- a/github/data_source_github_ip_ranges.go +++ b/github/data_source_github_ip_ranges.go @@ -34,9 +34,9 @@ func dataSourceGithubIpRanges() *schema.Resource { } func dataSourceGithubIpRangesRead(d *schema.ResourceData, meta interface{}) error { - org := meta.(*Organization) + owner := meta.(*Owner) - api, _, err := org.client.APIMeta(org.StopContext) + api, _, err := owner.client.APIMeta(owner.StopContext) if err != nil { return err } diff --git a/github/data_source_github_repositories.go b/github/data_source_github_repositories.go index 1123667064..f913644363 100644 --- a/github/data_source_github_repositories.go +++ b/github/data_source_github_repositories.go @@ -48,7 +48,7 @@ func dataSourceGithubRepositoriesRead(d *schema.ResourceData, meta interface{}) return err } - client := meta.(*Organization).client + client := meta.(*Owner).client query := d.Get("query").(string) opt := &github.SearchOptions{ diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index a463da2f28..6221676a9e 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -108,8 +108,8 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er return err } - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name var repoName string if fullName, ok := d.GetOk("full_name"); ok { diff --git a/github/data_source_github_team.go b/github/data_source_github_team.go index 3e0568a30a..b16fc16891 100644 --- a/github/data_source_github_team.go +++ b/github/data_source_github_team.go @@ -48,10 +48,10 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error { slug := d.Get("slug").(string) log.Printf("[INFO] Refreshing GitHub Team: %s", slug) - client := meta.(*Organization).client + client := meta.(*Owner).client ctx := context.Background() - team, err := getGithubTeamBySlug(ctx, client, meta.(*Organization).name, slug) + team, err := getGithubTeamBySlug(ctx, client, meta.(*Owner).name, slug) if err != nil { return err } @@ -76,10 +76,10 @@ 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) { +func getGithubTeamBySlug(ctx context.Context, client *github.Client, owner string, slug string) (team *github.Team, err error) { opt := &github.ListOptions{PerPage: 10} for { - teams, resp, err := client.Teams.ListTeams(ctx, org, opt) + teams, resp, err := client.Teams.ListTeams(ctx, owner, opt) if err != nil { return team, err } diff --git a/github/data_source_github_user.go b/github/data_source_github_user.go index 11b3104cb9..516483b3f8 100644 --- a/github/data_source_github_user.go +++ b/github/data_source_github_user.go @@ -99,7 +99,7 @@ func dataSourceGithubUserRead(d *schema.ResourceData, meta interface{}) error { username := d.Get("username").(string) log.Printf("[INFO] Refreshing GitHub User: %s", username) - client := meta.(*Organization).client + client := meta.(*Owner).client ctx := context.Background() user, _, err := client.Users.Get(ctx, username) diff --git a/github/provider.go b/github/provider.go index 4e317af53b..eb487bc751 100644 --- a/github/provider.go +++ b/github/provider.go @@ -14,11 +14,11 @@ func Provider() terraform.ResourceProvider { DefaultFunc: schema.EnvDefaultFunc("GITHUB_TOKEN", nil), Description: descriptions["token"], }, - "organization": { + "owner": { Type: schema.TypeString, Optional: true, - DefaultFunc: schema.EnvDefaultFunc("GITHUB_ORGANIZATION", nil), - Description: descriptions["organization"], + DefaultFunc: schema.EnvDefaultFunc("GITHUB_OWNER", nil), + Description: descriptions["owner"], }, "base_url": { Type: schema.TypeString, @@ -88,8 +88,8 @@ func init() { "token": "The OAuth token used to connect to GitHub. " + "If `anonymous` is false, `token` is required.", - "organization": "The GitHub organization name to manage. " + - "If `individual` is false, `organization` is required.", + "owner": "The GitHub owner name to manage. " + + "If `individual` is false, owner is required.", "base_url": "The GitHub Base API URL", @@ -110,7 +110,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc { return func(d *schema.ResourceData) (interface{}, error) { config := Config{ Token: d.Get("token").(string), - Organization: d.Get("organization").(string), + Owner: d.Get("organization").(string), BaseURL: d.Get("base_url").(string), Insecure: d.Get("insecure").(bool), Individual: d.Get("individual").(bool), @@ -122,7 +122,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc { return nil, err } - meta.(*Organization).StopContext = p.StopContext() + meta.(*Owner).StopContext = p.StopContext() return meta, nil } diff --git a/github/provider_test.go b/github/provider_test.go index b97f87f646..35f3e6fd59 100644 --- a/github/provider_test.go +++ b/github/provider_test.go @@ -55,8 +55,8 @@ func testAccPreCheck(t *testing.T) { if v := os.Getenv("GITHUB_TOKEN"); v == "" { t.Fatal("GITHUB_TOKEN must be set for acceptance tests") } - if v := os.Getenv("GITHUB_ORGANIZATION"); v == "" { - t.Fatal("GITHUB_ORGANIZATION must be set for acceptance tests") + if v := os.Getenv("GITHUB_OWNER"); v == "" { + t.Fatal("GITHUB_OWNER must be set for acceptance tests") } if v := os.Getenv("GITHUB_TEST_USER"); v == "" { t.Fatal("GITHUB_TEST_USER must be set for acceptance tests") diff --git a/github/resource_github_branch_protection.go b/github/resource_github_branch_protection.go index 28f6cf54b3..fef78b8673 100644 --- a/github/resource_github_branch_protection.go +++ b/github/resource_github_branch_protection.go @@ -150,9 +150,9 @@ func resourceGithubBranchProtectionCreate(d *schema.ResourceData, meta interface return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) branch := d.Get("branch").(string) @@ -193,13 +193,13 @@ func resourceGithubBranchProtectionRead(d *schema.ResourceData, meta interface{} return err } - client := meta.(*Organization).client + client := meta.(*Owner).client repoName, branch, err := parseTwoPartID(d.Id()) if err != nil { return err } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) if !d.IsNewResource() { @@ -259,7 +259,7 @@ func resourceGithubBranchProtectionUpdate(d *schema.ResourceData, meta interface return err } - client := meta.(*Organization).client + client := meta.(*Owner).client repoName, branch, err := parseTwoPartID(d.Id()) if err != nil { return err @@ -270,7 +270,7 @@ func resourceGithubBranchProtectionUpdate(d *schema.ResourceData, meta interface return err } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) log.Printf("[DEBUG] Updating branch protection: %s/%s (%s)", @@ -315,13 +315,13 @@ func resourceGithubBranchProtectionDelete(d *schema.ResourceData, meta interface return err } - client := meta.(*Organization).client + client := meta.(*Owner).client repoName, branch, err := parseTwoPartID(d.Id()) if err != nil { return err } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) log.Printf("[DEBUG] Deleting branch protection: %s/%s (%s)", orgName, repoName, branch) @@ -376,13 +376,13 @@ func flattenAndSetRequiredStatusChecks(d *schema.ResourceData, protection *githu } func requireSignedCommitsRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client repoName, branch, err := parseTwoPartID(d.Id()) if err != nil { return err } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) if !d.IsNewResource() { @@ -402,13 +402,13 @@ func requireSignedCommitsRead(d *schema.ResourceData, meta interface{}) error { func requireSignedCommitsUpdate(d *schema.ResourceData, meta interface{}) (err error) { requiredSignedCommit := d.Get("require_signed_commits").(bool) - client := meta.(*Organization).client + client := meta.(*Owner).client repoName, branch, err := parseTwoPartID(d.Id()) if err != nil { return err } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) if !d.IsNewResource() { diff --git a/github/resource_github_branch_protection_test.go b/github/resource_github_branch_protection_test.go index 69767fa0ff..63620f15dc 100644 --- a/github/resource_github_branch_protection_test.go +++ b/github/resource_github_branch_protection_test.go @@ -236,8 +236,8 @@ func testAccCheckGithubProtectedBranchExists(n, id string, protection *github.Pr return fmt.Errorf("Expected ID to be %v, got %v", id, rs.Primary.ID) } - conn := testAccProvider.Meta().(*Organization).client - o := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).client + o := testAccProvider.Meta().(*Owner).name r, b, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err @@ -360,14 +360,14 @@ func testAccCheckGithubBranchProtectionNoPullRequestReviewsExist(protection *git } func testAccGithubBranchProtectionDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_branch_protection" { continue } - o := testAccProvider.Meta().(*Organization).name + o := testAccProvider.Meta().(*Owner).name r, b, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err diff --git a/github/resource_github_issue_label.go b/github/resource_github_issue_label.go index a1d55ec480..2fbf0e6038 100644 --- a/github/resource_github_issue_label.go +++ b/github/resource_github_issue_label.go @@ -65,8 +65,8 @@ func resourceGithubIssueLabelCreateOrUpdate(d *schema.ResourceData, meta interfa return err } - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) name := d.Get("name").(string) color := d.Get("color").(string) @@ -140,13 +140,13 @@ func resourceGithubIssueLabelRead(d *schema.ResourceData, meta interface{}) erro return err } - client := meta.(*Organization).client + client := meta.(*Owner).client repoName, name, err := parseTwoPartID(d.Id()) if err != nil { return err } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) if !d.IsNewResource() { ctx = context.WithValue(ctx, ctxEtag, d.Get("etag").(string)) @@ -186,9 +186,9 @@ func resourceGithubIssueLabelDelete(d *schema.ResourceData, meta interface{}) er return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) name := d.Get("name").(string) ctx := context.WithValue(context.Background(), ctxId, d.Id()) diff --git a/github/resource_github_issue_label_test.go b/github/resource_github_issue_label_test.go index f0056a14f7..bb841de61b 100644 --- a/github/resource_github_issue_label_test.go +++ b/github/resource_github_issue_label_test.go @@ -136,8 +136,8 @@ func testAccCheckGithubIssueLabelExists(n string, label *github.Label) resource. return fmt.Errorf("No issue label ID is set") } - conn := testAccProvider.Meta().(*Organization).client - orgName := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).client + orgName := testAccProvider.Meta().(*Owner).name repoName, name, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err @@ -169,14 +169,14 @@ func testAccCheckGithubIssueLabelAttributes(label *github.Label, name, color str } func testAccGithubIssueLabelDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_issue_label" { continue } - orgName := testAccProvider.Meta().(*Organization).name + orgName := testAccProvider.Meta().(*Owner).name repoName, name, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err diff --git a/github/resource_github_membership.go b/github/resource_github_membership.go index 317b85a7b7..7103ba08ce 100644 --- a/github/resource_github_membership.go +++ b/github/resource_github_membership.go @@ -46,9 +46,9 @@ func resourceGithubMembershipCreateOrUpdate(d *schema.ResourceData, meta interfa return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name username := d.Get("username").(string) roleName := d.Get("role").(string) ctx := context.Background() @@ -79,9 +79,9 @@ func resourceGithubMembershipRead(d *schema.ResourceData, meta interface{}) erro return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name _, username, err := parseTwoPartID(d.Id()) if err != nil { return err @@ -122,8 +122,8 @@ func resourceGithubMembershipDelete(d *schema.ResourceData, meta interface{}) er return err } - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) log.Printf("[DEBUG] Deleting membership: %s", d.Id()) diff --git a/github/resource_github_membership_test.go b/github/resource_github_membership_test.go index 6edbe13e08..5620c48ba4 100644 --- a/github/resource_github_membership_test.go +++ b/github/resource_github_membership_test.go @@ -84,7 +84,7 @@ func TestAccGithubMembership_caseInsensitive(t *testing.T) { } func testAccCheckGithubMembershipDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_membership" { @@ -122,7 +122,7 @@ func testAccCheckGithubMembershipExists(n string, membership *github.Membership) return fmt.Errorf("No membership ID is set") } - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client orgName, username, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err @@ -148,7 +148,7 @@ func testAccCheckGithubMembershipRoleState(n string, membership *github.Membersh return fmt.Errorf("No membership ID is set") } - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client orgName, username, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err diff --git a/github/resource_github_organization_project.go b/github/resource_github_organization_project.go index 2be831b728..5ccdd8500d 100644 --- a/github/resource_github_organization_project.go +++ b/github/resource_github_organization_project.go @@ -48,8 +48,8 @@ func resourceGithubOrganizationProjectCreate(d *schema.ResourceData, meta interf return err } - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name name := d.Get("name").(string) body := d.Get("body").(string) ctx := context.Background() @@ -76,8 +76,8 @@ func resourceGithubOrganizationProjectRead(d *schema.ResourceData, meta interfac return err } - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name projectID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -120,8 +120,8 @@ func resourceGithubOrganizationProjectUpdate(d *schema.ResourceData, meta interf return err } - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name name := d.Get("name").(string) body := d.Get("body").(string) @@ -151,8 +151,8 @@ func resourceGithubOrganizationProjectDelete(d *schema.ResourceData, meta interf return err } - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name projectID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { return err diff --git a/github/resource_github_organization_webhook.go b/github/resource_github_organization_webhook.go index 98baa3e4c4..dd89780cba 100644 --- a/github/resource_github_organization_webhook.go +++ b/github/resource_github_organization_webhook.go @@ -78,9 +78,9 @@ func resourceGithubOrganizationWebhookCreate(d *schema.ResourceData, meta interf return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name webhookObj := resourceGithubOrganizationWebhookObject(d) ctx := context.Background() @@ -109,9 +109,9 @@ func resourceGithubOrganizationWebhookRead(d *schema.ResourceData, meta interfac return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name hookID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { return unconvertibleIdErr(d.Id(), err) @@ -166,9 +166,9 @@ func resourceGithubOrganizationWebhookUpdate(d *schema.ResourceData, meta interf return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name webhookObj := resourceGithubOrganizationWebhookObject(d) hookID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -193,9 +193,9 @@ func resourceGithubOrganizationWebhookDelete(d *schema.ResourceData, meta interf return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name hookID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { return unconvertibleIdErr(d.Id(), err) diff --git a/github/resource_github_organization_webhook_test.go b/github/resource_github_organization_webhook_test.go index 291753b93e..5e58d0a6ef 100644 --- a/github/resource_github_organization_webhook_test.go +++ b/github/resource_github_organization_webhook_test.go @@ -91,9 +91,9 @@ func testAccCheckGithubOrganizationWebhookExists(n string, hook *github.Hook) re return fmt.Errorf("No repository name is set") } - org := testAccProvider.Meta().(*Organization) - conn := org.client - getHook, _, err := conn.Organizations.GetHook(context.TODO(), org.name, hookID) + owner := testAccProvider.Meta().(*Owner) + conn := owner.client + getHook, _, err := conn.Organizations.GetHook(context.TODO(), owner.name, hookID) if err != nil { return err } @@ -144,8 +144,8 @@ func testAccCheckGithubOrganizationWebhookSecret(r, secret string) resource.Test } func testAccCheckGithubOrganizationWebhookDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client - orgName := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).client + ownerName := testAccProvider.Meta().(*Owner).name for _, rs := range s.RootModule().Resources { if rs.Type != "github_organization_webhook" { @@ -157,7 +157,7 @@ func testAccCheckGithubOrganizationWebhookDestroy(s *terraform.State) error { return unconvertibleIdErr(rs.Primary.ID, err) } - gotHook, resp, err := conn.Organizations.GetHook(context.TODO(), orgName, id) + gotHook, resp, err := conn.Organizations.GetHook(context.TODO(), ownerName, id) if err == nil { if gotHook != nil && *gotHook.ID == id { return fmt.Errorf("Webhook still exists") diff --git a/github/resource_github_project_column.go b/github/resource_github_project_column.go index 7c6242f35d..a34231cab4 100644 --- a/github/resource_github_project_column.go +++ b/github/resource_github_project_column.go @@ -45,7 +45,7 @@ func resourceGithubProjectColumnCreate(d *schema.ResourceData, meta interface{}) return err } - client := meta.(*Organization).client + client := meta.(*Owner).client options := github.ProjectColumnOptions{ Name: d.Get("name").(string), @@ -58,7 +58,7 @@ func resourceGithubProjectColumnCreate(d *schema.ResourceData, meta interface{}) } ctx := context.Background() - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name log.Printf("[DEBUG] Creating project column (%s) in project %d (%s)", options.Name, projectID, orgName) column, _, err := client.Projects.CreateProjectColumn(ctx, projectID, @@ -73,7 +73,7 @@ func resourceGithubProjectColumnCreate(d *schema.ResourceData, meta interface{}) } func resourceGithubProjectColumnRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client columnID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -106,7 +106,7 @@ func resourceGithubProjectColumnRead(d *schema.ResourceData, meta interface{}) e } func resourceGithubProjectColumnUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client options := github.ProjectColumnOptions{ Name: d.Get("name").(string), @@ -128,7 +128,7 @@ func resourceGithubProjectColumnUpdate(d *schema.ResourceData, meta interface{}) } func resourceGithubProjectColumnDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client columnID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index a0a9929d29..ff6cc1d5dc 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -187,14 +187,14 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er return err } - client := meta.(*Organization).client + client := meta.(*Owner).client if branchName, hasDefaultBranch := d.GetOk("default_branch"); hasDefaultBranch && (branchName != "master") { return fmt.Errorf("Cannot set the default branch on a new repository to something other than 'master'.") } repoReq := resourceGithubRepositoryObject(d) - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := repoReq.GetName() ctx := context.Background() @@ -256,8 +256,8 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro return err } - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name repoName := d.Id() log.Printf("[DEBUG] Reading repository: %s/%s", orgName, repoName) @@ -325,7 +325,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er return err } - client := meta.(*Organization).client + client := meta.(*Owner).client repoReq := resourceGithubRepositoryObject(d) // Can only set `default_branch` on an already created repository with the target branches ref already in-place @@ -338,7 +338,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er } repoName := d.Id() - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) log.Printf("[DEBUG] Updating repository: %s/%s", orgName, repoName) @@ -365,9 +365,9 @@ func resourceGithubRepositoryDelete(d *schema.ResourceData, meta interface{}) er return err } - client := meta.(*Organization).client + client := meta.(*Owner).client repoName := d.Id() - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) log.Printf("[DEBUG] Deleting repository: %s/%s", orgName, repoName) diff --git a/github/resource_github_repository_collaborator.go b/github/resource_github_repository_collaborator.go index 1af74c0091..8d95236ecf 100644 --- a/github/resource_github_repository_collaborator.go +++ b/github/resource_github_repository_collaborator.go @@ -53,9 +53,9 @@ func resourceGithubRepositoryCollaboratorCreate(d *schema.ResourceData, meta int return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name username := d.Get("username").(string) repoName := d.Get("repository").(string) ctx := context.Background() @@ -85,9 +85,9 @@ func resourceGithubRepositoryCollaboratorRead(d *schema.ResourceData, meta inter return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName, username, err := parseTwoPartID(d.Id()) if err != nil { return err @@ -162,9 +162,9 @@ func resourceGithubRepositoryCollaboratorDelete(d *schema.ResourceData, meta int return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name username := d.Get("username").(string) repoName := d.Get("repository").(string) diff --git a/github/resource_github_repository_collaborator_test.go b/github/resource_github_repository_collaborator_test.go index dbeba95d3b..3b77ffc248 100644 --- a/github/resource_github_repository_collaborator_test.go +++ b/github/resource_github_repository_collaborator_test.go @@ -93,14 +93,14 @@ func TestAccGithubRepositoryCollaborator_caseInsensitive(t *testing.T) { } func testAccCheckGithubRepositoryCollaboratorDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_repository_collaborator" { continue } - o := testAccProvider.Meta().(*Organization).name + o := testAccProvider.Meta().(*Owner).name r, u, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err @@ -133,8 +133,8 @@ func testAccCheckGithubRepositoryCollaboratorExists(n string) resource.TestCheck return fmt.Errorf("No membership ID is set") } - conn := testAccProvider.Meta().(*Organization).client - orgName := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).client + orgName := testAccProvider.Meta().(*Owner).name repoName, username, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err @@ -173,8 +173,8 @@ func testAccCheckGithubRepositoryCollaboratorPermission(n string) resource.TestC return fmt.Errorf("No membership ID is set") } - conn := testAccProvider.Meta().(*Organization).client - orgName := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).client + orgName := testAccProvider.Meta().(*Owner).name repoName, username, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err diff --git a/github/resource_github_repository_deploy_key.go b/github/resource_github_repository_deploy_key.go index 3ee2f3efc9..f1c930cdf9 100644 --- a/github/resource_github_repository_deploy_key.go +++ b/github/resource_github_repository_deploy_key.go @@ -59,13 +59,13 @@ func resourceGithubRepositoryDeployKeyCreate(d *schema.ResourceData, meta interf return err } - client := meta.(*Organization).client + client := meta.(*Owner).client repoName := d.Get("repository").(string) key := d.Get("key").(string) title := d.Get("title").(string) readOnly := d.Get("read_only").(bool) - owner := meta.(*Organization).name + owner := meta.(*Owner).name ctx := context.Background() log.Printf("[DEBUG] Creating repository deploy key: %s (%s/%s)", title, owner, repoName) @@ -92,9 +92,9 @@ func resourceGithubRepositoryDeployKeyRead(d *schema.ResourceData, meta interfac return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - owner := meta.(*Organization).name + owner := meta.(*Owner).name repoName, idString, err := parseTwoPartID(d.Id()) if err != nil { return err @@ -141,9 +141,9 @@ func resourceGithubRepositoryDeployKeyDelete(d *schema.ResourceData, meta interf return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - owner := meta.(*Organization).name + owner := meta.(*Owner).name repoName, idString, err := parseTwoPartID(d.Id()) if err != nil { return err diff --git a/github/resource_github_repository_deploy_key_test.go b/github/resource_github_repository_deploy_key_test.go index 841f03831c..42e484ac7c 100644 --- a/github/resource_github_repository_deploy_key_test.go +++ b/github/resource_github_repository_deploy_key_test.go @@ -81,14 +81,14 @@ func TestAccGithubRepositoryDeployKey_basic(t *testing.T) { } func testAccCheckGithubRepositoryDeployKeyDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_repository_deploy_key" { continue } - orgName := testAccProvider.Meta().(*Organization).name + orgName := testAccProvider.Meta().(*Owner).name repoName, idString, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err @@ -121,8 +121,8 @@ func testAccCheckGithubRepositoryDeployKeyExists(n string) resource.TestCheckFun return fmt.Errorf("No membership ID is set") } - conn := testAccProvider.Meta().(*Organization).client - orgName := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).client + orgName := testAccProvider.Meta().(*Owner).name repoName, idString, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err diff --git a/github/resource_github_repository_project.go b/github/resource_github_repository_project.go index 7e4fa4868b..3056c179fe 100644 --- a/github/resource_github_repository_project.go +++ b/github/resource_github_repository_project.go @@ -62,9 +62,9 @@ func resourceGithubRepositoryProjectCreate(d *schema.ResourceData, meta interfac return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) name := d.Get("name").(string) body := d.Get("body").(string) @@ -92,8 +92,8 @@ func resourceGithubRepositoryProjectRead(d *schema.ResourceData, meta interface{ return err } - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name projectID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -131,7 +131,7 @@ func resourceGithubRepositoryProjectRead(d *schema.ResourceData, meta interface{ } func resourceGithubRepositoryProjectUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client name := d.Get("name").(string) body := d.Get("body").(string) @@ -157,7 +157,7 @@ func resourceGithubRepositoryProjectUpdate(d *schema.ResourceData, meta interfac } func resourceGithubRepositoryProjectDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client projectID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 3ca4fabda7..5988f71095 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -30,9 +30,9 @@ func testSweepRepositories(region string) error { return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - repos, _, err := client.Repositories.List(context.TODO(), meta.(*Organization).name, nil) + repos, _, err := client.Repositories.List(context.TODO(), meta.(*Owner).name, nil) if err != nil { return err } @@ -41,7 +41,7 @@ func testSweepRepositories(region string) error { if strings.HasPrefix(*r.Name, "tf-acc-") || strings.HasPrefix(*r.Name, "foo-") { log.Printf("Destroying Repository %s", *r.Name) - if _, err := client.Repositories.Delete(context.TODO(), meta.(*Organization).name, *r.Name); err != nil { + if _, err := client.Repositories.Delete(context.TODO(), meta.(*Owner).name, *r.Name); err != nil { return err } } @@ -532,9 +532,9 @@ func testAccCheckGithubRepositoryExists(n string, repo *github.Repository) resou return fmt.Errorf("No repository name is set") } - org := testAccProvider.Meta().(*Organization) - conn := org.client - gotRepo, _, err := conn.Repositories.Get(context.TODO(), org.name, repoName) + owner := testAccProvider.Meta().(*Owner) + conn := owner.client + gotRepo, _, err := conn.Repositories.Get(context.TODO(), owner.name, repoName) if err != nil { return err } @@ -680,18 +680,18 @@ func testAccCheckGithubRepositoryAttributes(repo *github.Repository, want *testA } func testAccCheckGithubRepositoryDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client - orgName := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).client + ownerName := testAccProvider.Meta().(*Owner).name for _, rs := range s.RootModule().Resources { if rs.Type != "github_repository" { continue } - gotRepo, resp, err := conn.Repositories.Get(context.TODO(), orgName, rs.Primary.ID) + gotRepo, resp, err := conn.Repositories.Get(context.TODO(), ownerName, rs.Primary.ID) if err == nil { if gotRepo != nil && *gotRepo.Name == rs.Primary.ID { - return fmt.Errorf("Repository %s/%s still exists", orgName, *gotRepo.Name) + return fmt.Errorf("Repository %s/%s still exists", ownerName, *gotRepo.Name) } } if resp.StatusCode != 404 { @@ -703,21 +703,21 @@ func testAccCheckGithubRepositoryDestroy(s *terraform.State) error { } func testAccCreateRepositoryBranch(branch, repository string) error { - org := os.Getenv("GITHUB_ORGANIZATION") + owner := os.Getenv("GITHUB_OWNER") token := os.Getenv("GITHUB_TOKEN") config := Config{ - Token: token, - Organization: org, + Token: token, + Owner: owner, } c, err := config.Client() if err != nil { return fmt.Errorf("Error creating github client: %s", err) } - client := c.(*Organization).client + client := c.(*Owner).client - refs, _, err := client.Git.GetRefs(context.TODO(), org, repository, "heads") + refs, _, err := client.Git.GetRefs(context.TODO(), owner, repository, "heads") if err != nil { return fmt.Errorf("Error getting reference commit: %s", err) } @@ -730,7 +730,7 @@ func testAccCreateRepositoryBranch(branch, repository string) error { }, } - _, _, err = client.Git.CreateRef(context.TODO(), org, repository, newRef) + _, _, err = client.Git.CreateRef(context.TODO(), owner, repository, newRef) if err != nil { return fmt.Errorf("Error creating git reference: %s", err) } diff --git a/github/resource_github_repository_webhook.go b/github/resource_github_repository_webhook.go index 2442f3a5cb..c6ae453610 100644 --- a/github/resource_github_repository_webhook.go +++ b/github/resource_github_repository_webhook.go @@ -97,9 +97,9 @@ func resourceGithubRepositoryWebhookCreate(d *schema.ResourceData, meta interfac return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) hk := resourceGithubRepositoryWebhookObject(d) ctx := context.Background() @@ -128,9 +128,9 @@ func resourceGithubRepositoryWebhookRead(d *schema.ResourceData, meta interface{ return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) hookID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -184,9 +184,9 @@ func resourceGithubRepositoryWebhookUpdate(d *schema.ResourceData, meta interfac return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) hk := resourceGithubRepositoryWebhookObject(d) hookID, err := strconv.ParseInt(d.Id(), 10, 64) @@ -205,9 +205,9 @@ func resourceGithubRepositoryWebhookUpdate(d *schema.ResourceData, meta interfac } func resourceGithubRepositoryWebhookDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) hookID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { diff --git a/github/resource_github_repository_webhook_test.go b/github/resource_github_repository_webhook_test.go index 11f711dcac..b1a85c3aa6 100644 --- a/github/resource_github_repository_webhook_test.go +++ b/github/resource_github_repository_webhook_test.go @@ -116,9 +116,9 @@ func testAccCheckGithubRepositoryWebhookExists(n string, repoName string, hook * return fmt.Errorf("No repository name is set") } - org := testAccProvider.Meta().(*Organization) - conn := org.client - getHook, _, err := conn.Repositories.GetHook(context.TODO(), org.name, repoName, hookID) + owner := testAccProvider.Meta().(*Owner) + conn := owner.client + getHook, _, err := conn.Repositories.GetHook(context.TODO(), owner.name, repoName, hookID) if err != nil { return err } @@ -154,8 +154,8 @@ func testAccCheckGithubRepositoryWebhookAttributes(hook *github.Hook, want *test } func testAccCheckGithubRepositoryWebhookDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client - orgName := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).client + ownerName := testAccProvider.Meta().(*Owner).name for _, rs := range s.RootModule().Resources { if rs.Type != "github_repository_webhook" { @@ -167,7 +167,7 @@ func testAccCheckGithubRepositoryWebhookDestroy(s *terraform.State) error { return unconvertibleIdErr(rs.Primary.ID, err) } - gotHook, resp, err := conn.Repositories.GetHook(context.TODO(), orgName, rs.Primary.Attributes["repository"], id) + gotHook, resp, err := conn.Repositories.GetHook(context.TODO(), ownerName, rs.Primary.Attributes["repository"], id) if err == nil { if gotHook != nil && *gotHook.ID == id { return fmt.Errorf("Webhook still exists") diff --git a/github/resource_github_team.go b/github/resource_github_team.go index 0a7fcc020d..cf01041b3c 100644 --- a/github/resource_github_team.go +++ b/github/resource_github_team.go @@ -61,9 +61,9 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error { return err } - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name name := d.Get("name").(string) newTeam := github.NewTeam{ Name: name, @@ -98,7 +98,7 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error { } func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -142,7 +142,7 @@ func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error { } func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client editedTeam := github.NewTeam{ Name: d.Get("name").(string), @@ -182,7 +182,7 @@ func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceGithubTeamDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { diff --git a/github/resource_github_team_membership.go b/github/resource_github_team_membership.go index 5ba6e4e8a7..6442382a71 100644 --- a/github/resource_github_team_membership.go +++ b/github/resource_github_team_membership.go @@ -50,7 +50,7 @@ func resourceGithubTeamMembership() *schema.Resource { } func resourceGithubTeamMembershipCreateOrUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client teamIdString := d.Get("team_id").(string) teamId, err := strconv.ParseInt(teamIdString, 10, 64) @@ -80,7 +80,7 @@ func resourceGithubTeamMembershipCreateOrUpdate(d *schema.ResourceData, meta int } func resourceGithubTeamMembershipRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client teamIdString, username, err := parseTwoPartID(d.Id()) if err != nil { return err @@ -124,7 +124,7 @@ func resourceGithubTeamMembershipRead(d *schema.ResourceData, meta interface{}) } func resourceGithubTeamMembershipDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client teamIdString := d.Get("team_id").(string) teamId, err := strconv.ParseInt(teamIdString, 10, 64) diff --git a/github/resource_github_team_membership_test.go b/github/resource_github_team_membership_test.go index a5d14dbd44..3605b986ce 100644 --- a/github/resource_github_team_membership_test.go +++ b/github/resource_github_team_membership_test.go @@ -96,7 +96,7 @@ func TestAccGithubTeamMembership_caseInsensitive(t *testing.T) { } func testAccCheckGithubTeamMembershipDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_team_membership" { @@ -139,7 +139,7 @@ func testAccCheckGithubTeamMembershipExists(n string, membership *github.Members return fmt.Errorf("No team membership ID is set") } - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client teamIdString, username, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err @@ -171,7 +171,7 @@ func testAccCheckGithubTeamMembershipRoleState(n, expected string, membership *g return fmt.Errorf("No team membership ID is set") } - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client teamIdString, username, err := parseTwoPartID(rs.Primary.ID) if err != nil { return err diff --git a/github/resource_github_team_repository.go b/github/resource_github_team_repository.go index bd735bd26f..c172611757 100644 --- a/github/resource_github_team_repository.go +++ b/github/resource_github_team_repository.go @@ -52,14 +52,14 @@ func resourceGithubTeamRepositoryCreate(d *schema.ResourceData, meta interface{} return err } - client := meta.(*Organization).client + client := meta.(*Owner).client teamIdString := d.Get("team_id").(string) teamId, err := strconv.ParseInt(teamIdString, 10, 64) if err != nil { return unconvertibleIdErr(teamIdString, err) } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) permission := d.Get("permission").(string) ctx := context.Background() @@ -90,7 +90,7 @@ func resourceGithubTeamRepositoryRead(d *schema.ResourceData, meta interface{}) return err } - client := meta.(*Organization).client + client := meta.(*Owner).client teamIdString, repoName, err := parseTwoPartID(d.Id()) if err != nil { @@ -101,7 +101,7 @@ func resourceGithubTeamRepositoryRead(d *schema.ResourceData, meta interface{}) if err != nil { return unconvertibleIdErr(teamIdString, err) } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) if !d.IsNewResource() { ctx = context.WithValue(ctx, ctxEtag, d.Get("etag").(string)) @@ -144,14 +144,14 @@ func resourceGithubTeamRepositoryUpdate(d *schema.ResourceData, meta interface{} return err } - client := meta.(*Organization).client + client := meta.(*Owner).client teamIdString := d.Get("team_id").(string) teamId, err := strconv.ParseInt(teamIdString, 10, 64) if err != nil { return unconvertibleIdErr(teamIdString, err) } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) permission := d.Get("permission").(string) ctx := context.WithValue(context.Background(), ctxId, d.Id()) @@ -182,7 +182,7 @@ func resourceGithubTeamRepositoryDelete(d *schema.ResourceData, meta interface{} return err } - client := meta.(*Organization).client + client := meta.(*Owner).client teamIdString := d.Get("team_id").(string) @@ -190,7 +190,7 @@ func resourceGithubTeamRepositoryDelete(d *schema.ResourceData, meta interface{} if err != nil { return unconvertibleIdErr(teamIdString, err) } - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name repoName := d.Get("repository").(string) ctx := context.WithValue(context.Background(), ctxId, d.Id()) diff --git a/github/resource_github_team_repository_test.go b/github/resource_github_team_repository_test.go index 6eb381c63e..d5ab3e7764 100644 --- a/github/resource_github_team_repository_test.go +++ b/github/resource_github_team_repository_test.go @@ -99,7 +99,7 @@ func testAccCheckGithubTeamRepositoryExists(n string, repository *github.Reposit return fmt.Errorf("No team repository ID is set") } - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client teamIdString, repoName, err := parseTwoPartID(rs.Primary.ID) if err != nil { @@ -112,7 +112,7 @@ func testAccCheckGithubTeamRepositoryExists(n string, repository *github.Reposit repo, _, err := conn.Teams.IsTeamRepo(context.TODO(), teamId, - testAccProvider.Meta().(*Organization).name, + testAccProvider.Meta().(*Owner).name, repoName) if err != nil { @@ -124,7 +124,7 @@ func testAccCheckGithubTeamRepositoryExists(n string, repository *github.Reposit } func testAccCheckGithubTeamRepositoryDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_team_repository" { @@ -142,7 +142,7 @@ func testAccCheckGithubTeamRepositoryDestroy(s *terraform.State) error { repo, resp, err := conn.Teams.IsTeamRepo(context.TODO(), teamId, - testAccProvider.Meta().(*Organization).name, + testAccProvider.Meta().(*Owner).name, repoName) if err == nil { diff --git a/github/resource_github_team_test.go b/github/resource_github_team_test.go index d740a97ddb..336b0e7831 100644 --- a/github/resource_github_team_test.go +++ b/github/resource_github_team_test.go @@ -140,7 +140,7 @@ func testAccCheckGithubTeamExists(n string, team *github.Team) resource.TestChec return fmt.Errorf("No Team ID is set") } - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client id, err := strconv.ParseInt(rs.Primary.ID, 10, 64) if err != nil { return unconvertibleIdErr(rs.Primary.ID, err) @@ -178,7 +178,7 @@ func testAccCheckGithubTeamAttributes(team *github.Team, name, description strin } func testAccCheckGithubTeamDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_team" { diff --git a/github/resource_github_user_gpg_key.go b/github/resource_github_user_gpg_key.go index 964fed71c5..67edb43eb7 100644 --- a/github/resource_github_user_gpg_key.go +++ b/github/resource_github_user_gpg_key.go @@ -35,7 +35,7 @@ func resourceGithubUserGpgKey() *schema.Resource { } func resourceGithubUserGpgKeyCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client pubKey := d.Get("armored_public_key").(string) ctx := context.Background() @@ -52,7 +52,7 @@ func resourceGithubUserGpgKeyCreate(d *schema.ResourceData, meta interface{}) er } func resourceGithubUserGpgKeyRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -86,7 +86,7 @@ func resourceGithubUserGpgKeyRead(d *schema.ResourceData, meta interface{}) erro } func resourceGithubUserGpgKeyDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { diff --git a/github/resource_github_user_invitation_accepter.go b/github/resource_github_user_invitation_accepter.go index 28594921d0..ee0cd71a55 100644 --- a/github/resource_github_user_invitation_accepter.go +++ b/github/resource_github_user_invitation_accepter.go @@ -26,7 +26,7 @@ func resourceGithubUserInvitationAccepter() *schema.Resource { } func resourceGithubUserInvitationAccepterCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client invitationIdString := d.Get("invitation_id").(string) invitationId, err := strconv.Atoi(invitationIdString) diff --git a/github/resource_github_user_ssh_key.go b/github/resource_github_user_ssh_key.go index 2aefa88e6b..f0c2df126f 100644 --- a/github/resource_github_user_ssh_key.go +++ b/github/resource_github_user_ssh_key.go @@ -48,7 +48,7 @@ func resourceGithubUserSshKey() *schema.Resource { } func resourceGithubUserSshKeyCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client title := d.Get("title").(string) key := d.Get("key").(string) @@ -69,7 +69,7 @@ func resourceGithubUserSshKeyCreate(d *schema.ResourceData, meta interface{}) er } func resourceGithubUserSshKeyRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -105,7 +105,7 @@ func resourceGithubUserSshKeyRead(d *schema.ResourceData, meta interface{}) erro } func resourceGithubUserSshKeyDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { diff --git a/github/resource_organization_block.go b/github/resource_organization_block.go index 4878856fb3..f64900291a 100644 --- a/github/resource_organization_block.go +++ b/github/resource_organization_block.go @@ -39,8 +39,8 @@ func resourceOrganizationBlockCreate(d *schema.ResourceData, meta interface{}) e return err } - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name ctx := context.Background() username := d.Get("username").(string) @@ -55,8 +55,8 @@ func resourceOrganizationBlockCreate(d *schema.ResourceData, meta interface{}) e } func resourceOrganizationBlockRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client - orgName := meta.(*Organization).name + client := meta.(*Owner).client + orgName := meta.(*Owner).name username := d.Id() @@ -95,9 +95,9 @@ func resourceOrganizationBlockRead(d *schema.ResourceData, meta interface{}) err } func resourceOrganizationBlockDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*Organization).client + client := meta.(*Owner).client - orgName := meta.(*Organization).name + orgName := meta.(*Owner).name username := d.Id() ctx := context.WithValue(context.Background(), ctxId, d.Id()) diff --git a/github/sweeper_test.go b/github/sweeper_test.go index 1e0360071f..5647bf7e99 100644 --- a/github/sweeper_test.go +++ b/github/sweeper_test.go @@ -17,14 +17,14 @@ func sharedConfigForRegion(region string) (interface{}, error) { return nil, fmt.Errorf("empty GITHUB_TOKEN") } - if os.Getenv("GITHUB_ORGANIZATION") == "" { - return nil, fmt.Errorf("empty GITHUB_ORGANIZATION") + if os.Getenv("GITHUB_OWNER") == "" { + return nil, fmt.Errorf("empty GITHUB_OWNER") } config := Config{ - Token: os.Getenv("GITHUB_TOKEN"), - Organization: os.Getenv("GITHUB_ORGANIZATION"), - BaseURL: "", + Token: os.Getenv("GITHUB_TOKEN"), + Owner: os.Getenv("GITHUB_OWNER"), + BaseURL: "", } client, err := config.Client() diff --git a/github/util.go b/github/util.go index 6676edeb30..0514c172df 100644 --- a/github/util.go +++ b/github/util.go @@ -14,7 +14,7 @@ const ( ) func checkOrganization(meta interface{}) error { - if meta.(*Organization).name == "" { + if meta.(*Owner).name == "" { return fmt.Errorf("This resource requires GitHub organization to be set on the provider.") } diff --git a/go.mod b/go.mod index 10eb37901d..d4ea30761a 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,7 @@ require ( github.com/hashicorp/terraform v0.12.7 github.com/kylelemons/godebug v1.1.0 github.com/terraform-providers/terraform-provider-tls v1.2.0 - golang.org/x/oauth2 v0.0.0-20190604054615-0f29369cfe45 + golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 ) + +go 1.13 diff --git a/go.sum b/go.sum index db7f141e23..14b0235274 100644 --- a/go.sum +++ b/go.sum @@ -454,6 +454,8 @@ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAG golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604054615-0f29369cfe45 h1:7WTIev2se641DAZGtJcRvZBxQ1TvY+9GTffZHngkGHY= golang.org/x/oauth2 v0.0.0-20190604054615-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852/go.mod h1:JLpeXjPJfIyPr5TlbXLkXWLhP8nz10XfvxElABhCtcw= From 98f04452161ac741de8ac4be921e8b004dcd266e Mon Sep 17 00:00:00 2001 From: Eliasz Slusarczyk Date: Sat, 19 May 2018 20:24:51 +0100 Subject: [PATCH 02/11] Update website doc --- website/docs/index.html.markdown | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 28e932241a..a512b1b802 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -2,12 +2,12 @@ layout: "github" page_title: "Provider: GitHub" description: |- - The GitHub provider is used to interact with GitHub organization resources. + The GitHub provider is used to interact with GitHub resources. --- # GitHub Provider -The GitHub provider is used to interact with GitHub organization resources. +The GitHub provider is used to interact with GitHub resources. The provider allows you to manage your GitHub organization's members and teams easily. It needs to be configured with the proper credentials before it can be used. @@ -19,8 +19,8 @@ Use the navigation to the left to read about the available resources. ```hcl # Configure the GitHub Provider provider "github" { - token = "${var.github_token}" - organization = "${var.github_organization}" + token = "${var.github_token}" + owner = "${var.github_owner}" } # Add a user to the organization @@ -37,10 +37,10 @@ The following arguments are supported in the `provider` block: sourced from the `GITHUB_TOKEN` environment variable. If `anonymous` is false, token is required. -* `organization` - (Optional) This is the target GitHub organization to manage. +* `owner` - (Required) This is the target GitHub organization or a user to manage. The account corresponding to the token will need "owner" privileges for this - organization. It can also be sourced from the `GITHUB_ORGANIZATION` - environment variable. If `individual` is false, organization is required. + organization. It can also be sourced from the `GITHUB_OWNER` + environment variable. * `base_url` - (Optional) This is the target GitHub base API endpoint. Providing a value is a requirement when working with GitHub Enterprise. It is optional to provide this value and From 1e6a454e858108b14f600347e9b7f440f1937a97 Mon Sep 17 00:00:00 2001 From: Eliasz Slusarczyk Date: Sat, 19 May 2018 20:26:47 +0100 Subject: [PATCH 03/11] Add the possibility to create a repository when the owner is not an organization --- github/config.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/github/config.go b/github/config.go index 350c9d13d8..2bba741152 100644 --- a/github/config.go +++ b/github/config.go @@ -22,9 +22,14 @@ type Config struct { } type Owner struct { - name string - client *github.Client - StopContext context.Context + name string + client *github.Client + StopContext context.Context + Organization bool +} + +func (o *Owner) IsOrganization() bool { + return o.Organization } // Client configures and returns a fully initialized GithubClient @@ -40,6 +45,10 @@ func (c *Config) Client() (interface{}, error) { ctx = context.WithValue(ctx, oauth2.HTTPClient, insecureClient) } + if !c.Individual { + owner.Organization = true + } + // Either Owner needs to be set, or Individual needs to be true if c.Owner != "" && c.Individual { return nil, fmt.Errorf("If `individual` is true, `owner` cannot be set.") @@ -48,10 +57,6 @@ func (c *Config) Client() (interface{}, error) { return nil, fmt.Errorf("If `individual` is false, `owner` is required.") } - if c.Individual { - owner.name = "" - } - // 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.") @@ -86,6 +91,11 @@ func (c *Config) Client() (interface{}, error) { owner.client.BaseURL = u } + _, _, err := (*owner.client).Organizations.Get(context.TODO(), owner.name) + if err != nil { + owner.Organization = false + } + return &owner, nil } From 5bcc0d02b6386836803cd5116ff53236eda5f5f1 Mon Sep 17 00:00:00 2001 From: Eliasz Slusarczyk Date: Sat, 9 Jun 2018 15:22:08 +0100 Subject: [PATCH 04/11] Fix the metadata owner name after master rebase --- github/resource_github_repository.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index ff6cc1d5dc..2a0c3f5990 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -182,12 +182,11 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { } func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).client + owner := "" + if meta.(*Owner).IsOrganization() { + owner = meta.(*Owner).name + } if branchName, hasDefaultBranch := d.GetOk("default_branch"); hasDefaultBranch && (branchName != "master") { return fmt.Errorf("Cannot set the default branch on a new repository to something other than 'master'.") @@ -198,7 +197,7 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er repoName := repoReq.GetName() ctx := context.Background() - log.Printf("[DEBUG] Creating repository: %s/%s", orgName, repoName) + log.Printf("[DEBUG] Creating repository: %s/%s", owner, repoName) if template, ok := d.GetOk("template"); ok { templateConfigBlocks := template.([]interface{}) @@ -213,7 +212,7 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er templateRepoOwner := templateConfigMap["owner"].(string) templateRepoReq := github.TemplateRepoRequest{ Name: &repoName, - Owner: &orgName, + Owner: &owner, Description: github.String(d.Get("description").(string)), Private: github.Bool(d.Get("private").(bool)), } @@ -232,7 +231,7 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er } } else { // Create without a repository template - repo, _, err := client.Repositories.Create(ctx, orgName, repoReq) + repo, _, err := client.Repositories.Create(ctx, owner, repoReq) if err != nil { return err } @@ -241,7 +240,7 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er topics := repoReq.Topics if len(topics) > 0 { - _, _, err = client.Repositories.ReplaceAllTopics(ctx, orgName, repoName, topics) + _, _, err = client.Repositories.ReplaceAllTopics(ctx, owner, repoName, topics) if err != nil { return err } From 8fe96994581619ef6a23f724fa6e42aa1eaca901 Mon Sep 17 00:00:00 2001 From: Eliasz Slusarczyk Date: Sat, 9 Jun 2018 15:23:01 +0100 Subject: [PATCH 05/11] Restore organization variable to the provider for the lazy compatibility issues. --- github/provider.go | 14 +++++++++++++- github/provider_test.go | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/github/provider.go b/github/provider.go index eb487bc751..76202b23e1 100644 --- a/github/provider.go +++ b/github/provider.go @@ -20,6 +20,12 @@ func Provider() terraform.ResourceProvider { DefaultFunc: schema.EnvDefaultFunc("GITHUB_OWNER", nil), Description: descriptions["owner"], }, + "organization": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("GITHUB_ORGANIZATION", nil), + Description: descriptions["organization"], + }, "base_url": { Type: schema.TypeString, Optional: true, @@ -91,6 +97,8 @@ func init() { "owner": "The GitHub owner name to manage. " + "If `individual` is false, owner is required.", + "organization": "The GitHub owner name to manage.", + "base_url": "The GitHub Base API URL", "insecure": "Whether server should be accessed " + @@ -108,9 +116,13 @@ func init() { func providerConfigure(p *schema.Provider) schema.ConfigureFunc { return func(d *schema.ResourceData) (interface{}, error) { + owner := d.Get("owner").(string) + if owner == "" { + owner = d.Get("organization").(string) + } config := Config{ Token: d.Get("token").(string), - Owner: d.Get("organization").(string), + Owner: owner, BaseURL: d.Get("base_url").(string), Insecure: d.Get("insecure").(bool), Individual: d.Get("individual").(bool), diff --git a/github/provider_test.go b/github/provider_test.go index 35f3e6fd59..3df62192bc 100644 --- a/github/provider_test.go +++ b/github/provider_test.go @@ -58,6 +58,9 @@ func testAccPreCheck(t *testing.T) { if v := os.Getenv("GITHUB_OWNER"); v == "" { t.Fatal("GITHUB_OWNER must be set for acceptance tests") } + if v := os.Getenv("GITHUB_ORGANIZATION"); v == "" { + t.Fatal("GITHUB_ORGANIZATION must be set for acceptance tests") + } if v := os.Getenv("GITHUB_TEST_USER"); v == "" { t.Fatal("GITHUB_TEST_USER must be set for acceptance tests") } From 1f8b22fb9099a3cf4f77217c3c766e23138002b9 Mon Sep 17 00:00:00 2001 From: Eliasz Slusarczyk Date: Sat, 9 Jun 2018 15:26:03 +0100 Subject: [PATCH 06/11] Add the organization argument reference to the docs. --- website/docs/index.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index a512b1b802..f9f314ca87 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -42,6 +42,10 @@ The following arguments are supported in the `provider` block: organization. It can also be sourced from the `GITHUB_OWNER` environment variable. +* `organization` - (DEPRICATED) This is the target GitHub organization or a user to manage. The account + corresponding to the token will need "organization" privileges for this organization. It must be provided, but + it can also be sourced from the `GITHUB_ORGANIZATION` environment variable. + * `base_url` - (Optional) This is the target GitHub base API endpoint. Providing a value is a requirement when working with GitHub Enterprise. It is optional to provide this value and it can also be sourced from the `GITHUB_BASE_URL` environment variable. The value must end with a slash, From d67fa19dcdeb100ae723e9470cdd3cce699c69e8 Mon Sep 17 00:00:00 2001 From: Eliasz Slusarczyk Date: Sat, 9 Jun 2018 15:49:50 +0100 Subject: [PATCH 07/11] Increase the priority for organization provider argument over owner. --- github/provider.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/provider.go b/github/provider.go index 76202b23e1..bff61e6c48 100644 --- a/github/provider.go +++ b/github/provider.go @@ -116,9 +116,9 @@ func init() { func providerConfigure(p *schema.Provider) schema.ConfigureFunc { return func(d *schema.ResourceData) (interface{}, error) { - owner := d.Get("owner").(string) + owner := d.Get("organization").(string) if owner == "" { - owner = d.Get("organization").(string) + owner = d.Get("owner").(string) } config := Config{ Token: d.Get("token").(string), From 98b173bb6a3d0fd1f4dc72eeac306ad7268304ad Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 16 Jan 2020 22:17:22 +0300 Subject: [PATCH 08/11] Fix leftover errors --- github/resource_github_repository.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 2a0c3f5990..f18707ed70 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -193,7 +193,6 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er } repoReq := resourceGithubRepositoryObject(d) - orgName := meta.(*Owner).name repoName := repoReq.GetName() ctx := context.Background() @@ -240,7 +239,7 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er topics := repoReq.Topics if len(topics) > 0 { - _, _, err = client.Repositories.ReplaceAllTopics(ctx, owner, repoName, topics) + _, _, err := client.Repositories.ReplaceAllTopics(ctx, owner, repoName, topics) if err != nil { return err } From f9716313914c68e4ba5895f26202b02d7c24bb9d Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 16 Jan 2020 22:33:32 +0300 Subject: [PATCH 09/11] Make owner.IsOrganization a bool instead of method Per review comments https://github.com/terraform-providers/terraform-provider-github/pull/96#pullrequestreview-144486979 --- github/config.go | 16 ++++++---------- github/resource_github_repository.go | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/github/config.go b/github/config.go index 2bba741152..32fdfb454f 100644 --- a/github/config.go +++ b/github/config.go @@ -22,14 +22,10 @@ type Config struct { } type Owner struct { - name string - client *github.Client - StopContext context.Context - Organization bool -} - -func (o *Owner) IsOrganization() bool { - return o.Organization + name string + client *github.Client + StopContext context.Context + IsOrganization bool } // Client configures and returns a fully initialized GithubClient @@ -46,7 +42,7 @@ func (c *Config) Client() (interface{}, error) { } if !c.Individual { - owner.Organization = true + owner.IsOrganization = true } // Either Owner needs to be set, or Individual needs to be true @@ -93,7 +89,7 @@ func (c *Config) Client() (interface{}, error) { _, _, err := (*owner.client).Organizations.Get(context.TODO(), owner.name) if err != nil { - owner.Organization = false + owner.IsOrganization = false } return &owner, nil diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index f18707ed70..e21542f5cc 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -184,7 +184,7 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*Owner).client owner := "" - if meta.(*Owner).IsOrganization() { + if meta.(*Owner).IsOrganization { owner = meta.(*Owner).name } From 8db7ccf849ea654db98ffc5bbeede36673cceaa7 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 16 Jan 2020 22:48:41 +0300 Subject: [PATCH 10/11] Fix `*Owner` in tests --- github/resource_github_organization_project_test.go | 4 ++-- github/resource_github_project_column_test.go | 4 ++-- github/resource_github_repository_collaborator_test.go | 4 ++-- github/resource_github_repository_project_test.go | 4 ++-- github/resource_github_user_gpg_key_test.go | 4 ++-- github/resource_github_user_ssh_key_test.go | 4 ++-- github/resource_organization_block_test.go | 8 ++++---- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/github/resource_github_organization_project_test.go b/github/resource_github_organization_project_test.go index 4c2ae3ef88..b7886e3c0e 100644 --- a/github/resource_github_organization_project_test.go +++ b/github/resource_github_organization_project_test.go @@ -42,7 +42,7 @@ func TestAccGithubOrganizationProject_basic(t *testing.T) { } func testAccGithubOrganizationProjectDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_organization_project" { @@ -81,7 +81,7 @@ func testAccCheckGithubOrganizationProjectExists(n string, project *github.Proje return err } - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client gotProject, _, err := conn.Projects.GetProject(context.TODO(), projectID) if err != nil { return err diff --git a/github/resource_github_project_column_test.go b/github/resource_github_project_column_test.go index 417155a5d2..cc409f1108 100644 --- a/github/resource_github_project_column_test.go +++ b/github/resource_github_project_column_test.go @@ -49,7 +49,7 @@ func TestAccGithubProjectColumn_basic(t *testing.T) { } func testAccGithubProjectColumnDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_project_column" { @@ -87,7 +87,7 @@ func testAccCheckGithubProjectColumnExists(n string, project *github.ProjectColu return err } - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client gotColumn, _, err := conn.Projects.GetProjectColumn(context.TODO(), columnID) if err != nil { return err diff --git a/github/resource_github_repository_collaborator_test.go b/github/resource_github_repository_collaborator_test.go index 3b77ffc248..c345ff022d 100644 --- a/github/resource_github_repository_collaborator_test.go +++ b/github/resource_github_repository_collaborator_test.go @@ -224,8 +224,8 @@ func testAccCheckGithubRepositoryCollaboratorInvited(repoName, username string, return func(s *terraform.State) error { opt := &github.ListOptions{PerPage: maxPerPage} - client := testAccProvider.Meta().(*Organization).client - org := testAccProvider.Meta().(*Organization).name + client := testAccProvider.Meta().(*Owner).client + org := testAccProvider.Meta().(*Owner).name for { invitations, resp, err := client.Repositories.ListInvitations(context.TODO(), org, repoName, opt) diff --git a/github/resource_github_repository_project_test.go b/github/resource_github_repository_project_test.go index 4b9b25f0e2..85ae458274 100644 --- a/github/resource_github_repository_project_test.go +++ b/github/resource_github_repository_project_test.go @@ -47,7 +47,7 @@ func TestAccGithubRepositoryProject_basic(t *testing.T) { } func testAccGithubRepositoryProjectDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_repository_project" { @@ -86,7 +86,7 @@ func testAccCheckGithubRepositoryProjectExists(n string, project *github.Project return err } - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client gotProject, _, err := conn.Projects.GetProject(context.TODO(), projectID) if err != nil { return err diff --git a/github/resource_github_user_gpg_key_test.go b/github/resource_github_user_gpg_key_test.go index a90ff99161..723df5fc94 100644 --- a/github/resource_github_user_gpg_key_test.go +++ b/github/resource_github_user_gpg_key_test.go @@ -49,7 +49,7 @@ func testAccCheckGithubUserGpgKeyExists(n string, key *github.GPGKey) resource.T return unconvertibleIdErr(rs.Primary.ID, err) } - org := testAccProvider.Meta().(*Organization) + org := testAccProvider.Meta().(*Owner) receivedKey, _, err := org.client.Users.GetGPGKey(context.TODO(), id) if err != nil { return err @@ -60,7 +60,7 @@ func testAccCheckGithubUserGpgKeyExists(n string, key *github.GPGKey) resource.T } func testAccCheckGithubUserGpgKeyDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_user_gpg_key" { diff --git a/github/resource_github_user_ssh_key_test.go b/github/resource_github_user_ssh_key_test.go index 6dee167a80..d20185099b 100644 --- a/github/resource_github_user_ssh_key_test.go +++ b/github/resource_github_user_ssh_key_test.go @@ -57,7 +57,7 @@ func testAccCheckGithubUserSshKeyExists(n string, key *github.Key) resource.Test return unconvertibleIdErr(rs.Primary.ID, err) } - org := testAccProvider.Meta().(*Organization) + org := testAccProvider.Meta().(*Owner) receivedKey, _, err := org.client.Users.GetKey(context.TODO(), id) if err != nil { return err @@ -68,7 +68,7 @@ func testAccCheckGithubUserSshKeyExists(n string, key *github.Key) resource.Test } func testAccCheckGithubUserSshKeyDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client + conn := testAccProvider.Meta().(*Owner).client for _, rs := range s.RootModule().Resources { if rs.Type != "github_user_ssh_key" { diff --git a/github/resource_organization_block_test.go b/github/resource_organization_block_test.go index c66580689d..01e7602bd4 100644 --- a/github/resource_organization_block_test.go +++ b/github/resource_organization_block_test.go @@ -33,8 +33,8 @@ func TestAccOrganizationBlock_basic(t *testing.T) { } func testAccOrganizationBlockDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*Organization).client - orgName := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).client + orgName := testAccProvider.Meta().(*Owner).name for _, rs := range s.RootModule().Resources { if rs.Type != "github_organization_block" { @@ -60,8 +60,8 @@ func testAccCheckOrganizationBlockExists(n string) resource.TestCheckFunc { } username := rs.Primary.ID - conn := testAccProvider.Meta().(*Organization).client - orgName := testAccProvider.Meta().(*Organization).name + conn := testAccProvider.Meta().(*Owner).client + orgName := testAccProvider.Meta().(*Owner).name blocked, _, err := conn.Organizations.IsBlocked(context.TODO(), orgName, username) if err != nil { From 79f5cb01e30a91e64d3f72cd679ad9623bbb1a01 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 16 Jan 2020 23:08:55 +0300 Subject: [PATCH 11/11] Fix "File is not `gofmt`-ed with `-s` (gofmt)" --- github/provider.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/github/provider.go b/github/provider.go index bff61e6c48..b3b3597b90 100644 --- a/github/provider.go +++ b/github/provider.go @@ -121,12 +121,12 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc { owner = d.Get("owner").(string) } config := Config{ - Token: d.Get("token").(string), - Owner: owner, - BaseURL: d.Get("base_url").(string), - Insecure: d.Get("insecure").(bool), - Individual: d.Get("individual").(bool), - Anonymous: d.Get("anonymous").(bool), + Token: d.Get("token").(string), + Owner: owner, + BaseURL: d.Get("base_url").(string), + Insecure: d.Get("insecure").(bool), + Individual: d.Get("individual").(bool), + Anonymous: d.Get("anonymous").(bool), } meta, err := config.Client()