From af9752679e2eb2c47f3f08d5e44fb3f9a9a764f8 Mon Sep 17 00:00:00 2001 From: Tobias Sebastian Jenkner EXT Date: Wed, 18 Feb 2026 15:06:54 +0100 Subject: [PATCH 1/3] copilot generated testcase for https://github.com/integrations/terraform-provider-github/issues/2087 --- github/resource_github_repository_test.go | 67 +++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 1589c84bf1..70f4c470ec 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -2,6 +2,7 @@ package github import ( "fmt" + "os" "regexp" "strings" "testing" @@ -953,6 +954,72 @@ resource "github_repository" "test" { }) }) + t.Run("updates repository pages from legacy to workflow", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%spages-2087-%s", testResourcePrefix, randomID) + testVisibility := "private" + if testAccConf.authMode == individual { + testVisibility = "public" + } + + configs := map[string]string{ + "legacy": fmt.Sprintf(` + resource "github_repository" "test" { + name = "%s" + visibility = "%s" + auto_init = true + + pages { + build_type = "legacy" + + source { + branch = "main" + path = "/" + } + } + } + `, testRepoName, testVisibility), + "workflow": fmt.Sprintf(` + resource "github_repository" "test" { + name = "%s" + visibility = "%s" + auto_init = true + + pages { + build_type = "workflow" + } + } + `, testRepoName, testVisibility), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + if os.Getenv("GITHUB_TOKEN") == "" || os.Getenv("GITHUB_OWNER") == "" { + t.Skip("Skipping as GITHUB_TOKEN and GITHUB_OWNER are required for this testcase") + } + if testAccConf.baseURL.String() == DotComAPIURL { + t.Skip("Skipping as this testcase targets GHES") + } + }, + ProviderFactories: providerFactories, + Steps: []resource.TestStep{ + { + Config: configs["legacy"], + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("github_repository.test", "pages.0.source.0.branch", "main"), + resource.TestCheckResourceAttr("github_repository.test", "pages.0.source.0.path", "/"), + ), + }, + { + Config: configs["workflow"], + Check: resource.ComposeTestCheckFunc( + resource.TestCheckNoResourceAttr("github_repository.test", "pages.0.source.#"), + ), + }, + }, + }) + }) + t.Run("manages the security feature for a private repository", func(t *testing.T) { if !testAccConf.testAdvancedSecurity { t.Skip("Advanced Security is not enabled for this account") From 7ccfefe00cedb4175255b78a3185915a168079af Mon Sep 17 00:00:00 2001 From: Tobias Sebastian Jenkner EXT Date: Wed, 18 Feb 2026 19:34:54 +0100 Subject: [PATCH 2/3] simple fix developed with Copilot --- github/config.go | 2 ++ github/resource_github_repository.go | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/github/config.go b/github/config.go index a61dd541b7..868d13dcc0 100644 --- a/github/config.go +++ b/github/config.go @@ -35,6 +35,7 @@ type Owner struct { v3client *github.Client v4client *githubv4.Client StopContext context.Context + IsGHES bool IsOrganization bool } @@ -164,6 +165,7 @@ func (c *Config) Meta() (any, error) { owner.v4client = v4client owner.v3client = v3client owner.StopContext = context.Background() + owner.IsGHES = c.IsGHES _, err = c.ConfigureOwner(&owner) if err != nil { diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 9d756ac6c9..8f0079d7d4 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -978,7 +978,12 @@ func resourceGithubRepositoryUpdate(ctx context.Context, d *schema.ResourceData, if pages == nil { _, _, err = client.Repositories.EnablePages(ctx, owner, repoName, &github.Pages{Source: opts.Source, BuildType: opts.BuildType}) } else { - _, err = client.Repositories.UpdatePages(ctx, owner, repoName, opts) + if meta.(*Owner).IsGHES { + ghesOpts := updatePagesWithoutCNAME(opts) + _, err = client.Repositories.UpdatePagesGHES(ctx, owner, repoName, ghesOpts) + } else { + _, err = client.Repositories.UpdatePages(ctx, owner, repoName, opts) + } } if err != nil { return diag.FromErr(err) @@ -1129,6 +1134,19 @@ func expandPagesUpdate(input []any) *github.PagesUpdate { return update } +func updatePagesWithoutCNAME(update *github.PagesUpdate) *github.PagesUpdateWithoutCNAME { + if update == nil { + return nil + } + + return &github.PagesUpdateWithoutCNAME{ + BuildType: update.BuildType, + Source: update.Source, + Public: update.Public, + HTTPSEnforced: update.HTTPSEnforced, + } +} + func flattenPages(pages *github.Pages) []any { if pages == nil { return []any{} From 7f4f9e66061aa4981e847c73d9e843f820dd4c30 Mon Sep 17 00:00:00 2001 From: Tobias Sebastian Jenkner EXT Date: Wed, 18 Feb 2026 20:10:14 +0100 Subject: [PATCH 3/3] cleanup - remove PreCheck - this is not used in any tests here --- github/resource_github_repository_test.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 70f4c470ec..c49309f43c 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -2,7 +2,6 @@ package github import ( "fmt" - "os" "regexp" "strings" "testing" @@ -993,14 +992,6 @@ resource "github_repository" "test" { } resource.Test(t, resource.TestCase{ - PreCheck: func() { - if os.Getenv("GITHUB_TOKEN") == "" || os.Getenv("GITHUB_OWNER") == "" { - t.Skip("Skipping as GITHUB_TOKEN and GITHUB_OWNER are required for this testcase") - } - if testAccConf.baseURL.String() == DotComAPIURL { - t.Skip("Skipping as this testcase targets GHES") - } - }, ProviderFactories: providerFactories, Steps: []resource.TestStep{ {