Skip to content

Commit a25b53e

Browse files
fix: Resolve '400 Custom domains' error on GitHub Enterprise Server (#3489)
1 parent 782d39f commit a25b53e

4 files changed

+140
-0
lines changed

github/github-accessors.go

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/repos_pages.go

+29
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,36 @@ func (s *RepositoriesService) UpdatePages(ctx context.Context, owner, repo strin
170170
if err != nil {
171171
return resp, err
172172
}
173+
return resp, nil
174+
}
175+
176+
// PagesUpdateWithoutCNAME defines parameters for updating a GitHub Pages site on GitHub Enterprise Servers.
177+
// 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".
178+
type PagesUpdateWithoutCNAME struct {
179+
BuildType *string `json:"build_type,omitempty"`
180+
Source *PagesSource `json:"source,omitempty"`
181+
Public *bool `json:"public,omitempty"`
182+
HTTPSEnforced *bool `json:"https_enforced,omitempty"`
183+
}
184+
185+
// UpdatePagesGHES updates GitHub Pages for the named repo in GitHub Enterprise Servers.
186+
//
187+
// GitHub API docs: https://docs.github.com/rest/pages/pages#update-information-about-a-github-pages-site
188+
//
189+
//meta:operation PUT /repos/{owner}/{repo}/pages
190+
func (s *RepositoriesService) UpdatePagesGHES(ctx context.Context, owner, repo string, opts *PagesUpdateWithoutCNAME) (*Response, error) {
191+
u := fmt.Sprintf("repos/%v/%v/pages", owner, repo)
173192

193+
req, err := s.client.NewRequest("PUT", u, opts)
194+
195+
if err != nil {
196+
return nil, err
197+
}
198+
199+
resp, err := s.client.Do(ctx, req, nil)
200+
if err != nil {
201+
return resp, err
202+
}
174203
return resp, nil
175204
}
176205

github/repos_pages_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,44 @@ func TestRepositoriesService_UpdatePagesWorkflow(t *testing.T) {
200200
})
201201
}
202202

203+
func TestRepositoriesService_UpdatePagesGHES(t *testing.T) {
204+
t.Parallel()
205+
client, mux, _ := setup(t)
206+
207+
input := &PagesUpdateWithoutCNAME{
208+
BuildType: Ptr("workflow"),
209+
}
210+
211+
mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) {
212+
v := new(PagesUpdate)
213+
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
214+
215+
testMethod(t, r, "PUT")
216+
want := &PagesUpdate{BuildType: Ptr("workflow")}
217+
if !cmp.Equal(v, want) {
218+
t.Errorf("Request body = %+v, want %+v", v, want)
219+
}
220+
221+
fmt.Fprint(w, `{"build_type":"workflow"}`)
222+
})
223+
224+
ctx := context.Background()
225+
_, err := client.Repositories.UpdatePagesGHES(ctx, "o", "r", input)
226+
if err != nil {
227+
t.Errorf("Repositories.UpdatePagesGHES returned error: %v", err)
228+
}
229+
230+
const methodName = "UpdatePagesGHES"
231+
testBadOptions(t, methodName, func() (err error) {
232+
_, err = client.Repositories.UpdatePagesGHES(ctx, "\n", "\n", input)
233+
return err
234+
})
235+
236+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
237+
return client.Repositories.UpdatePagesGHES(ctx, "o", "r", input)
238+
})
239+
}
240+
203241
func TestRepositoriesService_UpdatePages_NullCNAME(t *testing.T) {
204242
t.Parallel()
205243
client, mux, _ := setup(t)

0 commit comments

Comments
 (0)