From 891a05cd1cc90adbfe681e2add0a22c629f0c92d Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 17 Jan 2025 16:11:18 +0000 Subject: [PATCH 01/11] Add public field to github pages --- github/data_source_github_repository.go | 4 ++++ github/resource_github_repository.go | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index ed2a30143b..426cf0f4ce 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -270,6 +270,10 @@ func dataSourceGithubRepository() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "public": { + Type: schema.TypeBool, + Computed: true, + }, "status": { Type: schema.TypeString, Computed: true, diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index f28cc4c6e8..05c1073aa2 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -295,6 +295,11 @@ func resourceGithubRepository() *schema.Resource { Computed: true, Description: "URL to the repository on the web.", }, + "public": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the rendered GitHub Pages site is publicly availabe.", + }, "status": { Type: schema.TypeString, Computed: true, @@ -948,6 +953,11 @@ func expandPagesUpdate(input []interface{}) *github.PagesUpdate { } update.Source = &github.PagesSource{Branch: &sourceBranch, Path: &sourcePath} } + + // Only set the github.PagesUpdate public field if the value is a valid boolean. + if v, ok := pages["public"].(bool); ok && v != "" { + update.Public = github.Bool(v) + } return update } @@ -966,6 +976,7 @@ func flattenPages(pages *github.Pages) []interface{} { pagesMap["build_type"] = pages.GetBuildType() pagesMap["url"] = pages.GetURL() pagesMap["status"] = pages.GetStatus() + pagesMap["public"] = pages.GetPublic() pagesMap["cname"] = pages.GetCNAME() pagesMap["custom_404"] = pages.GetCustom404() pagesMap["html_url"] = pages.GetHTMLURL() From 50725b5937703476710abe601223f8d11d136090 Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 17 Jan 2025 16:56:55 +0000 Subject: [PATCH 02/11] Add public field to repository pages --- github/data_source_github_repository.go | 4 ++++ github/resource_github_repository.go | 13 ++++++++++++- website/docs/r/repository.html.markdown | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index ed2a30143b..426cf0f4ce 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -270,6 +270,10 @@ func dataSourceGithubRepository() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "public": { + Type: schema.TypeBool, + Computed: true, + }, "status": { Type: schema.TypeString, Computed: true, diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index f28cc4c6e8..c7f424714a 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -295,9 +295,14 @@ func resourceGithubRepository() *schema.Resource { Computed: true, Description: "URL to the repository on the web.", }, + "public": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the rendered GitHub Pages site is publicly availabe.", + }, "status": { Type: schema.TypeString, - Computed: true, + Optional: true, Description: "The GitHub Pages site's build status e.g. building or built.", }, "url": { @@ -948,6 +953,11 @@ func expandPagesUpdate(input []interface{}) *github.PagesUpdate { } update.Source = &github.PagesSource{Branch: &sourceBranch, Path: &sourcePath} } + + // Only set the github.PagesUpdate public field if the value is a valid boolean. + if v, ok := pages["public"].(bool); ok { + update.Public = github.Bool(v) + } return update } @@ -966,6 +976,7 @@ func flattenPages(pages *github.Pages) []interface{} { pagesMap["build_type"] = pages.GetBuildType() pagesMap["url"] = pages.GetURL() pagesMap["status"] = pages.GetStatus() + pagesMap["public"] = pages.GetPublic() pagesMap["cname"] = pages.GetCNAME() pagesMap["custom_404"] = pages.GetCustom404() pagesMap["html_url"] = pages.GetHTMLURL() diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index dc18add1d6..8e344fcb15 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -136,6 +136,8 @@ The `pages` block supports the following: * `cname` - (Optional) The custom domain for the repository. This can only be set after the repository has been created. +* `public` - (Optional) Whether the rendered GitHub Pages site is publicly availabe. + #### GitHub Pages Source #### The `source` block supports the following: From c4b0fd32b838c2774caa435340ae7c13b2799653 Mon Sep 17 00:00:00 2001 From: Luca Date: Mon, 20 Jan 2025 11:27:49 +0000 Subject: [PATCH 03/11] add test and creation case --- github/resource_github_repository.go | 7 +++- github/resource_github_repository_test.go | 47 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index c7f424714a..9d6d269b5a 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -918,7 +918,12 @@ func expandPages(input []interface{}) *github.Pages { buildType = github.String(v) } - return &github.Pages{Source: source, BuildType: buildType} + var public *bool + // Only set the github.PagesUpdate public field if the value is a valid boolean. + if v, ok := pages["public"].(bool); ok { + public = github.Bool(v) + } + return &github.Pages{Source: source, BuildType: buildType, Public: public} } func expandPagesUpdate(input []interface{}) *github.PagesUpdate { diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index e09505dac9..f8645c9fb6 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -1125,6 +1125,53 @@ func TestAccGithubRepositoryPages(t *testing.T) { t.Errorf("got %q; want %q", pages.GetSource().GetPath(), "/docs") } }) + + t.Run("manages private pages feature for a repository", func(t *testing.T) { + config := fmt.Sprintf(` + resource "github_repository" "test" { + name = "tf-acc-%s" + auto_init = true + pages { + source { + branch = "main" + } + public = false + } + } + `, randomID) + + check := resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "pages.0.public", + "false", + ), + ) + + 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 feature") + }) + + t.Run("with an individual account", func(t *testing.T) { + t.Skip("individual account not supported for this feature") + }) + + t.Run("with an organization account", func(t *testing.T) { + testCase(t, organization) + }) + }) } func TestAccGithubRepositorySecurity(t *testing.T) { From b590cd478c5cfccddc1f176e8425e8720291c256 Mon Sep 17 00:00:00 2001 From: Luca <39161082+BartolottiLuca@users.noreply.github.com> Date: Wed, 22 Jan 2025 14:41:52 +0000 Subject: [PATCH 04/11] Update website/docs/r/repository.html.markdown Co-authored-by: Usman --- website/docs/r/repository.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index 8e344fcb15..4d5f391397 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -136,7 +136,7 @@ The `pages` block supports the following: * `cname` - (Optional) The custom domain for the repository. This can only be set after the repository has been created. -* `public` - (Optional) Whether the rendered GitHub Pages site is publicly availabe. +* `public` - (Optional) Whether the rendered GitHub Pages site is publicly available. #### GitHub Pages Source #### From abe0d9b0a15c32328c5f2abb92e21234769405ae Mon Sep 17 00:00:00 2001 From: Luca <39161082+BartolottiLuca@users.noreply.github.com> Date: Fri, 5 Dec 2025 11:36:07 +0000 Subject: [PATCH 05/11] Update repository.html.markdown From ca85b872fa4a8f572283958529893ac8248aa0d2 Mon Sep 17 00:00:00 2001 From: Luca <39161082+BartolottiLuca@users.noreply.github.com> Date: Tue, 13 Jan 2026 18:00:58 +0000 Subject: [PATCH 06/11] Update github/resource_github_repository.go better field description Co-authored-by: Timo Sand --- github/resource_github_repository.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index f5ed81dfdf..6d15181ba2 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -367,7 +367,7 @@ func resourceGithubRepository() *schema.Resource { "public": { Type: schema.TypeBool, Computed: true, - Description: "Whether the rendered GitHub Pages site is publicly availabe.", + Description: "Whether the GitHub Pages site is publicly visible. If set to `true`, the site is accessible to anyone on the internet. If set to `false`, the site will only be accessible to users who have at least `read` access to the repository that published the site.", }, "status": { Type: schema.TypeString, From 1c821b20e441129d313765128b7e25b78d923eac Mon Sep 17 00:00:00 2001 From: Luca Date: Tue, 13 Jan 2026 18:07:10 +0000 Subject: [PATCH 07/11] make status computed & remove unnecessary change --- github/resource_github_repository.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 6d15181ba2..69d1a63227 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -371,7 +371,7 @@ func resourceGithubRepository() *schema.Resource { }, "status": { Type: schema.TypeString, - Optional: true, + Computed: true, Description: "The GitHub Pages site's build status e.g. building or built.", }, "url": { @@ -1099,12 +1099,7 @@ func expandPages(input []any) *github.Pages { buildType = github.String(v) } - var public *bool - // Only set the github.PagesUpdate public field if the value is a valid boolean. - if v, ok := pages["public"].(bool); ok { - public = github.Bool(v) - } - return &github.Pages{Source: source, BuildType: buildType, Public: public} + return &github.Pages{Source: source, BuildType: buildType} } func expandPagesUpdate(input []any) *github.PagesUpdate { From 1461e9981fd437d109797572e7d7c1e05e1711c6 Mon Sep 17 00:00:00 2001 From: Luca <39161082+BartolottiLuca@users.noreply.github.com> Date: Fri, 23 Jan 2026 14:55:27 +0000 Subject: [PATCH 08/11] Apply suggestion from @deiga Co-authored-by: Timo Sand --- github/resource_github_repository.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index d6994fb2e1..66b7acd715 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -1128,7 +1128,7 @@ func expandPagesUpdate(input []any) *github.PagesUpdate { // Only set the github.PagesUpdate public field if the value is a valid boolean. if v, ok := pages["public"].(bool); ok && v != "" { - update.Public = github.Bool(v) + update.Public = github.Ptr(v) } return update From ffa8f54d89c1f4f00344c9938ae4c228d9784546 Mon Sep 17 00:00:00 2001 From: Luca <39161082+BartolottiLuca@users.noreply.github.com> Date: Fri, 23 Jan 2026 14:58:21 +0000 Subject: [PATCH 09/11] Apply suggestion from @deiga Co-authored-by: Timo Sand --- github/resource_github_repository_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 8f8a009a50..442edb7ef7 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -1337,7 +1337,7 @@ func Test_expandPages(t *testing.T) { testCase := func(t *testing.T, mode string) { resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessMode(t, mode) }, - Providers: testAccProviders, + ProviderFactories: providerFactories, Steps: []resource.TestStep{ { Config: config, From cd7bb22e3192c1a882c98634c257e7ca08a52cbf Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 23 Jan 2026 15:08:05 +0000 Subject: [PATCH 10/11] new test convention and use testResourcePrefix --- github/resource_github_repository_test.go | 41 +++++++---------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 442edb7ef7..949a6f68d7 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -1314,9 +1314,11 @@ func Test_expandPages(t *testing.T) { }) t.Run("manages private pages feature for a repository", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sprivate-pages-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-%s" + name = "%s" auto_init = true pages { source { @@ -1325,38 +1327,21 @@ func Test_expandPages(t *testing.T) { public = false } } - `, randomID) + `, testRepoName) check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "pages.0.public", - "false", - ), + resource.TestCheckResourceAttr("github_repository.test", "pages.0.public", "false"), ) - testCase := func(t *testing.T, mode string) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { skipUnlessMode(t, mode) }, - ProviderFactories: providerFactories, - Steps: []resource.TestStep{ - { - Config: config, - Check: check, - }, + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnlessMode(t, organization) }, + ProviderFactories: providerFactories, + 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 feature") - }) - - t.Run("with an individual account", func(t *testing.T) { - t.Skip("individual account not supported for this feature") - }) - - t.Run("with an organization account", func(t *testing.T) { - testCase(t, organization) + }, }) }) } From 94f32d53ec6b6335ddcace239201bbbd5f283b01 Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 13 Feb 2026 16:56:54 +0000 Subject: [PATCH 11/11] apply suggestions --- github/resource_github_repository.go | 1 + github/resource_github_repository_test.go | 2 +- website/docs/r/repository.html.markdown | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index e477d42ad5..b81125fdcf 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -376,6 +376,7 @@ func resourceGithubRepository() *schema.Resource { "public": { Type: schema.TypeBool, Computed: true, + Optional: true, Description: "Whether the GitHub Pages site is publicly visible. If set to `true`, the site is accessible to anyone on the internet. If set to `false`, the site will only be accessible to users who have at least `read` access to the repository that published the site.", }, "status": { diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 12ac9e1279..8c218e5dc6 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -1445,7 +1445,7 @@ func Test_expandPages(t *testing.T) { ) resource.Test(t, resource.TestCase{ - PreCheck: func() { skipUnlessMode(t, organization) }, + PreCheck: func() { skipUnlessHasOrgs(t) }, ProviderFactories: providerFactories, Steps: []resource.TestStep{ { diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index 4fc7b25cee..a6a66ddde7 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -156,7 +156,7 @@ The `pages` block supports the following: * `cname` - (Optional) The custom domain for the repository. This can only be set after the repository has been created. -* `public` - (Optional) Whether the GitHub Pages site is publicly visible. If set to `true`, the site is accessible to anyone on the internet. If set to `false`, the site will only be accessible to users who have at least `read` access to the repository that published the site. +* `public` - (Optional, Computed) Whether the GitHub Pages site is publicly visible. If set to `true`, the site is accessible to anyone on the internet. If set to `false`, the site will only be accessible to users who have at least `read` access to the repository that published the site. There is no single default: accounts without GitHub Enterprise are forced to have public pages; with Enterprise and Managed Users, pages can only be private; only Enterprise accounts without Managed Users can choose. See [About access control for GitHub Pages sites](https://docs.github.com/en/enterprise-cloud@latest/pages/getting-started-with-github-pages/changing-the-visibility-of-your-github-pages-site#about-access-control-for-github-pages-sites). The value is also computed from GitHub, so omitting it is safe. #### GitHub Pages Source