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 web commit sign off #2007

Merged
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
52 changes: 30 additions & 22 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ func resourceGithubRepository() *schema.Resource {
Default: false,
Description: "Automatically delete head branch after a pull request is merged. Defaults to 'false'.",
},
"web_commit_signoff_required": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Require contributors to sign off on web-based commits. Defaults to 'false'.",
},
"auto_init": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -470,28 +476,29 @@ func calculateSecurityAndAnalysis(d *schema.ResourceData) *github.SecurityAndAna

func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository {
repository := &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)),
HasDiscussions: github.Bool(d.Get("has_discussions").(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()),
AllowUpdateBranch: github.Bool(d.Get("allow_update_branch").(bool)),
SecurityAndAnalysis: calculateSecurityAndAnalysis(d),
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)),
HasDiscussions: github.Bool(d.Get("has_discussions").(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)),
WebCommitSignoffRequired: github.Bool(d.Get("web_commit_signoff_required").(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()),
AllowUpdateBranch: github.Bool(d.Get("allow_update_branch").(bool)),
SecurityAndAnalysis: calculateSecurityAndAnalysis(d),
}

// only configure merge commit if we are in commit merge strategy
Expand Down Expand Up @@ -678,6 +685,7 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro
d.Set("allow_squash_merge", repo.GetAllowSquashMerge())
d.Set("allow_update_branch", repo.GetAllowUpdateBranch())
d.Set("delete_branch_on_merge", repo.GetDeleteBranchOnMerge())
d.Set("web_commit_signoff_required", repo.GetWebCommitSignoffRequired())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be set somewhere in the Create/Update methods as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I miss adding it somewhere? I’ve tested this feature and it works as expected (adding, removing, updating the setting).

Is it possible that you’re asking for the other PR (the bug for gitcommit paginated call)?

d.Set("has_downloads", repo.GetHasDownloads())
d.Set("merge_commit_message", repo.GetMergeCommitMessage())
d.Set("merge_commit_title", repo.GetMergeCommitTitle())
Expand Down
32 changes: 18 additions & 14 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ func TestAccGithubRepositories(t *testing.T) {
config := fmt.Sprintf(`
resource "github_repository" "test" {

name = "tf-acc-test-create-%[1]s"
description = "Terraform acceptance tests %[1]s"
has_discussions = true
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

name = "tf-acc-test-create-%[1]s"
description = "Terraform acceptance tests %[1]s"
has_discussions = true
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
web_commit_signoff_required = true
}
`, randomID)

Expand All @@ -59,6 +59,10 @@ func TestAccGithubRepositories(t *testing.T) {
"github_repository.test", "merge_commit_title",
"MERGE_MESSAGE",
),
resource.TestCheckResourceAttr(
"github_repository.test", "web_commit_signoff_required",
"true",
),
)

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

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

* `web_commit_signoff_required` - (Optional) Require contributors to sign off on web-based commits. See more [here](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/managing-the-commit-signoff-policy-for-your-repository). Defaults to `false`.

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

* `auto_init` - (Optional) Set to `true` to produce an initial commit in the repository.
Expand Down