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
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 32 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions github/repos_pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,36 @@
if err != nil {
return resp, err
}
return resp, nil
}

// PagesUpdateWithoutCNAME defines parameters for updating a GitHub Pages site on GitHub Enterprise Servers.
// Sending a request with a CNAME (any value, empty string, or null) results in a 400 error: "Custom domains are not available for GitHub Pages."

Check failure on line 177 in github/repos_pages.go

View workflow job for this annotation

GitHub Actions / lint

Comment should end in a period (godot)
type PagesUpdateWithoutCNAME struct {
BuildType *string `json:"build_type,omitempty"`
Source *PagesSource `json:"source,omitempty"`
Public *bool `json:"public,omitempty"`
HTTPSEnforced *bool `json:"https_enforced,omitempty"`
}

// UpdatePagesGHES updates GitHub Pages for the named repo in GitHub Enterprise Servers.
//
// GitHub API docs: https://docs.github.com/rest/pages/pages#update-information-about-a-github-pages-site
//
//meta:operation PUT /repos/{owner}/{repo}/pages
func (s *RepositoriesService) UpdatePagesGHES(ctx context.Context, owner, repo string, opts *PagesUpdateWithoutCNAME) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages", owner, repo)

req, err := s.client.NewRequest("PUT", u, opts)

if err != nil {
return nil, err
}

resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, nil
}

Expand Down
38 changes: 38 additions & 0 deletions github/repos_pages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,44 @@ func TestRepositoriesService_UpdatePagesWorkflow(t *testing.T) {
})
}

func TestRepositoriesService_UpdatePagesGHES(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

input := &PagesUpdateWithoutCNAME{
BuildType: Ptr("workflow"),
}

mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) {
v := new(PagesUpdate)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PUT")
want := &PagesUpdate{BuildType: Ptr("workflow")}
if !cmp.Equal(v, want) {
t.Errorf("Request body = %+v, want %+v", v, want)
}

fmt.Fprint(w, `{"build_type":"workflow"}`)
})

ctx := context.Background()
_, err := client.Repositories.UpdatePagesGHES(ctx, "o", "r", input)
if err != nil {
t.Errorf("Repositories.UpdatePagesGHES returned error: %v", err)
}

const methodName = "UpdatePagesGHES"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Repositories.UpdatePagesGHES(ctx, "\n", "\n", input)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Repositories.UpdatePagesGHES(ctx, "o", "r", input)
})
}

func TestRepositoriesService_UpdatePages_NullCNAME(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
Expand Down
Loading