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

Add support for default merge commit params #1263

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
20 changes: 20 additions & 0 deletions github/data_source_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ func dataSourceGithubRepository() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"squash_merge_commit_title": {
Type: schema.TypeString,
Computed: true,
},
"squash_merge_commit_message": {
Type: schema.TypeString,
Computed: true,
},
"merge_commit_title": {
Type: schema.TypeString,
Computed: true,
},
"merge_commit_message": {
Type: schema.TypeString,
Computed: true,
},
"default_branch": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -234,6 +250,10 @@ 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("squash_merge_commit_title", repo.GetSquashMergeCommitTitle())
d.Set("squash_merge_commit_message", repo.GetSquashMergeCommitMessage())
d.Set("merge_commit_title", repo.GetMergeCommitTitle())
d.Set("merge_commit_message", repo.GetMergeCommitMessage())
d.Set("has_downloads", repo.GetHasDownloads())
d.Set("full_name", repo.GetFullName())
d.Set("default_branch", repo.GetDefaultBranch())
Expand Down
66 changes: 47 additions & 19 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ func resourceGithubRepository() *schema.Resource {
Optional: true,
Default: false,
},
"squash_merge_commit_title": {
Type: schema.TypeString,
Optional: true,
Default: "COMMIT_OR_PR_TITLE",
},
"squash_merge_commit_message": {
Type: schema.TypeString,
Optional: true,
Default: "COMMIT_MESSAGES",
},
"merge_commit_title": {
Type: schema.TypeString,
Optional: true,
Default: "MERGE_MESSAGE",
},
"merge_commit_message": {
Type: schema.TypeString,
Optional: true,
Default: "PR_TITLE",
},
"delete_branch_on_merge": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -282,25 +302,29 @@ 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)),
SquashMergeCommitTitle: github.String(d.Get("squash_merge_commit_title").(string)),
SquashMergeCommitMessage: github.String(d.Get("squash_merge_commit_message").(string)),
MergeCommitTitle: github.String(d.Get("merge_commit_title").(string)),
MergeCommitMessage: github.String(d.Get("merge_commit_message").(string)),
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 +464,10 @@ 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("squash_merge_commit_title", repo.GetSquashMergeCommitTitle())
d.Set("squash_merge_commit_message", repo.GetSquashMergeCommitMessage())
d.Set("merge_commit_title", repo.GetMergeCommitTitle())
d.Set("merge_commit_message", repo.GetMergeCommitMessage())
d.Set("delete_branch_on_merge", repo.GetDeleteBranchOnMerge())
d.Set("has_downloads", repo.GetHasDownloads())
d.Set("full_name", repo.GetFullName())
Expand Down
22 changes: 14 additions & 8 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ 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
merge_commit_title = "MERGE_MESSAGE"
merge_commit_message = "PR_TITLE"
auto_init = false

}
`, randomID)
Expand All @@ -45,6 +47,10 @@ func TestAccGithubRepositories(t *testing.T) {
"github_repository.test", "allow_auto_merge",
"true",
),
resource.TestCheckResourceAttr(
"github_repository.test", "merge_commit_title",
"MERGE_MESSAGE",
),
)

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

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

* `squash_merge_commit_title` - The default value for a squash merge commit title.

* `squash_merge_commit_message` - The default value for a squash merge commit message.

* `merge_commit_title` - The default value for a merge commit title.

* `merge_commit_message` - The default value for a merge commit message.

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

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

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

* `squash_merge_commit_title` - (Optional) Can be `PR_TITLE` or `COMMIT_OR_PR_TITLE` for a default squash merge commit title.

* `squash_merge_commit_message` - (Optional) Can be `PR_BODY`, `COMMIT_MESSAGES`, or `BLANK` for a default squash merge commit message.

* `merge_commit_title` - Can be `PR_TITLE` or `MERGE_MESSAGE` for a default merge commit title.

* `merge_commit_message` - Can be `PR_BODY`, `PR_TITLE`, or `BLANK` for a default merge commit message.

* `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