|
7 | 7 | "strconv" |
8 | 8 | "strings" |
9 | 9 |
|
10 | | - "github.com/google/go-github/v84/github" |
| 10 | + "github.com/google/go-github/v85/github" |
11 | 11 | "github.com/hashicorp/terraform-plugin-log/tflog" |
12 | 12 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" |
13 | 13 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" |
@@ -124,7 +124,34 @@ func resourceGithubRepositoryPagesCreate(ctx context.Context, d *schema.Resource |
124 | 124 | owner := meta.name // TODO: Add owner support // d.Get("owner").(string) |
125 | 125 | repoName := d.Get("repository").(string) |
126 | 126 |
|
127 | | - pagesReq := expandPagesForCreate(d) |
| 127 | + pagesReq := &github.Pages{} |
| 128 | + |
| 129 | + buildType := d.Get("build_type").(string) |
| 130 | + pagesReq.BuildType = new(buildType) |
| 131 | + |
| 132 | + if buildType == "legacy" { |
| 133 | + if source, ok := d.GetOk("source"); ok { |
| 134 | + sourceList := source.([]any) |
| 135 | + if len(sourceList) > 0 { |
| 136 | + sourceMap := sourceList[0].(map[string]any) |
| 137 | + branch := sourceMap["branch"].(string) |
| 138 | + pagesSource := &github.PagesSource{ |
| 139 | + Branch: new(branch), |
| 140 | + } |
| 141 | + if path, ok := sourceMap["path"].(string); ok && path != "" && path != "/" { |
| 142 | + pagesSource.Path = new(path) |
| 143 | + } |
| 144 | + pagesReq.Source = pagesSource |
| 145 | + } |
| 146 | + } |
| 147 | + // Default to main branch if no source specified |
| 148 | + if pagesReq.Source == nil { |
| 149 | + pagesReq.Source = &github.PagesSource{ |
| 150 | + Branch: new("main"), |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | + |
128 | 155 | pages, _, err := client.Repositories.EnablePages(ctx, owner, repoName, pagesReq) |
129 | 156 | if err != nil { |
130 | 157 | return diag.FromErr(err) |
@@ -299,18 +326,14 @@ func resourceGithubRepositoryPagesUpdate(ctx context.Context, d *schema.Resource |
299 | 326 | // Hence we make sure to only send the value if it's changed. |
300 | 327 | // Error: "400 Private pages is not enabled for this repository. All Pages will be public." |
301 | 328 | if d.HasChange("public") { |
302 | | - public, ok := d.Get("public").(bool) |
303 | | - if ok { |
304 | | - update.Public = new(public) |
305 | | - } |
| 329 | + public := d.Get("public").(bool) |
| 330 | + update.Public = new(public) |
306 | 331 | } |
307 | 332 |
|
308 | 333 | // `https_enforced` can't be sent to the API unless `cname` is set. Otherwise the API will return "404 The certificate does not exist yet". |
309 | 334 | if d.HasChange("https_enforced") { |
310 | | - httpsEnforced, ok := d.Get("https_enforced").(bool) |
311 | | - if ok { |
312 | | - update.HTTPSEnforced = new(httpsEnforced) |
313 | | - } |
| 335 | + httpsEnforced := d.Get("https_enforced").(bool) |
| 336 | + update.HTTPSEnforced = new(httpsEnforced) |
314 | 337 | } |
315 | 338 |
|
316 | 339 | buildType := d.Get("build_type").(string) |
@@ -399,35 +422,3 @@ func resourceGithubRepositoryPagesDiff(ctx context.Context, d *schema.ResourceDi |
399 | 422 |
|
400 | 423 | return nil |
401 | 424 | } |
402 | | - |
403 | | -func expandPagesForCreate(d *schema.ResourceData) *github.Pages { |
404 | | - pages := &github.Pages{} |
405 | | - |
406 | | - buildType := d.Get("build_type").(string) |
407 | | - pages.BuildType = new(buildType) |
408 | | - |
409 | | - if buildType == "legacy" { |
410 | | - if source, ok := d.GetOk("source"); ok { |
411 | | - sourceList := source.([]any) |
412 | | - if len(sourceList) > 0 { |
413 | | - sourceMap := sourceList[0].(map[string]any) |
414 | | - branch := sourceMap["branch"].(string) |
415 | | - pagesSource := &github.PagesSource{ |
416 | | - Branch: new(branch), |
417 | | - } |
418 | | - if path, ok := sourceMap["path"].(string); ok && path != "" && path != "/" { |
419 | | - pagesSource.Path = new(path) |
420 | | - } |
421 | | - pages.Source = pagesSource |
422 | | - } |
423 | | - } |
424 | | - // Default to main branch if no source specified |
425 | | - if pages.Source == nil { |
426 | | - pages.Source = &github.PagesSource{ |
427 | | - Branch: new("main"), |
428 | | - } |
429 | | - } |
430 | | - } |
431 | | - |
432 | | - return pages |
433 | | -} |
0 commit comments