Skip to content

Commit

Permalink
Merge pull request integrations#64 from terraform-providers/archived
Browse files Browse the repository at this point in the history
`github_repository` - adding support for `archived` repositories
  • Loading branch information
paultyng authored May 8, 2018
2 parents 341093b + f47fd58 commit 9b15a7b
Show file tree
Hide file tree
Showing 22 changed files with 3,914 additions and 248 deletions.
11 changes: 10 additions & 1 deletion github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func resourceGithubRepository() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"archived": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"full_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -122,6 +127,7 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository {
autoInit := d.Get("auto_init").(bool)
licenseTemplate := d.Get("license_template").(string)
gitIgnoreTemplate := d.Get("gitignore_template").(string)
archived := d.Get("archived").(bool)

repo := &github.Repository{
Name: &name,
Expand All @@ -137,6 +143,7 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository {
AutoInit: &autoInit,
LicenseTemplate: &licenseTemplate,
GitignoreTemplate: &gitIgnoreTemplate,
Archived: &archived,
}

return repo
Expand All @@ -157,7 +164,7 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er
}
d.SetId(*repo.Name)

return resourceGithubRepositoryRead(d, meta)
return resourceGithubRepositoryUpdate(d, meta)
}

func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) error {
Expand All @@ -178,6 +185,7 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro
}
return err
}

d.Set("name", repoName)
d.Set("description", repo.Description)
d.Set("homepage_url", repo.Homepage)
Expand All @@ -194,6 +202,7 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro
d.Set("svn_url", repo.SVNURL)
d.Set("git_clone_url", repo.GitURL)
d.Set("http_clone_url", repo.CloneURL)
d.Set("archived", repo.Archived)
return nil
}

