Skip to content

Commit 848f7e4

Browse files
authored
Support PagesSource as struct for update pages API (#2407)
Fixes: #2406.
1 parent fd22ee9 commit 848f7e4

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

github/github-accessors.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/repos_pages.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ type PagesUpdate struct {
9393
// Leaving CNAME empty will remove the custom domain.
9494
CNAME *string `json:"cname"`
9595
// Source must include the branch name, and may optionally specify the subdirectory "/docs".
96-
// Possible values are: "gh-pages", "master", and "master /docs".
97-
Source *string `json:"source,omitempty"`
96+
// Possible values for Source.Branch are usually "gh-pages", "main", and "master",
97+
// or any other existing branch name.
98+
// Possible values for Source.Path are: "/", and "/docs".
99+
Source *PagesSource `json:"source,omitempty"`
98100
// Public configures access controls for the site.
99101
// If "true", the site will be accessible to anyone on the internet. If "false",
100102
// the site will be accessible to anyone with read access to the repository that

github/repos_pages_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,20 @@ func TestRepositoriesService_UpdatePages(t *testing.T) {
7676

7777
input := &PagesUpdate{
7878
CNAME: String("www.my-domain.com"),
79-
Source: String("gh-pages"),
79+
Source: &PagesSource{Branch: String("gh-pages")},
8080
}
8181

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

8686
testMethod(t, r, "PUT")
87-
want := &PagesUpdate{CNAME: String("www.my-domain.com"), Source: String("gh-pages")}
87+
want := &PagesUpdate{CNAME: String("www.my-domain.com"), Source: &PagesSource{Branch: String("gh-pages")}}
8888
if !cmp.Equal(v, want) {
8989
t.Errorf("Request body = %+v, want %+v", v, want)
9090
}
9191

92-
fmt.Fprint(w, `{"cname":"www.my-domain.com","source":"gh-pages"}`)
92+
fmt.Fprint(w, `{"cname":"www.my-domain.com","source":{"branch":"gh-pages"}}`)
9393
})
9494

9595
ctx := context.Background()
@@ -114,7 +114,7 @@ func TestRepositoriesService_UpdatePages_NullCNAME(t *testing.T) {
114114
defer teardown()
115115

116116
input := &PagesUpdate{
117-
Source: String("gh-pages"),
117+
Source: &PagesSource{Branch: String("gh-pages")},
118118
}
119119

120120
mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) {
@@ -123,12 +123,12 @@ func TestRepositoriesService_UpdatePages_NullCNAME(t *testing.T) {
123123
t.Fatalf("unable to read body: %v", err)
124124
}
125125

126-
want := []byte(`{"cname":null,"source":"gh-pages"}` + "\n")
126+
want := []byte(`{"cname":null,"source":{"branch":"gh-pages"}}` + "\n")
127127
if !bytes.Equal(got, want) {
128128
t.Errorf("Request body = %+v, want %+v", got, want)
129129
}
130130

131-
fmt.Fprint(w, `{"cname":null,"source":"gh-pages"}`)
131+
fmt.Fprint(w, `{"cname":null,"source":{"branch":"gh-pages"}}`)
132132
})
133133

134134
ctx := context.Background()
@@ -393,12 +393,12 @@ func TestPagesUpdate_Marshal(t *testing.T) {
393393

394394
u := &PagesUpdate{
395395
CNAME: String("cname"),
396-
Source: String("src"),
396+
Source: &PagesSource{Path: String("src")},
397397
}
398398

399399
want := `{
400400
"cname": "cname",
401-
"source": "src"
401+
"source": { "path": "src" }
402402
}`
403403

404404
testJSONMarshal(t, u, want)

0 commit comments

Comments
 (0)