Skip to content

Commit

Permalink
fix: Repo Creation fails with enabled Pages (#1748)
Browse files Browse the repository at this point in the history
Co-authored-by: Keegan Campbell <me@kfcampbell.com>
  • Loading branch information
0x46616c6b and kfcampbell authored Jun 22, 2023
1 parent be7cfe8 commit 8c7b824
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
21 changes: 12 additions & 9 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,20 +836,23 @@ func expandPages(input []interface{}) *github.Pages {
return nil
}
pages := input[0].(map[string]interface{})
var source *github.PagesSource
if pagesSource, ok := pages["source"].([]interface{})[0].(map[string]interface{}); ok {
if v, ok := pagesSource["branch"].(string); ok {
if v != "" {
source := &github.PagesSource{
Branch: github.String("main"),
}
if len(pages["source"].([]interface{})) == 1 {
if pagesSource, ok := pages["source"].([]interface{})[0].(map[string]interface{}); ok {
if v, ok := pagesSource["branch"].(string); ok {
source.Branch = github.String(v)
}
}
if v, ok := pagesSource["path"].(string); ok {
// To set to the root directory "/", leave source.Path unset
if v != "" && v != "/" {
source.Path = github.String(v)
if v, ok := pagesSource["path"].(string); ok {
// To set to the root directory "/", leave source.Path unset
if v != "" && v != "/" {
source.Path = github.String(v)
}
}
}
}

var buildType *string
if v, ok := pages["build_type"].(string); ok {
buildType = github.String(v)
Expand Down
41 changes: 41 additions & 0 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,47 @@ func TestAccGithubRepositoryPages(t *testing.T) {

})

t.Run("expand Pages configuration with workflow", func(t *testing.T) {
input := []interface{}{map[string]interface{}{
"build_type": "workflow",
"source": []interface{}{map[string]interface{}{}},
}}

pages := expandPages(input)
if pages == nil {
t.Fatal("pages is nil")
}
if pages.GetBuildType() != "workflow" {
t.Errorf("got %q; want %q", pages.GetBuildType(), "workflow")
}
if pages.GetSource().GetBranch() != "main" {
t.Errorf("got %q; want %q", pages.GetSource().GetBranch(), "main")
}
})

t.Run("expand Pages configuration with source", func(t *testing.T) {
input := []interface{}{map[string]interface{}{
"build_type": "legacy",
"source": []interface{}{map[string]interface{}{
"branch": "main",
"path": "/docs",
}},
}}

pages := expandPages(input)
if pages == nil {
t.Fatal("pages is nil")
}
if pages.GetBuildType() != "legacy" {
t.Errorf("got %q; want %q", pages.GetBuildType(), "legacy")
}
if pages.GetSource().GetBranch() != "main" {
t.Errorf("got %q; want %q", pages.GetSource().GetBranch(), "main")
}
if pages.GetSource().GetPath() != "/docs" {
t.Errorf("got %q; want %q", pages.GetSource().GetPath(), "/docs")
}
})
}

func TestAccGithubRepositorySecurity(t *testing.T) {
Expand Down

0 comments on commit 8c7b824

Please sign in to comment.