Skip to content
Closed
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
8 changes: 8 additions & 0 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,14 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er
repoReq.DefaultBranch = github.String(d.Get("default_branch").(string))
}

// There's a bug in the GitHub 2022-11-28 version, that throws a 422 error
// whenever the `web_commit_signoff_required` is set to true, even when it
// is already true.
if !d.HasChange("web_commit_signoff_required") && d.Get("web_commit_signoff_required").(bool) {
// remove the field from the request
repoReq.WebCommitSignoffRequired = nil
}

repoName := d.Id()
owner := meta.(*Owner).name
ctx := context.WithValue(context.Background(), ctxId, d.Id())
Expand Down
112 changes: 111 additions & 1 deletion github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestAccGithubRepositories(t *testing.T) {

})

t.Run("updates a repositories name without error", func(t *testing.T) {
t.Run("updates a repository's name without error", func(t *testing.T) {

oldName := fmt.Sprintf(`tf-acc-test-rename-%[1]s`, randomID)
newName := fmt.Sprintf(`%[1]s-renamed`, oldName)
Expand Down Expand Up @@ -1567,6 +1567,115 @@ func TestAccGithubRepositoryVisibility(t *testing.T) {

}

func TestAccGithubRepositoryWebCommitSignoffRequired(t *testing.T) {

randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

t.Run("changes the web_commit_signoff_required attribute for a repository", func(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-%s"
auto_init = true
web_commit_signoff_required = true
}
`, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_repository.test", "web_commit_signoff_required",
"true",
),
)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}

t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})

t.Run("with an individual account", func(t *testing.T) {
testCase(t, individual)
})

t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})

})

// Test that setting any other setting than web_commit_signoff_required
// being set, doesn't set the value of web_commit_signoff_required to true
// or false in the GitHub API call.
t.Run("changes a non web_commit_signoff_required attribute for a repository", func(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-%s"
auto_init = true
allow_merge_commit = true
web_commit_signoff_required = true
}
`, randomID)

checks := map[string]resource.TestCheckFunc{
"before": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_repository.test", "web_commit_signoff_required",
"true",
),
),
"after": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_repository.test", "web_commit_signoff_required",
"true",
),
),
}

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: checks["before"],
},
{
Config: config,
Check: checks["after"],
},
},
})
}

t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})

t.Run("with an individual account", func(t *testing.T) {
testCase(t, individual)
})

t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})

})
}

func TestGithubRepositoryTopicPassesValidation(t *testing.T) {
resource := resourceGithubRepository()
schema := resource.Schema["topics"].Elem.(*schema.Schema)
Expand Down Expand Up @@ -1700,3 +1809,4 @@ func TestGithubRepositoryNameFailsValidationWithSpace(t *testing.T) {
t.Error(fmt.Errorf("unexpected name validation failure; expected=%s; action=%s", expectedFailure, actualFailure))
}
}