Expand Down
25 changes: 15 additions & 10 deletions github/resource_github_repository_deploy_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ import (
"strconv"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

const testRepo string = "test-repo"

func TestAccGithubRepositoryDeployKey_basic(t *testing.T) {
rs := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
repositoryName := fmt.Sprintf("acctest-%s", rs)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGithubRepositoryDeployKeyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccGithubRepositoryDeployKeyConfig,
{
Config: testAccGithubRepositoryDeployKeyConfig(repositoryName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubRepositoryDeployKeyExists("github_repository_deploy_key.test_repo_deploy_key"),
resource.TestCheckResourceAttr("github_repository_deploy_key.test_repo_deploy_key", "read_only", "false"),
resource.TestCheckResourceAttr("github_repository_deploy_key.test_repo_deploy_key", "repository", testRepo),
resource.TestCheckResourceAttr("github_repository_deploy_key.test_repo_deploy_key", "repository", repositoryName),
resource.TestCheckResourceAttr("github_repository_deploy_key.test_repo_deploy_key", "key", testAccGithubRepositoryDeployKeytestDeployKey),
resource.TestCheckResourceAttr("github_repository_deploy_key.test_repo_deploy_key", "title", "title"),
),
Expand All @@ -33,15 +34,17 @@ func TestAccGithubRepositoryDeployKey_basic(t *testing.T) {
}

func TestAccGithubRepositoryDeployKey_importBasic(t *testing.T) {
rs := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
repositoryName := fmt.Sprintf("acctest-%s", rs)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGithubRepositoryDeployKeyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccGithubRepositoryDeployKeyConfig,
{
Config: testAccGithubRepositoryDeployKeyConfig(repositoryName),
},
resource.TestStep{
{
ResourceName: "github_repository_deploy_key.test_repo_deploy_key",
ImportState: true,
ImportStateVerify: true,
Expand Down Expand Up @@ -106,7 +109,8 @@ func testAccCheckGithubRepositoryDeployKeyExists(n string) resource.TestCheckFun

const testAccGithubRepositoryDeployKeytestDeployKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDnDk1liOxXwE27fjOVVHl6RNVgQznGqGIfhsoa5QNfLOcoWJR3EIv44dSUx1GSvxQ7uR9qBY/i/SEdAbKdupo3Ru5sykc0GqaMRVys+Cin/Lgnl6+ntmTZOudNjIbz10Vfu/dKmexSzqlD3XWzPGXRI5WyKWzvc2XKjRdfnOOzogJpqJ5kh/CN0ZhCzBPTu/b4mJl2ionTEzEeLK2g4Re4IuU/dGoyf0LGLidjmqhSY7dQtL+mfte9m3x/BQTrDf0+AW3kGWXR8EL0EyIJ2HRtHW67YnoOcTAFK0hDCuKgvt78rqdUQ2bVjcsIhNqnvQMPf3ZeZ5bP2JqB9zKaFl8uaRJv+TdxEeFTkgnbYb85M+aBggBYr6xxeb24g7WlU0iPxJ8GmjvCizxe2I1DOJDRDozn1sinKjapNRdJy00iuo46TJC5Wgmid0vnMJ7SMZtubz+btxhoFLt4F4U2JnILaYG4/buJg4H/GkqmkE8G3hr4b4mgsFXBtBFgK6uCTFQSvvV7TyyWkZxHL6DRCxL/Dp0bSj+EM8Tw1K304EvkBEO3rMyvPs4nXL7pepyKWalmUI8U4Qp2xMXSq7fmfZY55osb03MUAtKl0wJ/ykyKOwYWeLbubSVcc6VPx5bXZmnM5bTcZdYW9+vNt86X2F2b0h/sIkGNEPpqQQBzElY+fQ=="

var testAccGithubRepositoryDeployKeyConfig = fmt.Sprintf(`
func testAccGithubRepositoryDeployKeyConfig(name string) string {
return fmt.Sprintf(`
resource "github_repository" "test_repo" {
name = "%s"
}
Expand All @@ -117,4 +121,5 @@ var testAccGithubRepositoryDeployKeyConfig = fmt.Sprintf(`
repository = "${github_repository.test_repo.name}"
title = "title"
}
`, testRepo, testAccGithubRepositoryDeployKeytestDeployKey)
`, name, testAccGithubRepositoryDeployKeytestDeployKey)
}
115 changes: 115 additions & 0 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func TestAccGithubRepository_basic(t *testing.T) {
AllowRebaseMerge: false,
HasDownloads: true,
DefaultBranch: "master",
Archived: false,
}),
),
},
Expand All @@ -89,6 +90,94 @@ func TestAccGithubRepository_basic(t *testing.T) {
AllowSquashMerge: true,
AllowRebaseMerge: true,
DefaultBranch: "master",
Archived: false,
}),
),
},
},
})
}

func TestAccGithubRepository_archive(t *testing.T) {
var repo github.Repository
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
name := fmt.Sprintf("tf-acc-test-%s", randString)
description := fmt.Sprintf("Terraform acceptance tests %s", randString)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGithubRepositoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubRepositoryArchivedConfig(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubRepositoryExists("github_repository.foo", &repo),
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{
Name: name,
Description: description,
Homepage: "http://example.com/",
HasIssues: true,
HasWiki: true,
AllowMergeCommit: true,
AllowSquashMerge: false,
AllowRebaseMerge: false,
HasDownloads: true,
DefaultBranch: "master",
Archived: true,
}),
),
},
},
})
}

func TestAccGithubRepository_archiveUpdate(t *testing.T) {
var repo github.Repository
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
name := fmt.Sprintf("tf-acc-test-%s", randString)
description := fmt.Sprintf("Terraform acceptance tests %s", randString)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGithubRepositoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubRepositoryConfig(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubRepositoryExists("github_repository.foo", &repo),
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{
Name: name,
Description: description,
Homepage: "http://example.com/",
HasIssues: true,
HasWiki: true,
AllowMergeCommit: true,
AllowSquashMerge: false,
AllowRebaseMerge: false,
HasDownloads: true,
DefaultBranch: "master",
Archived: false,
}),
),
},
{
Config: testAccGithubRepositoryArchivedConfig(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubRepositoryExists("github_repository.foo", &repo),
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{
Name: name,
Description: description,
Homepage: "http://example.com/",
HasIssues: true,
HasWiki: true,
AllowMergeCommit: true,
AllowSquashMerge: false,
AllowRebaseMerge: false,
HasDownloads: true,
DefaultBranch: "master",
Archived: true,
}),
),
},
Expand Down Expand Up @@ -143,6 +232,7 @@ func TestAccGithubRepository_defaultBranch(t *testing.T) {
AllowRebaseMerge: false,
HasDownloads: true,
DefaultBranch: "master",
Archived: false,
}),
),
},
Expand All @@ -165,6 +255,7 @@ func TestAccGithubRepository_defaultBranch(t *testing.T) {
AllowRebaseMerge: false,
HasDownloads: true,
DefaultBranch: "foo",
Archived: false,
}),
),
},
Expand Down Expand Up @@ -201,6 +292,7 @@ func TestAccGithubRepository_templates(t *testing.T) {
DefaultBranch: "master",
LicenseTemplate: "ms-pl",
GitignoreTemplate: "C++",
Archived: false,
}),
),
},
Expand Down Expand Up @@ -246,6 +338,7 @@ type testAccGithubRepositoryExpectedAttributes struct {
DefaultBranch string
LicenseTemplate string
GitignoreTemplate string
Archived bool
}

func testAccCheckGithubRepositoryAttributes(repo *github.Repository, want *testAccGithubRepositoryExpectedAttributes) resource.TestCheckFunc {
Expand Down Expand Up @@ -439,6 +532,28 @@ resource "github_repository" "foo" {
`, randString, randString)
}

func testAccGithubRepositoryArchivedConfig(randString string) string {
return fmt.Sprintf(`
resource "github_repository" "foo" {
name = "tf-acc-test-%s"
description = "Terraform acceptance tests %s"
homepage_url = "http://example.com/"
# So that acceptance tests can be run in a github organization
# with no billing
private = false
has_issues = true
has_wiki = true
allow_merge_commit = true
allow_squash_merge = false
allow_rebase_merge = false
has_downloads = true
archived = true
}
`, randString, randString)
}

func testAccGithubRepositoryConfigDefaultBranch(randString string) string {
return fmt.Sprintf(`
resource "github_repository" "foo" {
Expand Down
14 changes: 8 additions & 6 deletions github/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error {
n := d.Get("name").(string)
desc := d.Get("description").(string)
p := d.Get("privacy").(string)
githubTeam, _, err := client.Organizations.CreateTeam(context.TODO(), meta.(*Organization).name, &github.Team{
Name: &n,
githubTeam, _, err := client.Organizations.CreateTeam(context.TODO(), meta.(*Organization).name, &github.NewTeam{
Name: n,
Description: &desc,
Privacy: &p,
})
Expand Down Expand Up @@ -96,11 +96,13 @@ func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
description := d.Get("description").(string)
privacy := d.Get("privacy").(string)
team.Description = &description
team.Name = &name
team.Privacy = &privacy
editedTeam := github.NewTeam{
Name: name,
Description: &description,
Privacy: &privacy,
}

team, _, err = client.Organizations.EditTeam(context.TODO(), *team.ID, team)
team, _, err = client.Organizations.EditTeam(context.TODO(), *team.ID, &editedTeam)
if err != nil {
return err
}
Expand Down

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

Loading

0 comments on commit 9b15a7b

Please sign in to comment.