Skip to content
Open
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
2 changes: 2 additions & 0 deletions github/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Owner struct {
v3client *github.Client
v4client *githubv4.Client
StopContext context.Context
IsGHES bool
IsOrganization bool
}

Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 19 additions & 1 deletion github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{}
Expand Down
58 changes: 58 additions & 0 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,64 @@ 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{
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")
Expand Down