Skip to content

Comments

[FEAT] Add github_repository_pages Resource and Data Source#3168

Open
deiga wants to merge 21 commits intointegrations:mainfrom
F-Secure-web:add-github_repository_pages-resource
Open

[FEAT] Add github_repository_pages Resource and Data Source#3168
deiga wants to merge 21 commits intointegrations:mainfrom
F-Secure-web:add-github_repository_pages-resource

Conversation

@deiga
Copy link
Collaborator

@deiga deiga commented Feb 8, 2026

Resolves #3167
Resolves #2671
Resolves #3142
Resolves #1045
Resolves #2653
Resolves #2335


Before the change?

  • A repository's Pages resource was only manageable through github_repository

After the change?

  • There is now a github_repository_pages resource to manage the pages
  • There is now a github_repository_pages data source to fetch information about the pages
  • The pages fields are now deprecated in github_repository Resource and Data Source
  • It's possible to configure the public field of github_repository_pages
  • It's possible to configure the https_enforced field of github_repository_pages

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@github-actions
Copy link

github-actions bot commented Feb 8, 2026

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@deiga deiga added this to the v6.12.0 Release milestone Feb 8, 2026
@deiga deiga requested a review from stevehipwell February 12, 2026 11:58
@deiga deiga force-pushed the add-github_repository_pages-resource branch 2 times, most recently from e081a2d to c75d366 Compare February 13, 2026 22:14
Copy link
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good.

@deiga deiga force-pushed the add-github_repository_pages-resource branch from c75d366 to 91f6484 Compare February 17, 2026 20:09
@deiga deiga requested a review from stevehipwell February 17, 2026 20:10
@healiha
Copy link

healiha commented Feb 19, 2026

Would it be possible to add visibility to github_repository_pages?
image

The documentation doesn't seem to cover this, but after testing, a PUT request to https://api.github.com/repos/<org>/<repo>/pages with {"public": true/false} works.

@deiga
Copy link
Collaborator Author

deiga commented Feb 19, 2026

@healiha I'll check that out

@deiga deiga changed the title [FEAT] Add github_repository_pages Reasource and Data Source [FEAT] Add github_repository_pages Resource and Data Source Feb 20, 2026
stevehipwell
stevehipwell previously approved these changes Feb 20, 2026
Copy link
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stevehipwell
Copy link
Collaborator

@deiga could you please rebase this PR?

@deiga deiga force-pushed the add-github_repository_pages-resource branch from 18c8135 to 55b203a Compare February 21, 2026 06:23
@deiga deiga requested a review from stevehipwell February 21, 2026 06:36
Comment on lines 161 to 193
// Determine if we need to update the page with CNAME or public flag
shouldUpdatePage := false
update := &github.PagesUpdate{}
cname, cnameExists := d.GetOk("cname")
if cnameExists && cname.(string) != "" {
shouldUpdatePage = true
update.CNAME = github.Ptr(cname.(string))
}
public, publicExists := d.GetOkExists("public") // nolint:staticcheck // SA1019: There is no better alternative for checking if boolean value is set
if publicExists && public != nil {
shouldUpdatePage = true
update.Public = github.Ptr(public.(bool))
} else {
if err := d.Set("public", pages.GetPublic()); err != nil {
return diag.FromErr(err)
}
}
httpsEnforced, httpsEnforcedExists := d.GetOkExists("https_enforced") // nolint:staticcheck // SA1019: There is no better alternative for checking if boolean value is set
if httpsEnforcedExists && httpsEnforced != nil {
shouldUpdatePage = true
update.HTTPSEnforced = github.Ptr(httpsEnforced.(bool))
} else {
if err := d.Set("https_enforced", pages.GetHTTPSEnforced()); err != nil {
return diag.FromErr(err)
}
}

if shouldUpdatePage {
_, err = client.Repositories.UpdatePages(ctx, owner, repoName, update)
if err != nil {
return diag.FromErr(err)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Determine if we need to update the page with CNAME or public flag
shouldUpdatePage := false
update := &github.PagesUpdate{}
cname, cnameExists := d.GetOk("cname")
if cnameExists && cname.(string) != "" {
shouldUpdatePage = true
update.CNAME = github.Ptr(cname.(string))
}
public, publicExists := d.GetOkExists("public") // nolint:staticcheck // SA1019: There is no better alternative for checking if boolean value is set
if publicExists && public != nil {
shouldUpdatePage = true
update.Public = github.Ptr(public.(bool))
} else {
if err := d.Set("public", pages.GetPublic()); err != nil {
return diag.FromErr(err)
}
}
httpsEnforced, httpsEnforcedExists := d.GetOkExists("https_enforced") // nolint:staticcheck // SA1019: There is no better alternative for checking if boolean value is set
if httpsEnforcedExists && httpsEnforced != nil {
shouldUpdatePage = true
update.HTTPSEnforced = github.Ptr(httpsEnforced.(bool))
} else {
if err := d.Set("https_enforced", pages.GetHTTPSEnforced()); err != nil {
return diag.FromErr(err)
}
}
if shouldUpdatePage {
_, err = client.Repositories.UpdatePages(ctx, owner, repoName, update)
if err != nil {
return diag.FromErr(err)
}
}
// Check if we have values set that can't be configured as part of the create logic
cname, cnameOK := d.GetOk("cname")
public := d.get("public").(bool)
httpsEnforced := d.Get("https_enforced").(bool)
if cnameOK || public || httpsEnforced {
update := &github.PagesUpdate{}
if cnameOK {
update.CNAME = github.Ptr(cname.(string))
}
if public {
update.Public = github.Ptr(public)
}
if httpsEnforced {
update.HTTPSEnforced = github.Ptr(httpsEnforced)
}
_, err = client.Repositories.UpdatePages(ctx, owner, repoName, update)
if err != nil {
return diag.FromErr(err)
}
}

The logic for this can be significantly simplified as we only care about true values and this code is only run for the create.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! We do care are about the false value for public too, since a non-EMU GHEC can set either.
But I'll adopt your suggestion with that modification!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is that the unset value matches the default value. We only need to use the hacky method if we care about differentiating between false and unset.

In update, I'd expect the value to be set as we usually do rather than checking for a diff. Unless there is a specific reason not to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restructured it, but had to re-add the d.Set calls as otherwise the computed values won't be set


update := &github.PagesUpdate{}

if d.HasChange("cname") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally don't use this pattern, I'd expect to see d.get() & d.GetOk() here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what you mean. d.HasChange has been used ~36 times in the codebase.
d.HasChange() tells us if there is a value change in the plan, whereas d.Get() and d.GetOk() would cause us to send fields even if they are not changed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think 36 usages, some of which are definitely in diff functions, comes close to the occurrences of the get functions. The only reason you're in the update function is that there are changes to apply, so building the struct using the get functions (d.Get() for bools & d.GetOk() for strings where that aren't always set) is going to be the most efficient and readable pattern.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the API supports partial updates, I don't fully understand why we wouldn't want to utilize that.

For example these Optional & Computed fields are things that I wouldn't want to send unless they are actually changed in the plan and have been modified by the user.
Though I guess d.GetOk() isn't able to determine the latter once they have been set by Create or Read?

Could you elaborate the issue you're seeing with using d.HasChange()?

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
… config

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
deiga added 17 commits February 23, 2026 19:15
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
@deiga deiga force-pushed the add-github_repository_pages-resource branch from 7a1f79f to 56b7d70 Compare February 23, 2026 17:15
@deiga deiga requested a review from stevehipwell February 23, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment