Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Adding merge types to repository resource #1

Merged
merged 1 commit into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ func resourceGithubRepository() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"allow_merge_commit": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"allow_squash_merge": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"allow_rebase_merge": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"has_downloads": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -89,18 +104,24 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository {
private := d.Get("private").(bool)
hasIssues := d.Get("has_issues").(bool)
hasWiki := d.Get("has_wiki").(bool)
allowMergeCommit := d.Get("allow_merge_commit").(bool)
allowSquashMerge := d.Get("allow_squash_merge").(bool)
allowRebaseMerge := d.Get("allow_rebase_merge").(bool)
hasDownloads := d.Get("has_downloads").(bool)
autoInit := d.Get("auto_init").(bool)

repo := &github.Repository{
Name: &name,
Description: &description,
Homepage: &homepageUrl,
Private: &private,
HasIssues: &hasIssues,
HasWiki: &hasWiki,
HasDownloads: &hasDownloads,
AutoInit: &autoInit,
Name: &name,
Description: &description,
Homepage: &homepageUrl,
Private: &private,
HasIssues: &hasIssues,
HasWiki: &hasWiki,
AllowMergeCommit: &allowMergeCommit,
AllowSquashMerge: &allowSquashMerge,
AllowRebaseMerge: &allowRebaseMerge,
HasDownloads: &hasDownloads,
AutoInit: &autoInit,
}

return repo
Expand Down Expand Up @@ -144,6 +165,9 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro
d.Set("private", repo.Private)
d.Set("has_issues", repo.HasIssues)
d.Set("has_wiki", repo.HasWiki)
d.Set("allow_merge_commit", repo.AllowMergeCommit)
d.Set("allow_squash_merge", repo.AllowSquashMerge)
d.Set("allow_rebase_merge", repo.AllowRebaseMerge)
d.Set("has_downloads", repo.HasDownloads)
d.Set("full_name", repo.FullName)
d.Set("default_branch", repo.DefaultBranch)
Expand Down
60 changes: 42 additions & 18 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ func TestAccGithubRepository_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubRepositoryExists("github_repository.foo", &repo),
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{
Name: name,
Description: description,
Homepage: "http://example.com/",
HasIssues: true,
HasWiki: true,
HasDownloads: true,
DefaultBranch: "master",
Name: name,
Description: description,
Homepage: "http://example.com/",
HasIssues: true,
HasWiki: true,
AllowMergeCommit: false,
AllowSquashMerge: false,
AllowRebaseMerge: false,
HasDownloads: true,
DefaultBranch: "master",
}),
),
},
Expand All @@ -43,10 +46,13 @@ func TestAccGithubRepository_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubRepositoryExists("github_repository.foo", &repo),
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{
Name: name,
Description: "Updated " + description,
Homepage: "http://example.com/",
DefaultBranch: "master",
Name: name,
Description: "Updated " + description,
Homepage: "http://example.com/",
AllowMergeCommit: true,
AllowSquashMerge: true,
AllowRebaseMerge: true,
DefaultBranch: "master",
}),
),
},
Expand Down Expand Up @@ -98,13 +104,16 @@ func testAccCheckGithubRepositoryExists(n string, repo *github.Repository) resou
}

type testAccGithubRepositoryExpectedAttributes struct {
Name string
Description string
Homepage string
Private bool
HasIssues bool
HasWiki bool
HasDownloads bool
Name string
Description string
Homepage string
Private bool
HasIssues bool
HasWiki bool
AllowMergeCommit bool
AllowSquashMerge bool
AllowRebaseMerge bool
HasDownloads bool

DefaultBranch string
}
Expand All @@ -130,6 +139,15 @@ func testAccCheckGithubRepositoryAttributes(repo *github.Repository, want *testA
if *repo.HasWiki != want.HasWiki {
return fmt.Errorf("got has wiki %#v; want %#v", *repo.HasWiki, want.HasWiki)
}
if *repo.AllowMergeCommit != want.AllowMergeCommit {
return fmt.Errorf("got allow merge commit %#v; want %#v", *repo.AllowMergeCommit, want.AllowMergeCommit)
}
if *repo.AllowSquashMerge != want.AllowSquashMerge {
return fmt.Errorf("got allow squash merge %#v; want %#v", *repo.AllowSquashMerge, want.AllowSquashMerge)
}
if *repo.AllowRebaseMerge != want.AllowRebaseMerge {
return fmt.Errorf("got allow rebase merge %#v; want %#v", *repo.AllowRebaseMerge, want.AllowRebaseMerge)
}
if *repo.HasDownloads != want.HasDownloads {
return fmt.Errorf("got has downloads %#v; want %#v", *repo.HasDownloads, want.HasDownloads)
}
Expand Down Expand Up @@ -208,6 +226,9 @@ resource "github_repository" "foo" {

has_issues = true
has_wiki = true
allow_merge_commit = false
allow_squash_merge = false
allow_rebase_merge = false
has_downloads = true
}
`, randString, randString)
Expand All @@ -226,6 +247,9 @@ resource "github_repository" "foo" {

has_issues = false
has_wiki = false
allow_merge_commit = true
allow_squash_merge = true
allow_rebase_merge = true
has_downloads = false
}
`, randString, randString)
Expand Down
8 changes: 7 additions & 1 deletion website/docs/r/repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ The following arguments are supported:
* `has_wiki` - (Optional) Set to `true` to enable the Github Wiki features on
the repository.

* `allow_merge_commit` - (Optional) Set to `false` to disable merge commits on the repository.

* `allow_squash_merge` - (Optional) Set to `false` to disable squash merges on the repository.

* `allow_rebase_merge` - (Optional) Set to `false` to disable rebase merges on the repository.

* `has_downloads` - (Optional) Set to `true` to enable the (deprecated)
downloads features on the repository.

Expand All @@ -69,7 +75,7 @@ The following additional attributes are exported:

* `svn_url` - URL that can be provided to `svn checkout` to check out
the repository via Github's Subversion protocol emulation.


## Import

Expand Down