Skip to content

Commit

Permalink
Add support for use_squash_pr_title_as_default on repo
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettheel committed Jul 15, 2022
1 parent 1bd34d6 commit 9c8be54
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
5 changes: 5 additions & 0 deletions github/data_source_github_repository.go
Expand Up @@ -84,6 +84,10 @@ func dataSourceGithubRepository() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"use_squash_pr_title_as_default": {
Type: schema.TypeBool,
Computed: true,
},
"default_branch": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -234,6 +238,7 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er
d.Set("allow_squash_merge", repo.GetAllowSquashMerge())
d.Set("allow_rebase_merge", repo.GetAllowRebaseMerge())
d.Set("allow_auto_merge", repo.GetAllowAutoMerge())
d.Set("use_squash_pr_title_as_default", repo.GetUseSquashPRTitleAsDefault())
d.Set("has_downloads", repo.GetHasDownloads())
d.Set("full_name", repo.GetFullName())
d.Set("default_branch", repo.GetDefaultBranch())
Expand Down
45 changes: 26 additions & 19 deletions github/resource_github_repository.go
Expand Up @@ -94,6 +94,11 @@ func resourceGithubRepository() *schema.Resource {
Optional: true,
Default: false,
},
"use_squash_pr_title_as_default": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"delete_branch_on_merge": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -282,25 +287,26 @@ func calculateVisibility(d *schema.ResourceData) string {

func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository {
return &github.Repository{
Name: github.String(d.Get("name").(string)),
Description: github.String(d.Get("description").(string)),
Homepage: github.String(d.Get("homepage_url").(string)),
Visibility: github.String(calculateVisibility(d)),
HasDownloads: github.Bool(d.Get("has_downloads").(bool)),
HasIssues: github.Bool(d.Get("has_issues").(bool)),
HasProjects: github.Bool(d.Get("has_projects").(bool)),
HasWiki: github.Bool(d.Get("has_wiki").(bool)),
IsTemplate: github.Bool(d.Get("is_template").(bool)),
AllowMergeCommit: github.Bool(d.Get("allow_merge_commit").(bool)),
AllowSquashMerge: github.Bool(d.Get("allow_squash_merge").(bool)),
AllowRebaseMerge: github.Bool(d.Get("allow_rebase_merge").(bool)),
AllowAutoMerge: github.Bool(d.Get("allow_auto_merge").(bool)),
DeleteBranchOnMerge: github.Bool(d.Get("delete_branch_on_merge").(bool)),
AutoInit: github.Bool(d.Get("auto_init").(bool)),
LicenseTemplate: github.String(d.Get("license_template").(string)),
GitignoreTemplate: github.String(d.Get("gitignore_template").(string)),
Archived: github.Bool(d.Get("archived").(bool)),
Topics: expandStringList(d.Get("topics").(*schema.Set).List()),
Name: github.String(d.Get("name").(string)),
Description: github.String(d.Get("description").(string)),
Homepage: github.String(d.Get("homepage_url").(string)),
Visibility: github.String(calculateVisibility(d)),
HasDownloads: github.Bool(d.Get("has_downloads").(bool)),
HasIssues: github.Bool(d.Get("has_issues").(bool)),
HasProjects: github.Bool(d.Get("has_projects").(bool)),
HasWiki: github.Bool(d.Get("has_wiki").(bool)),
IsTemplate: github.Bool(d.Get("is_template").(bool)),
AllowMergeCommit: github.Bool(d.Get("allow_merge_commit").(bool)),
AllowSquashMerge: github.Bool(d.Get("allow_squash_merge").(bool)),
AllowRebaseMerge: github.Bool(d.Get("allow_rebase_merge").(bool)),
AllowAutoMerge: github.Bool(d.Get("allow_auto_merge").(bool)),
UseSquashPRTitleAsDefault: github.Bool(d.Get("use_squash_pr_title_as_default").(bool)),
DeleteBranchOnMerge: github.Bool(d.Get("delete_branch_on_merge").(bool)),
AutoInit: github.Bool(d.Get("auto_init").(bool)),
LicenseTemplate: github.String(d.Get("license_template").(string)),
GitignoreTemplate: github.String(d.Get("gitignore_template").(string)),
Archived: github.Bool(d.Get("archived").(bool)),
Topics: expandStringList(d.Get("topics").(*schema.Set).List()),
}
}

Expand Down Expand Up @@ -440,6 +446,7 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro
d.Set("allow_squash_merge", repo.GetAllowSquashMerge())
d.Set("allow_rebase_merge", repo.GetAllowRebaseMerge())
d.Set("allow_auto_merge", repo.GetAllowAutoMerge())
d.Set("use_squash_pr_title_as_default", repo.GetUseSquashPRTitleAsDefault())
d.Set("delete_branch_on_merge", repo.GetDeleteBranchOnMerge())
d.Set("has_downloads", repo.GetHasDownloads())
d.Set("full_name", repo.GetFullName())
Expand Down
21 changes: 13 additions & 8 deletions github/resource_github_repository_test.go
Expand Up @@ -24,14 +24,15 @@ func TestAccGithubRepositories(t *testing.T) {
name = "tf-acc-test-create-%[1]s"
description = "Terraform acceptance tests %[1]s"
has_issues = true
has_wiki = true
has_downloads = true
allow_merge_commit = true
allow_squash_merge = false
allow_rebase_merge = false
allow_auto_merge = true
auto_init = false
has_issues = true
has_wiki = true
has_downloads = true
allow_merge_commit = true
allow_squash_merge = false
allow_rebase_merge = false
allow_auto_merge = true
use_squash_pr_title_as_default = true
auto_init = false
}
`, randomID)
Expand All @@ -45,6 +46,10 @@ func TestAccGithubRepositories(t *testing.T) {
"github_repository.test", "allow_auto_merge",
"true",
),
resource.TestCheckResourceAttr(
"github_repository.test", "use_squash_pr_title_as_default",
"true",
),
)

testCase := func(t *testing.T, mode string) {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/repository.html.markdown
Expand Up @@ -53,6 +53,8 @@ The following arguments are supported:

* `allow_auto_merge` - Whether the repository allows auto-merging pull requests.

* `use_squash_pr_title_as_default` - Whether the repository defaults to using PR titles for squash merge commit messages.

* `has_downloads` - Whether the repository has Downloads feature enabled.

* `default_branch` - The name of the default branch of the repository.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/repository.html.markdown
Expand Up @@ -77,6 +77,8 @@ The following arguments are supported:

* `allow_auto_merge` - (Optional) Set to `true` to allow auto-merging pull requests on the repository.

* `use_squash_pr_title_as_default` - (Optional) Set to `true` to default to using PR titles for squash merge commit messages on the repository.

* `delete_branch_on_merge` - (Optional) Automatically delete head branch after a pull request is merged. Defaults to `false`.

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

0 comments on commit 9c8be54

Please sign in to comment.