diff --git a/github/data_source_github_ip_ranges.go b/github/data_source_github_ip_ranges.go index 23b0123251..e1408fbd82 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.(*Owner) + owner := meta.(*Owner) - api, _, err := org.v3client.APIMeta(org.StopContext) + api, _, err := owner.v3client.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 fd4bcba209..d01301c41d 100644 --- a/github/data_source_github_repositories.go +++ b/github/data_source_github_repositories.go @@ -43,11 +43,6 @@ func dataSourceGithubRepositories() *schema.Resource { } func dataSourceGithubRepositoriesRead(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client query := d.Get("query").(string) diff --git a/github/data_source_github_repositories_test.go b/github/data_source_github_repositories_test.go index 17f87c41a1..5dd2a95b3f 100644 --- a/github/data_source_github_repositories_test.go +++ b/github/data_source_github_repositories_test.go @@ -9,11 +9,8 @@ import ( ) func TestAccGithubRepositoriesDataSource_basic(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - query := "org:hashicorp repository:terraform" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -32,9 +29,6 @@ func TestAccGithubRepositoriesDataSource_basic(t *testing.T) { }) } func TestAccGithubRepositoriesDataSource_Sort(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -63,11 +57,8 @@ func TestAccGithubRepositoriesDataSource_Sort(t *testing.T) { } func TestAccGithubRepositoriesDataSource_noMatch(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - query := "klsafj_23434_doesnt_exist" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index 5b29d4ea07..6523479ac1 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -107,18 +107,13 @@ func dataSourceGithubRepository() *schema.Resource { } func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client - orgName := meta.(*Owner).name + owner := meta.(*Owner).name var repoName string if fullName, ok := d.GetOk("full_name"); ok { var err error - orgName, repoName, err = splitRepoFullName(fullName.(string)) + owner, repoName, err = splitRepoFullName(fullName.(string)) if err != nil { return err } @@ -131,8 +126,8 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("One of %q or %q has to be provided", "full_name", "name") } - log.Printf("[DEBUG] Reading GitHub repository %s/%s", orgName, repoName) - repo, _, err := client.Repositories.Get(context.TODO(), orgName, repoName) + log.Printf("[DEBUG] Reading GitHub repository %s/%s", owner, repoName) + repo, _, err := client.Repositories.Get(context.TODO(), owner, repoName) if err != nil { return err } @@ -170,7 +165,7 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er func splitRepoFullName(fullName string) (string, string, error) { parts := strings.Split(fullName, "/") if len(parts) != 2 { - return "", "", fmt.Errorf("Unexpected full name format (%q), expected org/repo_name", fullName) + return "", "", fmt.Errorf("Unexpected full name format (%q), expected owner/repo_name", fullName) } return parts[0], parts[1], nil } diff --git a/github/data_source_github_repository_test.go b/github/data_source_github_repository_test.go index adbcce9d6a..dbf48d9edd 100644 --- a/github/data_source_github_repository_test.go +++ b/github/data_source_github_repository_test.go @@ -9,11 +9,8 @@ import ( ) func TestAccGithubRepositoryDataSource_fullName_noMatchReturnsError(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - fullName := "klsafj_23434_doesnt_exist/not-exists" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -29,11 +26,8 @@ func TestAccGithubRepositoryDataSource_fullName_noMatchReturnsError(t *testing.T } func TestAccGithubRepositoryDataSource_name_noMatchReturnsError(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - name := "not-exists" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -49,11 +43,8 @@ func TestAccGithubRepositoryDataSource_name_noMatchReturnsError(t *testing.T) { } func TestAccGithubRepositoryDataSource_fullName_existing(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - fullName := testOwner + "/test-repo" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -69,11 +60,8 @@ func TestAccGithubRepositoryDataSource_fullName_existing(t *testing.T) { } func TestAccGithubRepositoryDataSource_name_existing(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - name := "test-repo" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 9055d761c6..63eb03dc57 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -196,11 +196,6 @@ 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).v3client if branchName, hasDefaultBranch := d.GetOk("default_branch"); hasDefaultBranch && (branchName != "master") { @@ -208,11 +203,11 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er } repoReq := resourceGithubRepositoryObject(d) - orgName := meta.(*Owner).name + owner := meta.(*Owner).name 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{}) @@ -227,7 +222,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)), } @@ -246,16 +241,24 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er } } else { // Create without a repository template - repo, _, err := client.Repositories.Create(ctx, orgName, repoReq) + var repo *github.Repository + var err error + if meta.(*Owner).IsOrganization { + repo, _, err = client.Repositories.Create(ctx, owner, repoReq) + } else { + // Create repository within authenticated user's account + repo, _, err = client.Repositories.Create(ctx, "", repoReq) + + } if err != nil { return err } - d.SetId(*repo.Name) + d.SetId(repo.GetName()) } 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 } @@ -265,23 +268,18 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er } func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client - orgName := meta.(*Owner).name + owner := meta.(*Owner).name repoName := d.Id() - log.Printf("[DEBUG] Reading repository: %s/%s", orgName, repoName) + log.Printf("[DEBUG] Reading repository: %s/%s", owner, repoName) ctx := context.WithValue(context.Background(), ctxId, d.Id()) if !d.IsNewResource() { ctx = context.WithValue(ctx, ctxEtag, d.Get("etag").(string)) } - repo, resp, err := client.Repositories.Get(ctx, orgName, repoName) + repo, resp, err := client.Repositories.Get(ctx, owner, repoName) if err != nil { if ghErr, ok := err.(*github.ErrorResponse); ok { if ghErr.Response.StatusCode == http.StatusNotModified { @@ -289,7 +287,7 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro } if ghErr.Response.StatusCode == http.StatusNotFound { log.Printf("[WARN] Removing repository %s/%s from state because it no longer exists in GitHub", - orgName, repoName) + owner, repoName) d.SetId("") return nil } @@ -337,11 +335,6 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro } func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client repoReq := resourceGithubRepositoryObject(d) @@ -355,11 +348,11 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er } repoName := d.Id() - orgName := meta.(*Owner).name + owner := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) - log.Printf("[DEBUG] Updating repository: %s/%s", orgName, repoName) - repo, _, err := client.Repositories.Edit(ctx, orgName, repoName, repoReq) + log.Printf("[DEBUG] Updating repository: %s/%s", owner, repoName) + repo, _, err := client.Repositories.Edit(ctx, owner, repoName, repoReq) if err != nil { return err } @@ -367,7 +360,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er if d.HasChange("topics") { topics := repoReq.Topics - _, _, err = client.Repositories.ReplaceAllTopics(ctx, orgName, *repo.Name, topics) + _, _, err = client.Repositories.ReplaceAllTopics(ctx, owner, *repo.Name, topics) if err != nil { return err } @@ -377,18 +370,13 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er } func resourceGithubRepositoryDelete(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client repoName := d.Id() - orgName := meta.(*Owner).name + owner := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) - log.Printf("[DEBUG] Deleting repository: %s/%s", orgName, repoName) - _, err = client.Repositories.Delete(ctx, orgName, repoName) + log.Printf("[DEBUG] Deleting repository: %s/%s", owner, repoName) + _, err := client.Repositories.Delete(ctx, owner, repoName) return err } diff --git a/github/resource_github_repository_deploy_key.go b/github/resource_github_repository_deploy_key.go index 255b073759..1b3248d57c 100644 --- a/github/resource_github_repository_deploy_key.go +++ b/github/resource_github_repository_deploy_key.go @@ -54,11 +54,6 @@ func resourceGithubRepositoryDeployKey() *schema.Resource { } func resourceGithubRepositoryDeployKeyCreate(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client repoName := d.Get("repository").(string) @@ -87,11 +82,6 @@ func resourceGithubRepositoryDeployKeyCreate(d *schema.ResourceData, meta interf } func resourceGithubRepositoryDeployKeyRead(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client owner := meta.(*Owner).name @@ -136,11 +126,6 @@ func resourceGithubRepositoryDeployKeyRead(d *schema.ResourceData, meta interfac } func resourceGithubRepositoryDeployKeyDelete(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client owner := meta.(*Owner).name diff --git a/github/resource_github_repository_deploy_key_test.go b/github/resource_github_repository_deploy_key_test.go index b66f7b1643..49443e7fa3 100644 --- a/github/resource_github_repository_deploy_key_test.go +++ b/github/resource_github_repository_deploy_key_test.go @@ -53,10 +53,6 @@ func TestSuppressDeployKeyDiff(t *testing.T) { } func TestAccGithubRepositoryDeployKey_basic(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - testUserEmail := os.Getenv("GITHUB_TEST_USER_EMAIL") if testUserEmail == "" { t.Skip("Skipping because `GITHUB_TEST_USER_EMAIL` is not set") @@ -103,7 +99,7 @@ func testAccCheckGithubRepositoryDeployKeyDestroy(s *terraform.State) error { continue } - orgName := testAccProvider.Meta().(*Owner).name + owner := testAccProvider.Meta().(*Owner).name repoName, idString, err := parseTwoPartID(rs.Primary.ID, "repository", "ID") if err != nil { return err @@ -114,7 +110,7 @@ func testAccCheckGithubRepositoryDeployKeyDestroy(s *terraform.State) error { return unconvertibleIdErr(idString, err) } - _, resp, err := conn.Repositories.GetKey(context.TODO(), orgName, repoName, id) + _, resp, err := conn.Repositories.GetKey(context.TODO(), owner, repoName, id) if err != nil && resp.Response.StatusCode != 404 { return err @@ -137,7 +133,7 @@ func testAccCheckGithubRepositoryDeployKeyExists(n string) resource.TestCheckFun } conn := testAccProvider.Meta().(*Owner).v3client - orgName := testAccProvider.Meta().(*Owner).name + owner := testAccProvider.Meta().(*Owner).name repoName, idString, err := parseTwoPartID(rs.Primary.ID, "repository", "ID") if err != nil { return err @@ -148,7 +144,7 @@ func testAccCheckGithubRepositoryDeployKeyExists(n string) resource.TestCheckFun return unconvertibleIdErr(idString, err) } - _, _, err = conn.Repositories.GetKey(context.TODO(), orgName, repoName, id) + _, _, err = conn.Repositories.GetKey(context.TODO(), owner, repoName, id) if err != nil { return err } diff --git a/github/resource_github_repository_file.go b/github/resource_github_repository_file.go index dbb777f407..e30af03ceb 100644 --- a/github/resource_github_repository_file.go +++ b/github/resource_github_repository_file.go @@ -32,9 +32,9 @@ func resourceGithubRepositoryFile() *schema.Resource { } client := meta.(*Owner).v3client - org := meta.(*Owner).name + owner := meta.(*Owner).name repo, file := splitRepoFilePath(parts[0]) - if err := checkRepositoryFileExists(client, org, repo, file, branch); err != nil { + if err := checkRepositoryFileExists(client, owner, repo, file, branch); err != nil { return nil, err } @@ -135,19 +135,15 @@ func resourceGithubRepositoryFileOptions(d *schema.ResourceData) (*github.Reposi } func resourceGithubRepositoryFileCreate(d *schema.ResourceData, meta interface{}) error { - if err := checkOrganization(meta); err != nil { - return err - } - client := meta.(*Owner).v3client - org := meta.(*Owner).name + owner := meta.(*Owner).name ctx := context.Background() repo := d.Get("repository").(string) file := d.Get("file").(string) branch := d.Get("branch").(string) - if err := checkRepositoryBranchExists(client, org, repo, branch); err != nil { + if err := checkRepositoryBranchExists(client, owner, repo, branch); err != nil { return err } @@ -161,8 +157,8 @@ func resourceGithubRepositoryFileCreate(d *schema.ResourceData, meta interface{} opts.Message = &m } - log.Printf("[DEBUG] Creating repository file: %s/%s/%s in branch: %s", org, repo, file, branch) - resp, _, err := client.Repositories.CreateFile(ctx, org, repo, file, opts) + log.Printf("[DEBUG] Creating repository file: %s/%s/%s in branch: %s", owner, repo, file, branch) + resp, _, err := client.Repositories.CreateFile(ctx, owner, repo, file, opts) if err != nil { return err } @@ -176,28 +172,23 @@ func resourceGithubRepositoryFileCreate(d *schema.ResourceData, meta interface{} } func resourceGithubRepositoryFileRead(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client - org := meta.(*Owner).name + owner := meta.(*Owner).name ctx := context.WithValue(context.Background(), ctxId, d.Id()) repo, file := splitRepoFilePath(d.Id()) branch := d.Get("branch").(string) - if err := checkRepositoryBranchExists(client, org, repo, branch); err != nil { + if err := checkRepositoryBranchExists(client, owner, repo, branch); err != nil { return err } - log.Printf("[DEBUG] Reading repository file: %s/%s/%s, branch: %s", org, repo, file, branch) + log.Printf("[DEBUG] Reading repository file: %s/%s/%s, branch: %s", owner, repo, file, branch) opts := &github.RepositoryContentGetOptions{Ref: branch} - fc, _, _, _ := client.Repositories.GetContents(ctx, org, repo, file, opts) + fc, _, _, _ := client.Repositories.GetContents(ctx, owner, repo, file, opts) if fc == nil { log.Printf("[WARN] Removing repository path %s/%s/%s from state because it no longer exists in GitHub", - org, repo, file) + owner, repo, file) d.SetId("") return nil } @@ -216,19 +207,15 @@ func resourceGithubRepositoryFileRead(d *schema.ResourceData, meta interface{}) } func resourceGithubRepositoryFileUpdate(d *schema.ResourceData, meta interface{}) error { - if err := checkOrganization(meta); err != nil { - return err - } - client := meta.(*Owner).v3client - org := meta.(*Owner).name + owner := meta.(*Owner).name ctx := context.Background() repo := d.Get("repository").(string) file := d.Get("file").(string) branch := d.Get("branch").(string) - if err := checkRepositoryBranchExists(client, org, repo, branch); err != nil { + if err := checkRepositoryBranchExists(client, owner, repo, branch); err != nil { return err } @@ -242,8 +229,8 @@ func resourceGithubRepositoryFileUpdate(d *schema.ResourceData, meta interface{} opts.Message = &m } - log.Printf("[DEBUG] Updating content in repository file: %s/%s/%s", org, repo, file) - resp, _, err := client.Repositories.CreateFile(ctx, org, repo, file, opts) + log.Printf("[DEBUG] Updating content in repository file: %s/%s/%s", owner, repo, file) + resp, _, err := client.Repositories.CreateFile(ctx, owner, repo, file, opts) if err != nil { return err } @@ -256,12 +243,8 @@ func resourceGithubRepositoryFileUpdate(d *schema.ResourceData, meta interface{} } func resourceGithubRepositoryFileDelete(d *schema.ResourceData, meta interface{}) error { - if err := checkOrganization(meta); err != nil { - return err - } - client := meta.(*Owner).v3client - org := meta.(*Owner).name + owner := meta.(*Owner).name ctx := context.Background() repo := d.Get("repository").(string) @@ -276,8 +259,8 @@ func resourceGithubRepositoryFileDelete(d *schema.ResourceData, meta interface{} Branch: &branch, } - log.Printf("[DEBUG] Deleting repository file: %s/%s/%s", org, repo, file) - _, _, err := client.Repositories.DeleteFile(ctx, org, repo, file, opts) + log.Printf("[DEBUG] Deleting repository file: %s/%s/%s", owner, repo, file) + _, _, err := client.Repositories.DeleteFile(ctx, owner, repo, file, opts) if err != nil { return nil } @@ -286,9 +269,9 @@ func resourceGithubRepositoryFileDelete(d *schema.ResourceData, meta interface{} } // checkRepositoryBranchExists tests if a branch exists in a repository. -func checkRepositoryBranchExists(client *github.Client, org, repo, branch string) error { +func checkRepositoryBranchExists(client *github.Client, owner, repo, branch string) error { ctx := context.WithValue(context.Background(), ctxId, buildTwoPartID(repo, branch)) - _, _, err := client.Repositories.GetBranch(ctx, org, repo, branch) + _, _, err := client.Repositories.GetBranch(ctx, owner, repo, branch) if err != nil { if ghErr, ok := err.(*github.ErrorResponse); ok { if ghErr.Response.StatusCode == http.StatusNotFound { @@ -302,14 +285,14 @@ func checkRepositoryBranchExists(client *github.Client, org, repo, branch string } // checkRepositoryFileExists tests if a file exists in a repository. -func checkRepositoryFileExists(client *github.Client, org, repo, file, branch string) error { +func checkRepositoryFileExists(client *github.Client, owner, repo, file, branch string) error { ctx := context.WithValue(context.Background(), ctxId, fmt.Sprintf("%s/%s", repo, file)) - fc, _, _, err := client.Repositories.GetContents(ctx, org, repo, file, &github.RepositoryContentGetOptions{Ref: branch}) + fc, _, _, err := client.Repositories.GetContents(ctx, owner, repo, file, &github.RepositoryContentGetOptions{Ref: branch}) if err != nil { return nil } if fc == nil { - return fmt.Errorf("File %s not a file in in repository %s/%s or repository is not readable", file, org, repo) + return fmt.Errorf("File %s not a file in in repository %s/%s or repository is not readable", file, owner, repo) } return nil diff --git a/github/resource_github_repository_file_test.go b/github/resource_github_repository_file_test.go index b9eaab9f38..881d24fc2c 100644 --- a/github/resource_github_repository_file_test.go +++ b/github/resource_github_repository_file_test.go @@ -49,19 +49,19 @@ func testSweepRepositoryFiles(region string) error { func testSweepDeleteRepositoryFiles(meta interface{}, branch string) error { client := meta.(*Owner).v3client - org := meta.(*Owner).name + owner := meta.(*Owner).name _, files, _, err := client.Repositories.GetContents( - context.TODO(), org, "test-repo", "", &github.RepositoryContentGetOptions{Ref: branch}) + context.TODO(), owner, "test-repo", "", &github.RepositoryContentGetOptions{Ref: branch}) if err != nil { return err } for _, f := range files { if name := f.GetName(); strings.HasPrefix(name, "tf-acc-") { - log.Printf("Deleting repository file: %s, repo: %s/test-repo, branch: %s", name, org, branch) + log.Printf("Deleting repository file: %s, repo: %s/test-repo, branch: %s", name, owner, branch) opts := &github.RepositoryContentFileOptions{Branch: github.String(branch)} - if _, _, err := client.Repositories.DeleteFile(context.TODO(), org, "test-repo", name, opts); err != nil { + if _, _, err := client.Repositories.DeleteFile(context.TODO(), owner, "test-repo", name, opts); err != nil { return err } } @@ -79,10 +79,6 @@ func TestAccGithubRepositoryFile_basic(t *testing.T) { t.Skip("This test requires you to set the test user's email address (set it by exporting GITHUB_TEST_USER_EMAIL)") } - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - var content github.RepositoryContent var commit github.RepositoryCommit @@ -161,10 +157,6 @@ func TestAccGithubRepositoryFile_branch(t *testing.T) { t.Skip("This test requires you to set the test user's email address (set it by exporting GITHUB_TEST_USER_EMAIL)") } - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - var content github.RepositoryContent var commit github.RepositoryCommit @@ -236,10 +228,6 @@ func TestAccGithubRepositoryFile_branch(t *testing.T) { } func TestAccGithubRepositoryFile_committer(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - var content github.RepositoryContent var commit github.RepositoryCommit @@ -322,15 +310,15 @@ func testAccCheckGithubRepositoryFileExists(n, path, branch string, content *git } conn := testAccProvider.Meta().(*Owner).v3client - org := testAccProvider.Meta().(*Owner).name + owner := testAccProvider.Meta().(*Owner).name opts := &github.RepositoryContentGetOptions{Ref: branch} - gotContent, _, _, err := conn.Repositories.GetContents(context.TODO(), org, "test-repo", path, opts) + gotContent, _, _, err := conn.Repositories.GetContents(context.TODO(), owner, "test-repo", path, opts) if err != nil { return err } - gotCommit, err := getFileCommit(conn, org, "test-repo", path, branch) + gotCommit, err := getFileCommit(conn, owner, "test-repo", path, branch) if err != nil { return err } @@ -395,7 +383,7 @@ func testAccCheckGithubRepositoryFileCommitAttributes(commit *github.RepositoryC func testAccCheckGithubRepositoryFileDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*Owner).v3client - org := testAccProvider.Meta().(*Owner).name + owner := testAccProvider.Meta().(*Owner).name for _, rs := range s.RootModule().Resources { if rs.Type != "github_repository_file" { @@ -405,10 +393,10 @@ func testAccCheckGithubRepositoryFileDestroy(s *terraform.State) error { repo, file := splitRepoFilePath(rs.Primary.ID) opts := &github.RepositoryContentGetOptions{Ref: rs.Primary.Attributes["branch"]} - fc, _, resp, err := conn.Repositories.GetContents(context.TODO(), org, repo, file, opts) + fc, _, resp, err := conn.Repositories.GetContents(context.TODO(), owner, repo, file, opts) if err == nil { if fc != nil { - return fmt.Errorf("Repository file %s/%s/%s still exists", org, repo, file) + return fmt.Errorf("Repository file %s/%s/%s still exists", owner, repo, file) } } if resp.StatusCode != 404 { diff --git a/github/resource_github_repository_project.go b/github/resource_github_repository_project.go index 51740ea5c5..270854e22e 100644 --- a/github/resource_github_repository_project.go +++ b/github/resource_github_repository_project.go @@ -57,14 +57,9 @@ func resourceGithubRepositoryProject() *schema.Resource { } func resourceGithubRepositoryProjectCreate(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client - orgName := meta.(*Owner).name + owner := meta.(*Owner).name repoName := d.Get("repository").(string) name := d.Get("name").(string) body := d.Get("body").(string) @@ -75,9 +70,9 @@ func resourceGithubRepositoryProjectCreate(d *schema.ResourceData, meta interfac } ctx := context.Background() - log.Printf("[DEBUG] Creating repository project: %s (%s/%s)", name, orgName, repoName) + log.Printf("[DEBUG] Creating repository project: %s (%s/%s)", name, owner, repoName) project, _, err := client.Repositories.CreateProject(ctx, - orgName, repoName, &options) + owner, repoName, &options) if err != nil { return err } @@ -87,13 +82,8 @@ func resourceGithubRepositoryProjectCreate(d *schema.ResourceData, meta interfac } func resourceGithubRepositoryProjectRead(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client - orgName := meta.(*Owner).name + owner := meta.(*Owner).name projectID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -125,7 +115,7 @@ func resourceGithubRepositoryProjectRead(d *schema.ResourceData, meta interface{ d.Set("name", project.GetName()) d.Set("body", project.GetBody()) d.Set("url", fmt.Sprintf("https://github.com/%s/%s/projects/%d", - orgName, d.Get("repository"), project.GetNumber())) + owner, d.Get("repository"), project.GetNumber())) return nil } diff --git a/github/resource_github_repository_project_test.go b/github/resource_github_repository_project_test.go index b0a5931e81..e0e4abd532 100644 --- a/github/resource_github_repository_project_test.go +++ b/github/resource_github_repository_project_test.go @@ -15,10 +15,6 @@ import ( ) func TestAccGithubRepositoryProject_basic(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - randRepoName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) var project github.Project diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index cef11471fc..82c22e1173 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -51,10 +51,6 @@ func testSweepRepositories(region string) error { } func TestAccGithubRepository_basic(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - var repo github.Repository rn := "github_repository.foo" @@ -120,10 +116,6 @@ func TestAccGithubRepository_basic(t *testing.T) { } func TestAccGithubRepository_archive(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - var repo github.Repository rn := "github_repository.foo" @@ -168,10 +160,6 @@ func TestAccGithubRepository_archive(t *testing.T) { } func TestAccGithubRepository_archiveUpdate(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - var repo github.Repository rn := "github_repository.foo" @@ -232,10 +220,6 @@ func TestAccGithubRepository_archiveUpdate(t *testing.T) { } func TestAccGithubRepository_hasProjects(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - rn := "github_repository.foo" randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) @@ -260,10 +244,6 @@ func TestAccGithubRepository_hasProjects(t *testing.T) { } func TestAccGithubRepository_defaultBranch(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - var repo github.Repository rn := "github_repository.foo" @@ -334,10 +314,6 @@ func TestAccGithubRepository_defaultBranch(t *testing.T) { } func TestAccGithubRepository_templates(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - var repo github.Repository rn := "github_repository.foo" @@ -385,10 +361,6 @@ func TestAccGithubRepository_templates(t *testing.T) { } func TestAccGithubRepository_topics(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - var repo github.Repository rn := "github_repository.foo" @@ -480,10 +452,6 @@ func TestAccGithubRepository_topics(t *testing.T) { } func TestAccGithubRepository_createFromTemplate(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - var repo github.Repository rn := "github_repository.foo" diff --git a/github/resource_github_repository_webhook.go b/github/resource_github_repository_webhook.go index 5925acc91a..1933b9c757 100644 --- a/github/resource_github_repository_webhook.go +++ b/github/resource_github_repository_webhook.go @@ -98,20 +98,15 @@ func resourceGithubRepositoryWebhookObject(d *schema.ResourceData) *github.Hook } func resourceGithubRepositoryWebhookCreate(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client - orgName := meta.(*Owner).name + owner := meta.(*Owner).name repoName := d.Get("repository").(string) hk := resourceGithubRepositoryWebhookObject(d) ctx := context.Background() - log.Printf("[DEBUG] Creating repository webhook: %d (%s/%s)", hk.GetID(), orgName, repoName) - hook, _, err := client.Repositories.CreateHook(ctx, orgName, repoName, hk) + log.Printf("[DEBUG] Creating repository webhook: %d (%s/%s)", hk.GetID(), owner, repoName) + hook, _, err := client.Repositories.CreateHook(ctx, owner, repoName, hk) if err != nil { return err } @@ -132,14 +127,9 @@ func resourceGithubRepositoryWebhookCreate(d *schema.ResourceData, meta interfac } func resourceGithubRepositoryWebhookRead(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client - orgName := meta.(*Owner).name + owner := meta.(*Owner).name repoName := d.Get("repository").(string) hookID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -150,8 +140,8 @@ func resourceGithubRepositoryWebhookRead(d *schema.ResourceData, meta interface{ ctx = context.WithValue(ctx, ctxEtag, d.Get("etag").(string)) } - log.Printf("[DEBUG] Reading repository webhook: %s (%s/%s)", d.Id(), orgName, repoName) - hook, _, err := client.Repositories.GetHook(ctx, orgName, repoName, hookID) + log.Printf("[DEBUG] Reading repository webhook: %s (%s/%s)", d.Id(), owner, repoName) + hook, _, err := client.Repositories.GetHook(ctx, owner, repoName, hookID) if err != nil { if ghErr, ok := err.(*github.ErrorResponse); ok { if ghErr.Response.StatusCode == http.StatusNotModified { @@ -190,14 +180,9 @@ func resourceGithubRepositoryWebhookRead(d *schema.ResourceData, meta interface{ } func resourceGithubRepositoryWebhookUpdate(d *schema.ResourceData, meta interface{}) error { - err := checkOrganization(meta) - if err != nil { - return err - } - client := meta.(*Owner).v3client - orgName := meta.(*Owner).name + owner := meta.(*Owner).name repoName := d.Get("repository").(string) hk := resourceGithubRepositoryWebhookObject(d) hookID, err := strconv.ParseInt(d.Id(), 10, 64) @@ -206,8 +191,8 @@ func resourceGithubRepositoryWebhookUpdate(d *schema.ResourceData, meta interfac } ctx := context.WithValue(context.Background(), ctxId, d.Id()) - log.Printf("[DEBUG] Updating repository webhook: %s (%s/%s)", d.Id(), orgName, repoName) - _, _, err = client.Repositories.EditHook(ctx, orgName, repoName, hookID, hk) + log.Printf("[DEBUG] Updating repository webhook: %s (%s/%s)", d.Id(), owner, repoName) + _, _, err = client.Repositories.EditHook(ctx, owner, repoName, hookID, hk) if err != nil { return err } @@ -218,7 +203,7 @@ func resourceGithubRepositoryWebhookUpdate(d *schema.ResourceData, meta interfac func resourceGithubRepositoryWebhookDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*Owner).v3client - orgName := meta.(*Owner).name + owner := meta.(*Owner).name repoName := d.Get("repository").(string) hookID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { @@ -226,8 +211,8 @@ func resourceGithubRepositoryWebhookDelete(d *schema.ResourceData, meta interfac } ctx := context.WithValue(context.Background(), ctxId, d.Id()) - log.Printf("[DEBUG] Deleting repository webhook: %s (%s/%s)", d.Id(), orgName, repoName) - _, err = client.Repositories.DeleteHook(ctx, orgName, repoName, hookID) + log.Printf("[DEBUG] Deleting repository webhook: %s (%s/%s)", d.Id(), owner, repoName) + _, err = client.Repositories.DeleteHook(ctx, owner, repoName, hookID) return err } diff --git a/github/resource_github_repository_webhook_test.go b/github/resource_github_repository_webhook_test.go index dbfc9021ea..e69cb5d980 100644 --- a/github/resource_github_repository_webhook_test.go +++ b/github/resource_github_repository_webhook_test.go @@ -15,10 +15,6 @@ import ( ) func TestAccGithubRepositoryWebhook_basic(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - rn := "github_repository_webhook.foo" randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) var hook github.Hook @@ -69,10 +65,6 @@ func TestAccGithubRepositoryWebhook_basic(t *testing.T) { } func TestAccGithubRepositoryWebhook_secret(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - rn := "github_repository_webhook.foo" randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) var hook github.Hook @@ -124,9 +116,9 @@ func testAccCheckGithubRepositoryWebhookExists(n string, repoName string, hook * return fmt.Errorf("No repository name is set") } - org := testAccProvider.Meta().(*Owner) - conn := org.v3client - getHook, _, err := conn.Repositories.GetHook(context.TODO(), org.name, repoName, hookID) + conn := testAccProvider.Meta().(*Owner).v3client + owner := testAccProvider.Meta().(*Owner).name + getHook, _, err := conn.Repositories.GetHook(context.TODO(), owner, repoName, hookID) if err != nil { return err } @@ -163,7 +155,7 @@ func testAccCheckGithubRepositoryWebhookAttributes(hook *github.Hook, want *test func testAccCheckGithubRepositoryWebhookDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*Owner).v3client - orgName := testAccProvider.Meta().(*Owner).name + owner := testAccProvider.Meta().(*Owner).name for _, rs := range s.RootModule().Resources { if rs.Type != "github_repository_webhook" { @@ -175,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(), owner, rs.Primary.Attributes["repository"], id) if err == nil { if gotHook != nil && gotHook.GetID() == id { return fmt.Errorf("Webhook still exists") diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index 06f13fd17a..4562b5d1fd 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -2,16 +2,13 @@ layout: "github" page_title: "GitHub: github_repository" description: |- - Creates and manages repositories within GitHub organizations + Creates and manages repositories within GitHub organizations or personal accounts --- # github_repository This resource allows you to create and manage repositories within your -GitHub organization. - -This resource cannot currently be used to manage *personal* repositories, -outside of organizations. +GitHub organization or personal account. ## Example Usage diff --git a/website/docs/r/repository_webhook.html.markdown b/website/docs/r/repository_webhook.html.markdown index d589af7959..5456b3d677 100644 --- a/website/docs/r/repository_webhook.html.markdown +++ b/website/docs/r/repository_webhook.html.markdown @@ -2,16 +2,13 @@ layout: "github" page_title: "GitHub: github_repository_webhook" description: |- - Creates and manages repository webhooks within GitHub organizations + Creates and manages repository webhooks within GitHub organizations or personal accounts --- # github_repository_webhook This resource allows you to create and manage webhooks for repositories within your -GitHub organization. - -This resource cannot currently be used to manage webhooks for *personal* repositories, -outside of organizations. +GitHub organization or personal account. ## Example Usage