Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolve '400 Custom domains' error on GitHub Enterprise Server #3489

Merged
merged 5 commits into from
Feb 25, 2025

Conversation

atilsensalduz
Copy link
Contributor

@atilsensalduz atilsensalduz commented Feb 21, 2025

This PR fixes an issue with the UpdatePages method, which caused the error: "400 Custom domains are not available for GitHub Pages" on GHES. The issue occurred because the update struct didn't specify the omitempty tag for JSON marshalling, which resulted in explicit null values being sent. As a result, GHES returned the error.

To resolve this, the fix adds a check for the client URL. If the URL differs from the public GitHub API, a new struct is created without the CNAME field to avoid sending null values.

Question: Should we add the omitempty tag directly to the CNAME field of the PagesUpdate struct instead of this workaround?

References:

Fixes: #3466.

The UpdatePages method fails on GitHub Enterprise Server. The fix set nil CNAME when request sending to GHES.

References:
- Issue: google#3466

Signed-off-by: atilsensalduz <atil.sensalduz@gmail.com>
The UpdatePages method fails on GitHub Enterprise Server. The fix set nil CNAME when request sending to GHES.

References:
- Issue: google#3466

Signed-off-by: atilsensalduz <atil.sensalduz@gmail.com>
@gmlewis gmlewis changed the title fix: resolve '400 Custom domains' error on GitHub Enterprise Server fix: Resolve '400 Custom domains' error on GitHub Enterprise Server Feb 21, 2025
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.03%. Comparing base (868f897) to head (f7cf4e6).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3489   +/-   ##
=======================================
  Coverage   91.02%   91.03%           
=======================================
  Files         179      179           
  Lines       15561    15574   +13     
=======================================
+ Hits        14165    14178   +13     
  Misses       1223     1223           
  Partials      173      173           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gmlewis
Copy link
Collaborator

gmlewis commented Feb 21, 2025

What happens when a person wishes to remove a custom domain?

When this happens for other endpoints (where sending a "null" is important and has a specific meaning), we often introduce a second endpoint that has serves the other usage, and whose name highlights the difference between the two use cases.

I think that might be appropriate here.

If you look around, you should be able to find some endpoints like that, but if you can't, let me know and I'll dig around for examples of this.

The UpdatePages method was failing on GHES due to the CNAME field being sent in the request.
This fix introduces a dedicated method for updating pages on GHES, using a request struct without the CNAME field
to ensure compatibility.

References:
- Issue: google#3466

Signed-off-by: atilsensalduz <atil.sensalduz@gmail.com>
The UpdatePages method was failing on GHES due to the CNAME field being sent in the request.
This fix introduces a dedicated method for updating pages on GHES, using a request struct without the CNAME field
to ensure compatibility.

References:
- Issue: google#3466

Signed-off-by: atilsensalduz <atil.sensalduz@gmail.com>
@atilsensalduz
Copy link
Contributor Author

What happens when a person wishes to remove a custom domain?

When this happens for other endpoints (where sending a "null" is important and has a specific meaning), we often introduce a second endpoint that has serves the other usage, and whose name highlights the difference between the two use cases.

I think that might be appropriate here.

If you look around, you should be able to find some endpoints like that, but if you can't, let me know and I'll dig around for examples of this.

You're absolutely right. Thanks for guiding me toward the better approach. I've updated the PR to use a separate endpoint for updating pages specifically for GHES and to use a struct without the CNAME field to avoid the 400 error.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Feb 22, 2025
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @atilsensalduz!
LGTM.

Awaiting second LGTM+Approval from any other contributor to this repo before merging.

@stevehipwell - might you have time for a coffee review? Thank you!

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Whups, I spoke too soon. Please fix the lint issues by following step 4 of CONTRIBUTING.md.

The UpdatePages method was failing on GHES due to the CNAME field being sent in the request.
This fix introduces a dedicated method for updating pages on GHES, using a request struct without the CNAME field
to ensure compatibility.

References:
- Issue: google#3466

Signed-off-by: atilsensalduz <atil.sensalduz@gmail.com>
@atilsensalduz
Copy link
Contributor Author

Whups, I spoke too soon. Please fix the lint issues by following step 4 of CONTRIBUTING.md.

Ah, sorry about that! I must have missed it. 🤦 Thanks for the heads-up! I've fixed the lint issues now. I really appreciate your review and support! @gmlewis

Copy link
Contributor

@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

@gmlewis
Copy link
Collaborator

gmlewis commented Feb 25, 2025

Thank you, @stevehipwell!
Merging.

@gmlewis gmlewis merged commit a25b53e into google:master Feb 25, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsReview PR is awaiting a review before merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UpdatePages method doesn't work on github enterprise server (CNAME argument not allowed)
3 participants